Question

In: Computer Science

CompSci 251: Assignment 3 Due 2/20, 2017 10:00am Topics Covered: Instance variables and methods; using a...

CompSci 251: Assignment 3

Due 2/20, 2017 10:00am

Topics Covered: Instance variables and methods; using a driver class

1 Introduction

This assignment will have you implement your first real Java class using instance variables(state) and meth- ods(behaviour). It will also probably be the first time that you write a program with a driver class.

2 Income tax computation

Most Americans (not just Americans, really!) complain about filing their income taxes. Some people dont think they should pay at all. Others dont like some of things that taxes are used for. Many people find the forms and the concepts confusing (they are). But the basic computation for income tax is not really that complicated. Its really the many special rules that make it hard to understand.

For this assignment, we’ll write a class that does the basic income tax computation for a “typical” household. The steps (for our simplified situation) are:

Compute Adjusted Gross Income (AGI) where AGI = wages + interestIncome.

Compute total deductions, where deductions = stateTax + propertyTax.

Compute taxable income, where taxableIncome = AGI - deductions.

Compute tax using this table. You have to know whether the household is single or married to choose the correct column.

Tax rate

Single

Married filing jointl

10%

$0 - $9,275

$0 to $18,550

15%

$9,276 - $37,650

$18,551-$75,300

25%

$37,651 - $91,150

$75,301-$151,900

28%

$91,151 - $190,150

$151,901-$231,450

33%

$190,151 - $413,350

$231,451-$413,350

35%

$413,351 - $415,050

$413,351-$466,950

39.6%

≥ $415, 051

≥ $466, 951

Your class will also compute the overall tax rate, which is just total tax divided by AGI. For most people, this number is much lower than the rate on their bracket.

1

2.1 The IncomeTax and IncomeTaxDriver class

Here is the UML class diagram for the IncomeTax class.

IncomeTax

- name: String // name of person whose tax is computed - married : boolean // true if married, false if single
- wages: integer
- interest: integer

- stateTax: integer
- propertyTax: integer

+ getName() : String
+ setName(String) : void
+ isMarried() : boolean
+ setMarried(boolean) : void
+ getWages() : integer
+ setWages(integer) : void
+ getInterest() : integer
+ setInterest(integer) : void
+ getStateTax() : integer
+ setStateTax(integer) : void
+ getPropertyTax() : integer
+ setPropertyTax(integer) : void

+ getAGI() : integer
+ getDeductions() : integer
+ getTaxableIncome() : integer + getIncomeTax() : double
+ getOverallRate() : double

The instance variables were explained above. Each one has a mutator/setter and an accessor/getter. The mutators for the integer variables must check the input value to ensure that it is non-negative. If the value is negative, they should leave the variable unchanged. You may not add additional instance variables. Any values that you need can be computed from the instance variables. The remaining methods compute values used in the tax computation. getIncomeTax() and getOverallRate() are the only ones that return double values and they need to because of the nature of the computation. The income tax computation looks complicated, but it really is not.

First, you figure out which top tax bracket the person falls into. For that tax bracket, the person will pay 10/15/25/28/33/35/39.6 percent of their income above the minimum value for the bracket, plus the total tax they owe from all the lower brackets. The second part of this formula is actually a fixed value for each bracket (once you know whether the person is married or single).

You can do this with a big if-else statement or there is a slick way to put the relevant values in arrays and use a loop to do the computation. The IncomeTaxDriver class is only required to have a main() method, though you can make other methods if you wish. It creates two IncomeTax objects, prompting the user to enter the five values needed to initialize the objects and setting them using the mutators/setters. It prints a summary of the income tax computation for each object and states which person is paying the most tax(Total Income Tax).

2.2 Requirements

• All instance variables must be private

2

In the IncomeTax class, no methods do any input or output.

You must use the class and method names that we specify above.

Your classes must follow the description in the previous section.

You should have two other helper methods in the driver class. One to read in the values for the IncomeTax object (private static IncomeTax initIncomeTax(Scanner stdIn)) and another to print the data about an IncomeTax object (private static void printIncomeTax(IncomeTax it)).

Only the total incomeTax and the overall tax rate values need to be printed with fractional parts. Its a good idea to use printf() to control the number of digits to the right of the decimal place.

2.3 Example how to use the Table

