Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## IRS Coding Error

Hi, I am trying to code an IRS that calculates the taxes according to one's marriage. However, although I have done the coding, I do not know how to create a main function so that I can make it run.
Following is the code

---------------------------------------------------------------------

import java.util.Scanner;

public class IRS {

private Scanner in;
private int maritalStatus;
private double income;

public IRS(){
maritalStatus = 1;
income = 0;
in = new Scanner(System.in);
}

public IRS(int m, double i){
maritalStatus = m;
income = i;
in = new Scanner(System.in);
}

/**
* Retrieves data from the keyboard. Returns true if data is valid,
* false if any of the values are out of range.
*/
public boolean input(){
boolean valid = false;
System.out.print("Enter marital status (1=single, 2=married): ");
maritalStatus = in.nextInt();
if(maritalStatus == 1 || maritalStatus == 2){
valid = true;
}
System.out.print("Enter taxable income: ");
income = in.nextDouble();
if(income < 0){
valid = false;
}
return valid;
}

/**
* Returns amount of tax.
* preconditions: maritalStatus is 1 or 2, income > 0
*/
public double calcTax(){

if(maritalStatus == 1){
if(income <= 27050){
return income * 0.15;
}else if(income <= 65550){
return (income - 27050) * 0.275 + 4057.5;
}else if(income <= 136750){
return (income - 65550) * 0.305 + 14645;
}else if(income <= 297350){
return (income - 136750) * 0.355 + 36361;
}else{
return (income - 297350) * 0.391 + 93374;
}
}else{
if(income <= 45200){
return income * 0.15;
}else if(income <= 109250){
return (income - 45200) * 0.275 + 6780;
}else if(income <= 166500){
return (income - 109250) * 0.305 + 24393.75;
}else if(income <= 297350){
return (income - 166500) * 0.355 + 41855;
}else{
return (income - 297350) * 0.391 + 88306;
}
}
}

public void printData(){
System.out.printf("\$%.2f", calcTax());
System.out.println();
}
}

2. This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

#### Posting Permissions

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