Results 1 to 8 of 8
Thread: Java compile error
- 10-14-2010, 06:11 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
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
- 10-14-2010, 06:12 PM #2
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.
- 10-14-2010, 06:17 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
if you can help me. how would i make it take two arguments. im a beginner in an AP COMPUTER Science class.
-
- 10-14-2010, 06:28 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
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
- 10-14-2010, 06:31 PM #6
-
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
- 10-14-2010, 06:48 PM #8
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
-
Java Compile error
By pablo2002 in forum Java AppletsReplies: 8Last Post: 09-12-2010, 02:48 AM -
compile error
By angryredantz in forum New To JavaReplies: 1Last Post: 01-23-2009, 10:44 PM -
Compile Error - Please Help!!
By AJ2009 in forum New To JavaReplies: 10Last Post: 01-04-2009, 03:59 PM -
Java 1.5 compile time error
By ank_k in forum New To JavaReplies: 4Last Post: 11-13-2008, 11:12 AM -
compile error
By dirtycash in forum New To JavaReplies: 6Last Post: 12-12-2007, 06:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks