Results 1 to 12 of 12
Thread: Java Code running problem
 10252010, 08:50 PM #1Member
 Join Date
 Oct 2010
 Posts
 81
 Rep Power
 0
Java Code running problem
This is the code
Java Code:import java.util.Scanner; public class Taxes { static double taxes; public static void main(String[] args) { // Prompting System.out.println("Enter maritial status (1=single, 2=married)"); Scanner scanner= new Scanner(System.in); int marital=scanner.nextInt(); System.out.println("Enter taxable income: "); Scanner scanner1 = new Scanner(System.in); double income=scanner.nextDouble(); if(marital ==1); if(marital ==2); System.out.println("Your Federal Tax = $" + single(income)); } public static double single(double s) { //finding out tax for single if (s > 0 && s<=27050) taxes= .15*(s0); if (s > 27050 && s<=65550) taxes= 4057.50 + 0.275*(s27050); if (s > 65550 && s<=136750) taxes= 14645.00 + 0.305*(s65550); if (s > 136750 && s<=297350) taxes= 36361.00 + .355*(s136750); if (s > 297350) taxes= 93374.00 + .391*(s297350); return taxes; } public static double married(double m) { //finding out tax for double if (m > 0 && m <= 45200) taxes= .15*(m0); if (m > 45200 && m <= 109250) taxes= 6780.00 + .275*(m45200); if (m > 109250 && m <= 166500) taxes= 24393.75 + .305*(m109250); if (m > 166500 && m <= 297350) taxes= 41855.00 + .355*(m166500); if (m> 297350) taxes= 88306.00 + .391*(m297350); return taxes; } }
thank you
 10252010, 10:02 PM #2Senior Member
 Join Date
 Feb 2009
 Posts
 312
 Rep Power
 12
Take a look at your if statements inside your main method. Since there is a ";" after each one, they are effectively doing the following:
Java Code:if (marital == 1) { ; } if (marital == 2) { : } System.out.println("Your Federal Tax = $" + single(income));
 10262010, 01:46 AM #3Member
 Join Date
 Oct 2010
 Posts
 81
 Rep Power
 0
what im saying is that... im trying to get when i input 2 for the scanner it will do the tasks for the married if statements.. when i do either one its the same thing as the formulas are clearly diffrent with differnt numbers which will give me diff rent number if ran correctly. but when i run the same salary for each married and single its the same, even though married is diffrent from single. im trying to figure out why it wont run correctly if i input 2 meaning married. if i fix this issue my code will work perfectly
 10262010, 01:51 AM #4
Your if statements are not doing anything the way they are now. There is no code inside of them. And then after these statements you are calling only the single() method every time.
Java Code:if(marital ==1); if(marital ==2); System.out.println("Your Federal Tax = $" + single(income));
Sincerely, Joshua Green
Please REP if I help :)
 10262010, 01:54 AM #5Member
 Join Date
 Oct 2010
 Posts
 81
 Rep Power
 0
i have the if statements for both married and single correct.. could you tell me how i would use them properly the if statements would i put the if statements for the single under the marital==1?
 10262010, 01:58 AM #6
Yes, exactly. Except don't use a semicolon ";" after the if statement. You will use brackets and then put your code in between those brackets underneath. Example:
Java Code:if(marital == 1) { // Your single code here }
Sincerely, Joshua Green
Please REP if I help :)
 10262010, 02:06 AM #7Member
 Join Date
 Oct 2010
 Posts
 81
 Rep Power
 0
would i include the
Java Code:public static double single(double s)
 10262010, 02:12 AM #8
All you have to do is call the method from inside the if statement. Not put the entire method inside of the if statement. Call the single() method just like you did in your output statement, but inside the if statement.
Sincerely, Joshua Green
Please REP if I help :)
 10262010, 02:24 AM #9Member
 Join Date
 Oct 2010
 Posts
 81
 Rep Power
 0
so i wouldnt use that public double inside the if statement?
 10262010, 02:42 AM #10Member
 Join Date
 Oct 2010
 Posts
 81
 Rep Power
 0
could you give me a hint on how i would pass the method im stuck on this last part and everytihng will run complete
 10262010, 02:50 AM #11Member
 Join Date
 Oct 2010
 Posts
 81
 Rep Power
 0
ive completed the error this is what i came up with and it works perfectly
Java Code:import java.util.Scanner; public class Taxes { private static final double income = 0; static double taxes; public static void main(String[] args) { // Prompting System.out.println("Enter maritial status (1=single, 2=married)"); Scanner scanner= new Scanner(System.in); int marital=scanner.nextInt(); System.out.println("Enter taxable income: "); Scanner scanner1 = new Scanner(System.in); double income=scanner.nextDouble(); if(marital ==1){ System.out.println("Your Federal Tax = $" + single(income)); } if (marital==2){ System.out.println("Your Federal Tax = $" + married(income)); } } public static double single(double s) { //finding out tax for single if (s > 0 && s<=27050) taxes= .15*(s0); if (s > 27050 && s<=65550) taxes= 4057.50 + 0.275*(s27050); if (s > 65550 && s<=136750) taxes= 14645.00 + 0.305*(s65550); if (s > 136750 && s<=297350) taxes= 36361.00 + .355*(s136750); if (s > 297350) taxes= 93374.00 + .391*(s297350); return taxes; } public static double married(double m) { //finding out tax for double if (m > 0 && m <= 45200) taxes= .15*(m0); if (m > 45200 && m <= 109250) taxes= 6780.00 + .275*(m45200); if (m > 109250 && m <= 166500) taxes= 24393.75 + .305*(m109250); if (m > 166500 && m <= 297350) taxes= 41855.00 + .355*(m166500); if (m> 297350) taxes= 88306.00 + .391*(m297350); return taxes; } }
 10262010, 04:07 AM #12
Similar Threads

Problem running Java with XP Pro SP2
By swarv in forum New To JavaReplies: 16Last Post: 06232010, 01:58 PM 
Problem in running Java swing wizard in jre 1.6 while it is running in jre 1.4
By Sanjay Dwivedi in forum AWT / SwingReplies: 0Last Post: 08262009, 01:03 PM 
Running .javafiles won't work/compile does!(Code inside)
By wyldstyle in forum New To JavaReplies: 6Last Post: 02062009, 08:05 PM 
Problem in running java programs
By aravind in forum New To JavaReplies: 0Last Post: 07142008, 11:19 AM 
problem while running java code..
By Jjava in forum New To JavaReplies: 0Last Post: 02082008, 06:33 AM
Bookmarks