Results 1 to 3 of 3

Thread: Quick Java Help!

  1. #1
    import java.io.*;

    public class FunctionalCal{
    public static void main (String[] args) throws IOException{
        BufferedReader option = new BufferedReader(
        (new InputStreamReader(System.in)));
       
    int num1=0;
    int num2=0;
    int choice;
    double result=0;

    // ------------------------------------------------------------------------
    // Beginning of the application. You will be asked several questions and
    // you will have to submit a response.
    // ------------------------------------------------------------------------
                   
            choice = Calculator.number();
            if(choice!=6){
            System.out.println("Enter an integer:");
            num1 = Integer.parseInt(option.readLine());
            System.out.println("Enter another integer:");
            num2 = Integer.parseInt(option.readLine());
            }
           
                while(choice !=6){
                if (choice == 1){
                result = Calculator.add(num1,num2);}
                if (choice == 2){
                result = Calculator.subtract(num1,num2);}
                if (choice == 3){
                result = Calculator.multiply(num1,num2);}
                if (choice == 4){
                result = Calculator.divide(num1,num2);}
                if (choice == 5){
                result = Calculator.pow(num1,num2);}
               
                System.out.println(result);
                choice = Calculator.number();
                if (choice!=6){
                System.out.println("Enter an integer:");
                num1 = Integer.parseInt(option.readLine());
                System.out.println("Enter another integer:");
                num2 = Integer.parseInt(option.readLine());
                }
                }
             
                System.out.println("G O O D B Y E");}
           
           

    }
    import java.io.*;

    public class Calculator{
    public static int number() throws IOException{
        BufferedReader option = new BufferedReader(
        (new InputStreamReader(System.in)));
       
    int number;

            System.out.println("\nMain Menu\n");
            System.out.println("1) Add");
            System.out.println("2) Subtract");
            System.out.println("3) Multiply");
            System.out.println("4) Divide");
            System.out.println("5) Raise to a power");
            System.out.println("6) Quit");
            number = Integer.parseInt(option.readLine());
           
            return(number);
    }

    public static int add(int a, int B) throws IOException{
        BufferedReader add = new BufferedReader(
        (new InputStreamReader(System.in)));
       
    int result;

        result = a + b;
       
            return(result);
    }

    public static int subtract(int a, int B) throws IOException{
        BufferedReader subtract = new BufferedReader(
        (new InputStreamReader(System.in)));
       
    int result;

        result = a - b;
       
            return(result);
    }

    public static int multiply(int a, int B) throws IOException{
        BufferedReader multiply = new BufferedReader(
        (new InputStreamReader(System.in)));
       
    int result;

        result = a * b;
       
            return(result);
    }

    public static int divide(int a, int B) throws IOException{
        BufferedReader divide = new BufferedReader(
        (new InputStreamReader(System.in)));
       
    int result;

        result = a/b;
       
            return(result);
    }

    public static int pow(int a, int B) throws IOException{
        BufferedReader pow= new BufferedReader(
        (new InputStreamReader(System.in)));
       
    int result;

        result = Math.pow(a,B);
       
            return result;
    }

    }
    TOP ONE IS MY MAIN ONE... the second is my class...

    i keep getting this error!?!?

    >>

    java.lang.NoSuchMethodError: main
    Exception in thread "main"

    any clues?.. it worked before i was showing someone how to do this...

  2. Lounge   -   #2
    Wolfmight's Avatar Poster BT Rep: +1
    Join Date
    Feb 2003
    Location
    Location: Location:
    Posts
    5,545
    The Method of whatever your trying to do is not correct.. try reprogramming it to use a different way to do whatever u want it to do..
    I've used java before.. there's many tweaks u can do.
    What exactly are you trying to do?
    Looks like some sort of "internet quiz".

  3. Lounge   -   #3
    BANNED
    Join Date
    Dec 2007
    Location
    Owl Sanctuary
    Age
    72
    Posts
    40
    java is for cheese mechanics.

Bookmarks

Posting Permissions

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