Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: help me please this is a calculator by the way

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default help me please this is a calculator by the way

    What did I do wrong here? I was trying to make a calculator for my AP Comp Science class and it turned out now to work.. I followed the teachers instructions but it didn't work. Does anyone have any suggestions on how to fix this?Thanks

    import java.util.*;
     
    public class d
    {
        public static void main(String[] args)
        {
            /*Scanner input = new Scanner(System.in);
            System.out.println("What are you doing?");
            if (answer.equalsIgnorecase("multiplication"))
            {
                Multiplication();
            }*/
            System.out.println("Hello, If you are doing Multiplication Type 1.");
            System.out.println("If you are doing Addition, Type 2.");
            System.out.println("If you are doing Subtraction, Type 3");
            System.out.println("If you are doing Division, Type 4");
            Scanner input = new Scanner(System.in);
            int decision;
            decision = input.nextInt();
            if (decision == 1)
            {
                Multiplication();
            }
            if (decision == 2)
            {
                Addition();
            }
            if (decision == 3)
            {
                Subtraction();
            }
            if (decision == 4)
            {
                Division();
            }
            else {
                System.out.println("Those aren't valid numbers.");
            }
        }
     
     
        }
        public static void Multiplication()
        {
            int mInput1;
            int mInput2;
     
            Scanner input = new Scanner(System.in);
            System.out.print("What is the first number? ");
            mInput1 = input.nextInt();
     
            System.out.print("What is the second number? ");
            mInput2 = input.nextInt();
     
            System.out.println(mInput1 + " times " + mInput2 + " equals " + mInput1 * mInput2);
        }
        public static void Addition()
        {
            int aInput1;
            int aInput2;
            int aAnswer;
     
            Scanner input = new Scanner(System.in);
            System.out.println("What is the first number?");
            aInput1 = input.nextInt();
     
            System.out.println("What is the second number?");
            aInput2 = input.nextInt();
     
            aAnswer = aInput1 + aInput2;
            System.out.println(aInput1 + " plus " + aInput2 + " equals " + aAnswer);
        }
        public static void Subtraction()
        {
            int sInput1;
            int sInput2;
            int sAnswer;
     
            Scanner input = new Scanner(System.in);
            System.out.println("What is the first number?");
            sInput1 = input.nextInt();
     
            System.out.println("What is the second number?");
            sInput2 = input.nextInt();
     
            sAnswer = sInput1 - sInput2;
            System.out.println(sInput1 + " minus " + sInput2 + " equals " + sAnswer);
        }
        public static void Division()
        {
            int dInput1;
            int dInput2;
            int dAnswer;
     
            Scanner input = new Scanner(System.in);
            System.out.println("What is the first number?");
            dInput1 = input.nextInt();
     
            System.out.println("What is the second number?");
            dInput2 = input.nextInt();
     
            dAnswer = dInput2 / dInput1;
            System.out.println(dInput1 + " divided by " + dInput2 + " equals " + dAnswer);
        }
    }
    Last edited by ryry163; May 8th, 2014 at 05:58 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,312
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: help me please this is a calculator by the way

    What did I do wrong here
    Please explain.

    The first problem I see is the classname. d????

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    ryry163 (May 8th, 2014)

  4. #3
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: help me please this is a calculator by the way

    Oh thank you I fixed it... First time here...

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,312
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: help me please this is a calculator by the way

    it didn't work
    Please explain.

    The first problem I see is the classname. d????

    1 out of 3 is a start.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. calculator
    By sabir_wahab27 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 18th, 2014, 06:27 AM
  2. Help with a calculator
    By minipanda1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 9th, 2013, 10:17 AM
  3. Calculator
    By Andrew Wilson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 08:08 AM
  4. Calculator
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2010, 09:00 AM
  5. [SOLVED] Calculator help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2010, 05:27 PM