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 2 of 2

Thread: hi everyone!! I'm new to java programming.. can you help me out? please

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy hi everyone!! I'm new to java programming.. can you help me out? please

    hi everyone!! I'm new to java programming.. Can you help me out? please?

    I made a simple calculator program, and i don't know if it's right.. There's no errors but it won't run? please help me solve my problem.. Thanks in advance..



     
    package simplecalculator;
     
    import javax.swing.*;
    import java.util.Scanner;
     
    public class simplecalculator
    {
        static Scanner input = new Scanner(System.in);
     
        public static void main(String[] args)
        {
            int choice;
     
                do{
                System.out.println(" *************************** ");
                System.out.println("     Tonelete's Calculator   ");
                System.out.println(" *************************** ");
                System.out.println("                             ");
                System.out.println("      (a) ADDITION           ");
                System.out.println("      (b) SUBTRACTION        ");
                System.out.println("      (c) MULTIPLICATION     ");
                System.out.println("      (d) DIVISION           ");
                System.out.println("      (e) QUIT               ");
                System.out.println("                             ");
                System.out.println(" *************************** ");
                System.out.println("Your choice: ");
                choice = input.nextInt();
                }while (choice < 'a' || choice > 'e');
     
                switch (choice)
                {
                    case 'a':
                        add();
                        break;
     
                    case 'b':
                        minus();
                        break;
     
                    case 'c':
                        times();
                        break;
     
                    case 'd':
                        divide();
                        break;
     
                    case 'e':
                        System.exit(0);
                        break;
                }
     
            }
     
        private static void add() {
            int x, y, sum = 0;
            int again;
            String output;
     
                        JOptionPane.showMessageDialog(null, "ADDITION");
                            x = Integer.parseInt
                                (JOptionPane.showInputDialog(null, "Enter first Number"));
                            y = Integer.parseInt
                                (JOptionPane.showInputDialog(null, "Enter second Number"));
                        sum = x + y;
                        output = "The Sum is " + sum + ".";
                        JOptionPane.showMessageDialog(null, output);
                        System.out.println("Try Again? (Y/N):  ");
                        again = input.next().charAt(0);
               if (again == 'Y' || again == 'y');
        }
     
        private static void minus() {
            int x, y, difference = 0;
            int again;
     
            String output;
     
                        JOptionPane.showMessageDialog(null, "SUBTRACTION");
                            x = Integer.parseInt
                                (JOptionPane.showInputDialog(null, "Enter first Number"));
                            y = Integer.parseInt
                                (JOptionPane.showInputDialog(null, "Enter second Number"));
                        difference = x - y;
                        output = "The difference is " + difference + ".";
                        JOptionPane.showMessageDialog(null, output);
                        System.out.println("Try Again? (Y/N):  ");
                        again = input.next().charAt(0);
               if (again == 'Y' || again == 'y');
        }
     
        private static void times() {
            int x, y, product = 0;
            int again;
     
            String output;
     
                        JOptionPane.showMessageDialog(null, "MULTIPLICATION");
                            x = Integer.parseInt
                                (JOptionPane.showInputDialog(null, "Enter first Number"));
                            y = Integer.parseInt
                                (JOptionPane.showInputDialog(null, "Enter second Number"));
                        product = x * y;
                        output = "The Product is " + product + ".";
                        JOptionPane.showMessageDialog(null, output);
                        System.out.println("Try Again? (Y/N):  ");
                        again = input.next().charAt(0);
               if (again == 'Y' || again == 'y');
        }
     
         private static void divide() {
             int x, y;
             double quotient;
             int again;
     
             String output;
     
                        JOptionPane.showMessageDialog(null, "DIVISION");
                            x = (int) Double.parseDouble
                                (JOptionPane.showInputDialog(null, "Enter first Number"));
                            y = (int) Double.parseDouble
                                (JOptionPane.showInputDialog(null, "Enter second Number"));
                        quotient = x / y;
                        output = "The Quotient is " + quotient + ".";
                        JOptionPane.showMessageDialog(null, output);
                        System.out.println("Try Again? (Y/N):  ");
                        again = input.next().charAt(0);
               if (again == 'Y' || again == 'y');
        }
    }

    THANKS in ADVANCE...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: hi everyone!! I'm new to java programming.. can you help me out? please

    but it won't run
    Please explain what happens when you try to execute it.

Similar Threads

  1. New to Java Programming!!!!
    By ruffu054 in forum Member Introductions
    Replies: 4
    Last Post: August 15th, 2011, 07:41 PM
  2. Is java a power full programming language? can java do this?
    By Jhovarie in forum Java Theory & Questions
    Replies: 5
    Last Post: March 2nd, 2011, 02:02 PM
  3. Java 3d Programming
    By Nickthecoder in forum Java Theory & Questions
    Replies: 1
    Last Post: May 5th, 2010, 10:48 PM
  4. Is Java Programming Best?
    By messenger in forum Java IDEs
    Replies: 3
    Last Post: May 4th, 2010, 09:11 PM
  5. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 14th, 2010, 06:42 AM