Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Proaram 2 (20 points; Design and implement a Java program for programming exerci

ID: 3590266 • Letter: P

Question

Proaram 2 (20 points; Design and implement a Java program for programming exercise 6.15, page 237, from the textbook (name it TaxTable). Do not have the program prompt the user for input and all output is handled by the main method. Change the taxable income interval from $50 to $500 (21 rows per table rather than 201 rows per table) and design the program to print out a separate table for each filing status (Single, Married Joint or Qualifying Widow(er), Married Separate, and Head of Household) one after another separated by a few blank lines. Document your code and organize the outputs using appropriate formatting techniques NOTE 1: Even though the income range stated in the textbook exercise does not cover every tax bracket, the method (or methods) in the submitted program must be able to generate the correct tax (using Table 3.2 on page 90 of the textbook) for any value of taxable income for every filing status NOTE 2: The method Math.round) is one approach for displaying the tax amount in whole dollars (integer). Other approaches, such as the printf) method, may be used as long as the result is rounded not merely truncated, and no decimal point is displayed

Explanation / Answer

  import java.util.ArrayList;

import java.util.List;

import java.lang.Integer;

import java.util.HashMap;

/* IMPORTANT: class must not be public. */

/*

* uncomment this if you want to read input.

import java.io.BufferedReader;

import java.io.InputStreamReader;

*/

class Range {

private int low;

private int high;

public Range(int low, int high){

this.low = low;

this.high = high;

}

public boolean contains(int number){

return (number >= low && number <= high);

}

}

class TaxBracket{ //class to store the tax bracket

HashMap<Integer, Range> single = new HashMap(); // datastructure to store key and range

HashMap<Integer, Range> marriedJoint = new HashMap();

HashMap<Integer, Range> mSeparate = new HashMap();

HashMap<Integer, Range> headOfHouse = new HashMap();

  

TaxBracket() //define constructor with the tax bracket

{

single.put(10,new Range(0,8350));

single.put(15,new Range(8351,33950));

single.put(25,new Range(33951,82250));

single.put(28,new Range(82251,171550));

single.put(33,new Range(171551,372950));

single.put(35,new Range(372951,100000000));

marriedJoint.put(10,new Range(0,16700));

marriedJoint.put(15,new Range(16701,67900));

marriedJoint.put(25,new Range(67901,137050));

marriedJoint.put(28,new Range(137051,208850));

marriedJoint.put(33,new Range(208851,372950));

marriedJoint.put(35,new Range(372951,100000000));

mSeparate.put(10,new Range(0,8350));

mSeparate.put(15,new Range(8351,33950));

mSeparate.put(25,new Range(33951,68525));

mSeparate.put(28,new Range(68526,104425));

mSeparate.put(33,new Range(104426,186475));

mSeparate.put(35,new Range(186475,100000000));

headOfHouse.put(10,new Range(0,11950));

headOfHouse.put(15,new Range(11951,45500));

headOfHouse.put(25,new Range(45501,117450));

headOfHouse.put(28,new Range(1174541,190200));

headOfHouse.put(33,new Range(190201,372950));

headOfHouse.put(35,new Range(372951,100000000));

}

}

class TaxPrint {

public static void main(String args[] ) throws Exception {

TaxBracket taxb = new TaxBracket();

int income;

ArrayList<Integer> list = new ArrayList(); // list containg the tax brackets

list.add(10);

list.add(15);

list.add(25);

list.add(28);

list.add(33);

list.add(35);

for(income=50000; income<=60000;income+=50) // calculating tax for all categories

{

System.out.print(income+" ");

for(int j : list)

{

if(taxb.single.get(j).contains(income))

System.out.print(Math.round(income*j/100) + " ");

}

for(int j : list)

{

if(taxb.marriedJoint.get(j).contains(income))

System.out.print(Math.round(income*j/100) + " ");

}

for(int j : list)

{

if(taxb.mSeparate.get(j).contains(income))

System.out.print(Math.round(income*j/100) + " ");

}

for(int j : list)

{

if(taxb.headOfHouse.get(j).contains(income))

System.out.print(Math.round(income*j/100) + " ");

}

System.out.print(" ");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote