Results 1 to 3 of 3
  1. #1
    madkidd02 is offline Member
    Join Date
    Oct 2008
    Rep Power

    Default Calculator help.

    ok im supposed to do a calculator and ive red the book over 20-30 times and this just doesnt make sense to me . my calculator isnt supposed to have graphics or nothing just a plain old dos calc. asks you wat operation you want to do. you type it in. the operation comes out nd u input the numbers and it solves it for you. i have the division code and the start of the calc. but idk how to put them together. can someone help. heres my code. for the calc and division.

    Java Code:
    import java.util.Scanner;
    public class Calc
    	public static void main(String []args)
    		//creat a scanner object to read input
    		Scanner keyboard = new Scanner(;
    		int multiply, add, subtract, divide, number ;
    		System.out.println("What operation would you like to do?:");
    		System.out.println ("multiply");
    		System.out.println ("add");
    		System.out.println ("subtract");
    		System.out.println ("divide");
    		multiply = keyboard.nextInt();
    		add = keyboard.nextInt();
    		subtract = keyboard.nextInt();
    		divide = keyboard.nextInt();
    and heres the division which i got from the book

    Java Code:
    import java.util.Scanner; //needed for scanner class
     *this program demonstrates the if-else statement
    public class Division
    	public static void main(String []args)
    		double number1, number2; // division operands
    		double quotient;		// result of division
    		// creat a scanner objet for keyboard input
    		Scanner keyboard = new Scanner(;
    		//get the first number
    		System.out.print("enter a number: ");
    		number1 = keyboard.nextDouble();
    				//get the 2nd number
    		System.out.print("divided by: ");
    		number2 = keyboard.nextDouble();
    		if (2 == 0)
    			System.out.println("division by zero is not possible.");
    			System.out.println("please run the program again and ");
    			System.out.println("enter a number other than zero");
    			quotient = number1 / number2;
    			System.out.println("divided by " + number2);
    			System.out.println("is " + quotient);

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Do you know how to create and use methods? and how is your Calc class getting input? how can it tell what operation to perform?
    Last edited by Fubarable; 10-25-2008 at 04:46 AM.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    Yes, first of all learn about methods in Java, how to define how to handle to have some process how to call methods in different locations and so on.

    When you get fair knowledge about methods, you can easily implement all your classes as a method. Actually you can find out what your classes doing, which you have found from the book.

Similar Threads

  1. HELP FAST!!----Interest Calculator
    By Coop33 in forum New To Java
    Replies: 8
    Last Post: 10-15-2008, 01:44 PM
  2. Calculator Problem. Thanks for helping! ^^
    By clark_sandy in forum New To Java
    Replies: 3
    Last Post: 07-06-2008, 04:01 PM
  3. Java Calculator
    By aapanju in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 05:33 AM
  4. calculator not working
    By Renegade85 in forum New To Java
    Replies: 5
    Last Post: 03-10-2008, 03:27 PM
  5. Swing Calculator
    By nemo in forum AWT / Swing
    Replies: 1
    Last Post: 05-28-2007, 11:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts