Question
FederalTax has already been made FederalTax.java import java.text.*; public class FederalTax { //instance variables private String SSN; private double income; NumberFormat money = NumberFormat.getCurrencyInstance(); //class
FederalTax has already been made
FederalTax.java
import java.text.*; public class FederalTax { //instance variables private String SSN; private double income; NumberFormat money = NumberFormat.getCurrencyInstance(); //class constants private final double DEFAULT_INCOME = 0; private final String DEFAULT_SSN = "001-01-0001"; //default constructor public FederalTax(){ setSSN(DEFAULT_SSN); setIncome(DEFAULT_INCOME); } /on-default constructor public FederalTax(String SSN, double income){ setSSN(SSN); setIncome(income); } //accessor methods public String getSSN(){return SSN;} public double getIncome(){return income;} //mutator methods public void setSSN(String newSSN){ SSN=newSSN; if(SSN!=null){ int indexOfHyphen = SSN.indexOf("-"); int indexOfSecondHyphen = SSN.indexOf("-", SSN.indexOf("-")+1); String areaNumber = SSN.substring(0, indexOfHyphen); String groupNumber = SSN.substring(indexOfHyphen+1, indexOfSecondHyphen); String serialNumber = SSN.substring(indexOfSecondHyphen+1); if(SSN.length() == 11 && areaNumber.matches("[0-9]+") && groupNumber.matches("[0-9]+") && serialNumber.matches("[0-9]+")){ int iAreaNumber = Integer.parseInt(areaNumber); int iGroupNumber = Integer.parseInt(groupNumber); int iSerialNumber = Integer.parseInt(serialNumber); if(iAreaNumber>0 && iAreaNumber0 && iGroupNumber0 && iSerialNumber0){ income = newIncome; } else{ income = DEFAULT_INCOME; } } //other methods public String toString(){ return "SSN: "+ SSN +" Taxable Income: "+money.format(income); } public int taxBracket(){ if(income>250000){ return 3; } else if(income53500){ return 2; } else{ return 1; } } public double taxPaid(){ double tp; if(income>250000){ tp = ((income-250000)*.396)+79772; return Math.round(tp*100.0)/100.0; } else if(income53500){ tp = ((income-53500)*.31)+12107; return Math.round(tp*100.0)/100.0; } else{ tp = (income*.15); return Math.round(tp*100.0)/100.0; } } }
Main.java
public class Main { public static void main(String[] args) { System.out.println("Test Case 4 - getHighestTaxObject()"); // no objects yet System.out.print("no objects yet testing "); boolean a0=FederalTax.getHighestTaxObject()==null; if (a0) System.out.println("PASSED"); else System.out.println("FAILED "+FederalTax.getHighestTaxObject());
// default object System.out.print("default object testing "); FederalTax p1=new FederalTax(); boolean a1=FederalTax.getHighestTaxObject().toString().equals("SSN: 001-01-0001 Taxable Income: $0.00"); if (a1) System.out.println("PASSED"); else System.out.println("FAILED "+FederalTax.getHighestTaxObject());
// new object larger System.out.print("new object larger testing "); FederalTax p2=new FederalTax("323-56-0822", 50000.); boolean a2=FederalTax.getHighestTaxObject().toString().equals("SSN: 323-56-0822 Taxable Income: $50,000.00"); if (a2) System.out.println("PASSED"); else System.out.println("FAILED "+FederalTax.getHighestTaxObject());
// new object equal System.out.print("new object equal testing "); FederalTax p3=new FederalTax("123-45-6789", 50000.); boolean a3=FederalTax.getHighestTaxObject().toString().equals("SSN: 323-56-0822 Taxable Income: $50,000.00"); if (a3) System.out.println("PASSED"); else System.out.println("FAILED "+FederalTax.getHighestTaxObject());
// new object smaller System.out.print("new object smaller testing "); FederalTax p4=new FederalTax("111-22-3333", 49999.); boolean a4=FederalTax.getHighestTaxObject().toString().equals("SSN: 323-56-0822 Taxable Income: $50,000.00"); if (a4) System.out.println("PASSED"); else System.out.println("FAILED "+FederalTax.getHighestTaxObject());
// new object larger System.out.print("new object larger testing "); FederalTax p5=new FederalTax("444-44-4444", 50001.); boolean a5=FederalTax.getHighestTaxObject().toString().equals("SSN: 444-44-4444 Taxable Income: $50,001.00"); if (a5) System.out.println("PASSED"); else System.out.println("FAILED "+FederalTax.getHighestTaxObject()); } }
For federal tax purposes, a person is identified by their social security number, a String in the form "AAA-GG-SSSS". The first three-digit field is called the "area number". The central, two-digit field is called the "group number". The final, four-digit field is called the "serial number". Valid Area Numbers are 001 through 649. Valid Group Numbers are 01 through 99. Valid Serial Numbers are 0001 through 9999. Use 001-01-0001 for a default SSN. The federal income tax that a person pays is a function of the person's taxable income (default value 0 ). The following table contains formulas for computing a single person's tax. Create a FederalTax class with necessary instance attributes, instance methods, class constants: - Constructors - default and non-default - Accessors - returns values of the instance variables - Mutators - assigns new values to the instance variables, including error checking on the arguments. All mutators should be private as a user cannot change their SSN or income after creating a FederalTax object. - toString method that returns a String with messages and values of the instance variables as shown. Note the formatting. SSN : 001-01-0001 Taxable Income: $0.00 - taxBracket () - uses the above table to compute and return the tax bracket - taxPaid() - uses the above table to compute and return the tax paid, a real number rounded to 2 decimal places. You also want the class to keep track of the FederalTax object that has the highest tax paid. Provide a class method getHighestTaxObject() to return that object (use a deep copy). Question 3 - Class Coding - FederalTax Enhancement (3 points) Start with your FederalTax.java from Lab 01. Test with FederalTaxTest.java from Lab01 and with the Lab 03A Main.java Check the test cases carefully for correct naming of methods and argument types
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started