Hi, I have done the code but it wont print out 25500.00 for the output. I also n
ID: 3800637 • Letter: H
Question
Hi, I have done the code but it wont print out 25500.00 for the output.
I also need a psueocode or whiteboard for this I learned about this in class but don't understand how to make one.
Here is the code to make it easier
import java.util.Scanner;
public class Income {
public static void main(String args[]){
double income;
double tax;
Scanner input = new Scanner(System.in);
System.out.print("Input your income:");
income = input.nextInt();
if(income > 0 && ++income <= 6000){
tax = income * 0.1;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 6001 && ++income <= 27950){
tax = income * 0.15;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 27951 && ++income <= 67700){
tax = income * 0.27;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 67701 && ++income <= 141250){
tax = income * 0.30;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 141251 && ++income <= 307050){
tax = income * 0.35;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income > 307050){
tax = income * (38.6/100);
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else {
System.out.println("Wrong Input; try again.");
}
}
}
Explanation / Answer
Hi
I have fixed the issue and highlighted the code changes below.
Income.java
import java.util.Scanner;
public class Income {
public static void main(String args[]){
double income;
double tax;
Scanner input = new Scanner(System.in);
System.out.print("Input your income:");
income = input.nextDouble();
if(income > 0 && ++income <= 6000){
tax = income * 0.1;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 6001 && ++income <= 27950){
tax = income * 0.15;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 27951 && ++income <= 67700){
tax = income * 0.27;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 67701 && ++income <= 141250){
tax = income * 0.30;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income >= 141251 && ++income <= 307050){
tax = income * 0.35;
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else if(income > 307050){
tax = income * (38.6/100);
System.out.printf("income tax for a single "
+ "perosn making $%.2f is $%.2f%n", income, tax);
}
else {
System.out.println("Wrong Input; try again.");
}
}
}
Output:
Input your income:85000.00
income tax for a single perosn making $85004.00 is $25501.20
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.