Results 1 to 8 of 8
  1. #1
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default Java compile error

    Code:

    import java.util.Scanner;
    public class IRSTaxes {

    /**
    * @param args
    * @param taxes
    */
    public static void main(String[] args, double taxes) {
    // TODO Auto-generated method stub
    System.out.println("Enter marital status (1=single, 2=married) ");
    Scanner scanner= new Scanner(System.in);
    int marital = scanner.nextInt();

    if (marital==1);
    {
    Scanner sc=new Scanner(System.in);
    double salary=sc.nextDouble();


    }


    }

    }


    this code when i run the program it runs as
    java.lang.NoSuchMethodError: main
    Exception in thread "main"

    please help me why this is doing this as i am trying to code an IRS java program

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    The main() method takes a single argument: an array of Strings. You have a method named main, but it takes two arguments: an array of Strings and a double.

  3. #3
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    if you can help me. how would i make it take two arguments. im a beginner in an AP COMPUTER Science class.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by socboy6579 View Post
    if you can help me. how would i make it take two arguments. im a beginner in an AP COMPUTER Science class.
    You don't. The Main method must come with one parameter and one parameter only -- an array of Strings. There's no way around this.

  5. #5
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    this is my code so far:


    import java.util.Scanner;
    public class IRSTaxes {

    /**
    * @param args
    * @param taxes
    */
    public static void main(String[] args) {
    double taxes;
    // TODO Auto-generated method stub
    System.out.println("Enter marital status (1=single, 2=married) ");
    Scanner scanner= new Scanner(System.in);
    int marital = scanner.nextInt();

    if (marital==1);
    {
    Scanner sc=new Scanner(System.in);
    double salary=sc.nextDouble();

    if(salary > 0 && salary <= 27050);
    taxes= (salary-27050)*0.15;

    if(salary > 27050 && salary <= 65550);
    taxes= (salary -65550)*0.275 +4057.50;

    if(salary > 65550 && salary <= 136750);
    taxes= (salary -136750)*.305 +14645.00;

    if (salary > 136750 && salary <= 297350);
    taxes= (salary -297350)*.355 +36361.00;

    if (salary > 297350);
    taxes= (salary -297350)*.391 + 93374.00;

    System.out.println("Enter taxable income: ");
    Scanner scanner1= new Scanner(System.in);
    double income=scanner.nextDouble();
    }



    }

    }


    with this code i am trying to get the amount of your taxes when you are single and you make a certain income. I need a scanner to input your salary and then with the code to determine your taxes. is this correct

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    Quote Originally Posted by socboy6579 View Post
    is this correct
    You tell us. Does it do what you expect?

    PS- When posting code, make sure you use the code tags to preserve formatting.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by socboy6579 View Post
    this is my code so far:

    with this code i am trying to get the amount of your taxes when you are single and you make a certain income. I need a scanner to input your salary and then with the code to determine your taxes. is this correct
    1) What happens when you try the code? This is the way to find out if it is correct.
    2) Your posted code has lost all its formatting is too difficult to read. If you want to make it easier to read, edit your post above, and add code tags. You can learn how to do this by clicking on the first link in my signature below. -- or look here: Using Code Tags

  8. #8
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by socboy6579 View Post
    if you can help me. how would i make it take two arguments. im a beginner in an AP COMPUTER Science class.

    since the String is an array you can pass as many arguments you want. the drawback is that you have to convert the strings to the type you need. here is an example for your double

    Java Code:
    import java.util.Scanner;
    
    public class IRSTaxes {
    
        /**
         * @param args
         * @param taxes
         */
        public static void main(String[] args) {
            // the arguments should be a string and a double
            // please adapt this to your reguirements
            double taxes = 0.0D;
            if (args.length != 2) {
                System.out.println("Please enter a string and a double as argument");
                System.exit(1);
            }
            System.out.println("args[0] = " + args[0]);
            try {
                taxes = Double.parseDouble(args[1]);
            } catch (NumberFormatException e) {
                System.out.println("You entered an invalid number, taxes set to 0.0");
            }
            
            System.out.println("args[1] = " + taxes);
            System.out.println("Enter marital status (1=single, 2=married) ");
            Scanner scanner = new Scanner(System.in);
            int marital = scanner.nextInt();
    
            if (marital == 1)
                ;
            {
                Scanner sc = new Scanner(System.in);
                double salary = sc.nextDouble();
            }
        }
    }

    start this app with the parameter hallo 5.5.

Similar Threads

  1. Java Compile error
    By pablo2002 in forum Java Applets
    Replies: 8
    Last Post: 09-12-2010, 03:48 AM
  2. compile error
    By angryredantz in forum New To Java
    Replies: 1
    Last Post: 01-23-2009, 11:44 PM
  3. Compile Error - Please Help!!
    By AJ2009 in forum New To Java
    Replies: 10
    Last Post: 01-04-2009, 04:59 PM
  4. Java 1.5 compile time error
    By ank_k in forum New To Java
    Replies: 4
    Last Post: 11-13-2008, 12:12 PM
  5. compile error
    By dirtycash in forum New To Java
    Replies: 6
    Last Post: 12-12-2007, 07:00 PM

Posting Permissions

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