Joe is single and has a Taxable Income of $57,250. However, his income tax is not 25% of $57250, which would be $14312.50.

Instead, there are three steps:
He pays 10% tax on the ”first $9,275” of his income: ( .10 * 9275 ) = $927.50
He pays 15% tax on the additional income, up to $37,650: ( .15 * (37650 -9275) ) = $4256.25 Finally, he also pays 25% tax on his income over $37,650: ( .25 * (57650 - 37650) ) = $4900.00 His total tax is the sum of these three numbers:$927.50 + $4256.25 + $4900.00 = $10083.75

2.4 Sample Output

    Welcome to the Income Tax Program!
Please enter values for person #1 income tax profile:
Enter person’s name: Alex
Is Alex married (true or false):true
Enter wages of Alex: 22000
Enter interest income of Alex: 0
Enter state taxes paid by Alex: 1000
Enter property taxes paid by Alex: 300
Please enter values for person #2 income tax profile:
Enter person’s name: Victor
Is Victor married (true or false):false
Enter wages of Victor: 50000
Enter interest income of Victor: 0
Enter state taxes paid by Victor: 5000
Enter property taxes paid by Victor: 1000
Income Tax Profile for Alex
Marital Status: true
Wages: $22000
Interest Income: $0
Adjusted Gross Income: $22000
State Tax Paid: $1000
Property Tax Paid: $300
Total Deductions: $1300
Taxable Income: $20700
Total Income Tax: $2177.50

3

Overall Tax Rate: 9.90%
Income Tax Profile for Victor
Marital Status: false
Wages: $50000
Interest Income: $0
Adjusted Gross Income: $50000
State Tax Paid: $5000
Property Tax Paid: $1000
Total Deductions: $6000
Taxable Income: $44000
Total Income Tax: $6771.25
Overall Tax Rate: 13.54%
Victor will pay more income tax than Alex
Goodbye!

Solutions

Expert Solution

public class IncomeTax {

   private String name;
   private boolean isMarried;
   private int wages;
   private int interest;
   private int stateTax;
   private int propertyTax;

   public IncomeTax(String name, boolean isMarried, int wages,
           int stateTax, int propertyTax) {
       this.name = name;
       this.isMarried = isMarried;
       this.wages = wages;
      
       this.stateTax = stateTax;
       this.propertyTax = propertyTax;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public boolean isMarried() {
       return isMarried;
   }

   public void setMarried(boolean isMarried) {
       this.isMarried = isMarried;
   }

   public int getWages() {
       return wages;
   }

   public void setWages(int wages) {
       this.wages = wages;
   }

   public int getInterest() {
       return interest;
   }

   public void setInterest(int interest) {
       this.interest = interest;
   }

   public int getStateTax() {
       return stateTax;
   }

   public void setStateTax(int stateTax) {
       this.stateTax = stateTax;
   }

   public int getPropertyTax() {
       return propertyTax;
   }

   public void setPropertyTax(int propertyTax) {
       this.propertyTax = propertyTax;
   }

   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + interest;
       result = prime * result + (isMarried ? 1231 : 1237);
       result = prime * result + ((name == null) ? 0 : name.hashCode());
       result = prime * result + propertyTax;
       result = prime * result + stateTax;
       result = prime * result + wages;
       return result;
   }

   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       IncomeTax other = (IncomeTax) obj;
       if (interest != other.interest)
           return false;
       if (isMarried != other.isMarried)
           return false;
       if (name == null) {
           if (other.name != null)
               return false;
       } else if (!name.equals(other.name))
           return false;
       if (propertyTax != other.propertyTax)
           return false;
       if (stateTax != other.stateTax)
           return false;
       if (wages != other.wages)
           return false;
       return true;
   }

   public int getAGI() {

       double interestIncome = getWages() * (getOverallRate() / 100);
       return (int) (wages + interestIncome);

   }

   public int getDeductions() {
       return getStateTax() + getPropertyTax();

   }

   public int getTaxableIncome() {
       return getAGI() - getDeductions();

   }

   public double getIncomeTax() {
       double overallrateInterestrate = getOverallRate() / 100;
       double getDeductionAmout = wages - getDeductions();
       double overallrateInterestrateincome = (overallrateInterestrate*getDeductionAmout);
double totalincome=getDeductionAmout-overallrateInterestrateincome;
       return totalincome;
   }

   public double getOverallRate() {

       boolean status = isMarried();
       if (status == true) {
           if (wages > 0 || wages < 9275) {
               setInterest(10);
               return getInterest();
           }
           if (wages > 9276 || wages < 37650) {
               setInterest(15);
               return getInterest();
           }
           if (wages > 37650 || wages < 91150) {
               setInterest(25);
               return getInterest();
           }
           if (wages > 91151 || wages < 190150) {
               setInterest(28);
               return getInterest();
           }
           if (wages > 190151 || wages < 413350) {
               setInterest(33);
               return getInterest();
           }
           if (wages > 413351 || wages < 415050) {
               setInterest(35);
               return getInterest();
           }
           if (wages >= 415051) {
               setInterest(10);
               return getInterest();
           }

       } else {
           if (wages > 0 || wages < 18850) {
               setInterest(10);
               return getInterest();
           }
           if (wages > 18851 || wages < 75300) {
               setInterest(15);
               return getInterest();
           }
           if (wages > 75301 || wages < 151900) {
               setInterest(25);
               return getInterest();
           }
           if (wages > 151901 || wages < 231450) {
               setInterest(28);
               return getInterest();
           }
           if (wages > 231451 || wages < 413350) {
               setInterest(33);
               return getInterest();
           }
           if (wages > 413351 || wages < 466950) {
               setInterest(35);
               return getInterest();
           }
           if (wages >= 466950) {
               setInterest(10);
               return getInterest();
           }

       }
       return 0;

   }

   public String toString() {
       return "IncomeTax [name=" + name + ", isMarried=" + isMarried
               + ", wages=" + wages + ", interest=" + interest + ", stateTax="
               + stateTax + ", propertyTax=" + propertyTax + "]";
   }

}

import java.util.Scanner;

public class IncomeTaxDriverClass {

   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       System.out.println("enter the name");
       String name = scanner.next();
       System.out.println("enter the marital status");
       boolean married = scanner.nextBoolean();
       System.out.println("enter the wages ");
       int wages = scanner.nextInt();
       System.out.println("enter the state tax paid");
       int stateTax = scanner.nextInt();
       System.out.println("enter the property tax paid");
       int propertyTax = scanner.nextInt();

       IncomeTax tax = new IncomeTax(name, married, wages, stateTax,
               propertyTax);
       System.out.println("enter the name");
       String name1 = scanner.next();
       System.out.println("enter the marital status");
       boolean married1 = scanner.nextBoolean();
       System.out.println("enter the wages ");
       int wages1 = scanner.nextInt();
       System.out.println("enter the state tax paid");
       int stateTax1 = scanner.nextInt();
       System.out.println("enter the property tax paid");
       int propertyTax1 = scanner.nextInt();
       IncomeTax tax1 = new IncomeTax(name1, married1, wages1,
               stateTax1, propertyTax1);
      
       System.out.println(tax.toString());

       double agi=tax.getAGI();
       System.out.println("the agi is "+agi);
      
       double deductions=tax.getDeductions();
       System.out.println("deducitons"+deductions);
      
       double taxincome=tax.getIncomeTax();
       System.out.println("after tax ,income "+taxincome);
      
       double aftertax=tax.getWages()-taxincome;
       System.out.println(" tax income $"+aftertax);
      
  
      
       System.out.println(tax1.toString());
       double agi1=tax1.getAGI();
       System.out.println("the agi is "+agi1);
      
       double deductions1=tax1.getDeductions();
       System.out.println("deducitons"+deductions1);
      
       double taxincome1=tax1.getIncomeTax();
       System.out.println("after tax, income "+taxincome1);
      
       double aftertax1=tax1.getWages()-taxincome1;
       System.out.println(" tax income $"+aftertax1);
      
      

   }

}

output

enter the name
mark
enter the marital status
true
enter the wages
25000
enter the state tax paid
150
enter the property tax paid
3000
enter the name
smith
enter the marital status
false
enter the wages
36000
enter the state tax paid
250
enter the property tax paid
1500
IncomeTax [name=mark, isMarried=true, wages=25000, interest=0, stateTax=150, propertyTax=3000]
the agi is 27500.0
deducitons3150.0
after tax ,income 19665.0
tax income $5335.0
IncomeTax [name=smith, isMarried=false, wages=36000, interest=0, stateTax=250, propertyTax=1500]
the agi is 39600.0
deducitons1750.0
after tax, income 30825.0
tax income $5175.0


