Here is the program code:
/**
* Class Name: IncomeTax
* ---------------------
* Purpose: to compute base income, taxable income, and tax based
* on the previous two variables. This program will also output
* the aforementioned variables.
*/
import java.util.Scanner;
import java.io.InputStreamReader;
public class IncomeTax{
//Make all the variables, and constants, required for calculations. The constants can be
//changed from here by the programmer to ensure that they only have to change one number,
//thus preventing bugs.
int inpIncome, baseIncome, deps;
float taxableIncome, tax, taxOwed, taxPaid, taxRefund;
private final int b = 16000;
private final int c = 4500;
private final float d = 0.60f;
//Pretty straightforward. Tell the user what do do, and they input the appropriate numbers.
public void getInfo(Scanner in, IncomeTax a){
System.out.print("Please enter the number of dependants: ");
a.deps = in.nextInt(); System.out.print('\n');
System.out.print("Please enter your input income: ");
a.inpIncome = in.nextInt(); System.out.print('\n');
}
//This figures out the base income based on the user input, and then it calculates what the
//taxable income is.
public void calcTxInc(IncomeTax a){
a.baseIncome = a.b + (a.c * a.deps);
a.taxableIncome = a.inpIncome - a.baseIncome;
}
//computes tax
public void compTax(IncomeTax a){
//if the taxable income is smaller than or equal to zero, then tax becomes negative (the value
//of taxable income).
if(a.taxableIncome <= 0.00f){a.tax = a.taxableIncome;}
//if taxable income is between 0 and a.b, then calculate tax with this equation.
else if(0.00f < a.taxableIncome && a.taxableIncome < a.b){
a.tax = a.taxbleIncome * (0.50f - ((d/10.00f) * 0.50f));
if(a.tax >= 0.00f){a.tax = 0.00f;}
//if taxable income is greater than a.b, use this equation
}else if(a.b <= taxableIncome){
a.tax = taxableIncome * a.d;
}
}
//if the user will pay their tax, then here is where they input how much they will pay.
public void payTax(Scanner in, IncomeTax a){
System.out.print("Please enter an amount to pay(in the format $x.xx): ");
a.taxPaid = in.nextFloat();
System.out.print('\n');
}
//Computes the total tax that the user owes.
public void compTaxOwed(IncomeTax a){
a.taxOwed = a.tax - a.taxPaid;
//if they get a refund, then their refund is calculated, and "owed" is returned as zero.
if(a.taxOwed < 0.00f){
a.taxRefund = a.taxOwed * (-1);
a.taxOwed = 0.00f;
//if the tax owed is greater than zero, set refund to zero, and return "owed"
}else if(a.taxOwed > 0.00f){
a.taxRefund = 0.00f;
//if there is no tax (i.e. all tax is paid off) set refund to zero and return.
}else if(a.taxOwed == 0.00f){
a.taxRefund = 0.00f;
return;
}
}
//prints all the information
public void printInfo(IncomeTax a){
System.out.println("Your Tax information is as follows: ");
System.out.println("Input Income: " + a.inpIncome);
System.out.println("Base Income: " + a.baseIncome);
System.out.println("Taxable Income: " + a.taxableIncome);
System.out.println("Tax: " + a.tax);
//if taxRefund is greater than zero, print the amount.
if(a.taxRefund != 0.00f){
System.out.println("Tax Refund: " + a.taxRefund);
}else{
//or else, print the amount of tax owed.
System.out.println("Tax Owed: " + a.taxOwed);
}
}
//your friendly neighbourhood main function.
public static void main(String[] args){
char check;
//creates a new IncomeTax object so that we can operate on it.
IncomeTax a = new IncomeTax();
//creates a new scanner to get the tax information.
Scanner jack = new Scanner(System.in);
//a quick hack to ensure the proper information is put into the "check" var.
InputStreamReader slip = new InputStreamReader(System.in);
//retrieve information from the user.
a.getInfo(jack, a);
//close the scanner since we don't need it anymore
jack.close();
//call the function that computes the applicable taxes.
a.compTax(a);
//check if the user will make a payment on their taxes.
System.out.print("Would you like to make a tax Payment? [y/n] ");
//reads the y/n
check = (char) slip.read();
//if the user inputs invalid information, the program exits.
if(check != 'y' || check != 'n'){
System.out.println("Error. Status returned -1. Invalid input.");
return;
//if the user says "y" then this kicks the user into the function where they
//decide how much to pay.
}else if(check == 'y'){
a.payTax(jack, a);
slip.close();
//if they don't want to, then close the streamreader, we have no more use for it.
}else if(check == 'n'){
slip.close();
}
//compute how much tax is owed, or how much of a return will be recieved.
a.compTaxOwed(a);
//print the information, then exit.
a.printinfo(a);
}
}
javac output:
cripps@presarioV2:~/programming/java tutorials/my code/MUNcs/javaI/assignment4$ javac IncomeTax.java
IncomeTax.java:41: cannot find symbol
symbol : variable taxbleIncome
location: class IncomeTax
a.tax = a.taxbleIncome * (0.50f - ((d/10.00f) * 0.50f));
^
IncomeTax.java:120: cannot find symbol
symbol : method printinfo(IncomeTax)
location: class IncomeTax
a.printinfo(a);
^
2 errors