How to Make a Calculator Application in Java Netbeans


Introduction: How to Make a Calculator Application in Java Netbeans

About: I make stuff sometimes

Hey guys! I'm back and I've got another awesome instructable for you! i'm going to be making a calculator in Java Netbeans, please  leave a comment or check out my other projects, hope you enjoy! I also have a website now! Check it out here:

Step 1: Installing

If you're new than welcome aboard! If you haven't yet, you will need to download and install the latest version of Java Netbeans. If you already have, you can skip this step. Click to "run it" and save it somewhere safe, like your installs folder.

Step 2: Beginning

Click "New Project", we don't need to change any of the default settings so click "Next", name it "Calculator" and click "Finish".

Step 3: Coding

Don't worry, this isn't a very hard project at all, it's mostly for beginners of Netbeans or anyone who's interested on the subject, if you haven't yet, you should go check out my other project ("How to make a HelloWorld application in Java Netbeans") before doing this one because it basically builds on my first project. Phew, okay enough of the talk let's get coding! Above where it says:
public class Calculator { type import java.util.Scanner; or copy and paste it. It may come up with a warning sign, don't worry we're going to fix that later, but for now, your code should look like this: 
import java.util.Scanner;
public class Calculator {
Now click behind the second to last bracket in your code and hit return a couple of times. Now click at the end of the green code that says // TODO code application logic here, hit return and type: 
Scanner scan = new Scanner(;
int Tommy = scan.nextInt();
double Bob = scan.nextDouble();

Woah! what just happened! It's okay, but guess what! You just made your very first variables! Congrats, but we're not done yet, the first thing you should see is that the warning sign by import java.util.Scanner; is gone, thats because we gave it something to "scan" in this case the variables (Tommy and Bob). You may notice that one of the variables (Bob) has a little different code than the other variable (Tommy). you'll find out what that does later. Our last piece of code goes under our last one, click at the end of double Bob = scan.nextDouble();, hit return twice and type System.out.println("The answer is " + (Tommy * Bob)); 

now, here's a little trick I found while doing a tutorial once, if you type sout in your code and click tab it will automatically change it to
System.out.println(""); try it if you want!

Step 4: Running

You've done it! it's alive! Congratulations! Run your project and click in the output box and type a 7, hit return, an type another 7 then hit enter/return and it should say: The answer is 49.0, now, the experimenting begins if you change the code System.out.println("The answer is " + (Tommy * Bob)); to System.out.println("The answer is " + (Tommy + Bob)); it will add the two numbers instead of multiplying them, finally if you change it to System.out.println("The answer is " + (Tommy - Bob)); it will subtract the two numbers, it even goes into negatives. Now, remember when we talked about how one variable's code was different from the other? Well, now I'll show you what that means, change the code to subtract and type 1 "return" 0.1 "return" and it should say The answer is 0.9, yep, you guessed it, you can use decimals, but only for the second digit you input, if you use a decimal for the first number it won't work.

Step 5: Conclusion

I hope you enjoyed this instructable and will check out my others. Please leave a comment and have a code filled day! :D

If you want to download the code you can get it here open it with textedit or notepad and copy the code then create a new project called Calculator and paste it all in, the only difference between this one and the one in the instructable is that it uses different variable names.



  • Water Contest

    Water Contest
  • Stick It! Contest

    Stick It! Contest
  • Creative Misuse Contest

    Creative Misuse Contest

4 Discussions

if you know everything so plz send the commons of calculator on java plz