I need my output to float to only 2 decimal places as the output is money. For example if I run:
Enter 1 if you are single. Enter 2 if you are married
1
Enter your taxable income
27060.34
Federal Income Tax:$4060.3435
I need the federal income tax to output $4060.34 instead of $4060.3435
My code:
import static org.junit.Assert.*;
import java.util.Scanner;
import org.junit.Test;
public class IRS {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter 1 if you are single. Enter 2 if you are married");
int martialstatus = scan.nextInt();
if (martialstatus == 1) {
Scanner scan2 = new Scanner(System.in);
System.out.println("Enter your taxable income");
double income = scan2.nextDouble();
if ((income > 0) && (income <= 27050.00)) {
System.out.println("Federal Income Tax:$" + (income * .15));
}
if ((income > 27050.00) && (income <= 65550.00)) {
System.out.println("Federal Income Tax:$" + (4057.50 + (.275 * (income - 27050))));
}
if ((income > 65550.00) && (income <= 136750.00)) {
System.out.println("Federal Income Tax:$" + (14645.00 + (.305 * (income - 65550.00))));
}
if ((income > 136750.00) && (income <= 297350.00)) {
System.out.println("Federal Income Tax:$" + (36361.00 + (.355 * (income - 136750.00))));
}
if (income > 297350.00) {
System.out.println("Federal Income Tax:$" + (93374.00 + (.391 * (income - 297350.00))));
}
} else if (martialstatus == 2) {
Scanner scan3 = new Scanner(System.in);
System.out.println("Enter your taxable income");
double income2 = scan3.nextDouble();
if (income2 <= 45200.00) {
System.out.println("Federal Income Tax:$" + (.15 * income2));
}
if ((income2 > 45200.00) && (income2 <= 109250.00)) {
System.out.println("Federal Income Tax:$" + (6780.00 + (.275 * (income2 - 45200))));
}
if ((income2 > 109250.00) && (income2 <= 166500.00)) {
System.out.println("Federal Income Tax:$" + (24393.75 + (.305 * (income2 - 109250.00))));
}
if ((income2 > 166500.00) && (income2 <= 297350.00)) {
System.out.println("Federal Income Tax:$" + (41855.00 + (.355 * (income2 - 166500.00))));
}
if (income2 > 297350.00) {
System.out.println("Federal Income Tax:$" + (88306.00 + (.391 * (income2 - 297350.00))));
}
} else {
System.out.println("Error. Try again");
}
}
}