Related Solutions

[Point: 10] The instance of a list ADT using array is L = (10, 20, 30,...
[Point: 10] The instance of a list ADT using array is L = (10, 20, 30, 40, 50, 60). Find the output of following code segment or what is returned by each statement. remove(30);          find(50):                insert(7, 3):           findKth(4)             [Point: 5] The complexity of remove operation from a LIST ADT using array implementation is O(N). Explain why? [Point: 10] Show that the running time for the following segment of code is O(N3) without using the rule for loop. Make sure to...
The assignment for this week builds on what we covered in Chapter 3 using functions, as...
The assignment for this week builds on what we covered in Chapter 3 using functions, as well as introduces Conditional Statements. I have created your HTML file for you, along with some starter JavaScript to get you started. The HTML contains 3 text boxes and a button, and you'll recognize it as a simple registration form. Typically when you complete a form online, the data is sent to a server to be processed. If we are must send data across...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to...
Problem 3 Prototype object doubleQ A doubleQ object has 2 instance variables: firstQ and secondQ arrays...
Problem 3 Prototype object doubleQ A doubleQ object has 2 instance variables: firstQ and secondQ arrays that together implement a queue enqueue() instance method adds its argument to the end of this.secondQ dequeue() instance method removes and returns the element at the front of this.firstQ transfer() instance method removes the element from the front of this.secondQ, adds it to the end of this.firstQ If this.secondQ is empty, does nothing Test code is included in the file Download this file (with...
Assign 7,000 vehicles between node 1 and 2, using 3 traffic assignment methods: all-or-nothing, iterative, and...
Assign 7,000 vehicles between node 1 and 2, using 3 traffic assignment methods: all-or-nothing, iterative, and incremental. Use n=5 in the incremental method. In each method, determine the final travel time (T) of each link as well as the assigned volume. The link performance functions are as follows.  [100 pts.] TA = 15 [1+0.15 (VA  / 1000)4] TB = 20 [1+0.15 (VB  / 3000)4] TC = 21 [1+0.15 (VC  / 1500)4]
Multivariable calculus Evaluate: ∮ 3? 2 ?? + 2???? using two different methods. C is the...
Multivariable calculus Evaluate: ∮ 3? 2 ?? + 2???? using two different methods. C is the boundary of the graphs C y = x2 from (3, 9) to (0, 0) followed by the line segment from (0, 0) to (3, 9). 2. Evaluate: ∮(8? − ? 2 ) ?? + [2? − 3? 2 + ?]?? using one method. C is the boundary of the graph of a circle of radius 4 oriented counterclockwise
Assignment 2 (worth 10% of the final course grade - due date July 23, 2019) Prof....
Assignment 2 (worth 10% of the final course grade - due date July 23, 2019) Prof. Sherif Saad Purpose The purpose of this assignment is to help you to practice working with C String, arrays, and pointers Learning Outcomes ● Develop skills with pointers ● Learn how to traverse C String using pointers ● Passing Strings to functions ● Manipulate C String ● Develop algorithm design skills Problem Overview You will implement a basic string manipulation library called xstring.h. This...
Using the following data set: 10, 5, 2, 7, 20, 3, 13, 15, 8, 9 Apply...
Using the following data set: 10, 5, 2, 7, 20, 3, 13, 15, 8, 9 Apply the Merge sort algorithm. [Show to sorting process of the first half only] Apply the Quick sort algorithm [Show the first partitioning implementation]
y x1 x2 13 20 3 1 15 2 11 23 2 2 10 4 20...
y x1 x2 13 20 3 1 15 2 11 23 2 2 10 4 20 30 1 15 21 4 27 38 0 5 18 2 26 24 5 1 16 2 A manufacturer recorded the number of defective items (y) produced on a given day by each of ten machine operators and also recorded the average output per hour (x1) for each operator and the time in weeks from the last machine service (x2). a. What is the...
Directions: This assignment requires a 2-3 page written paper. Investigate various methods of performing survey research....
Directions: This assignment requires a 2-3 page written paper. Investigate various methods of performing survey research. Include personal and phone interviews, self-administered questionnaires, and computerized questionnaires in this assignment. State the advantages and disadvantages of each of these three types of survey research. Give an example survey research topic and specify which method you would use in that instance. State your reasons.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT