Java Reference
In-Depth Information
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice:
Enter an amount to deposit:
3
10
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice:
The balance is 107.0
1
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice:
4
Enter an id:
***10.8
(
Financial: the
Tax
class
) Programming Exercise 7.12 writes a program for com-
puting taxes using arrays. Design a class named
Tax
to contain the following
instance data fields:
■
int filingStatus
: One of the four tax-filing statuses:
0
—single filer,
1
—
married filing jointly or qualifying widow(er),
2
—married filing separately,
and
3
—head of household. Use the public static constants
SINGLE_FILER
(
0
),
MARRIED_JOINTLY_OR_QUALIFYING_WIDOW(ER)
(
1
),
MARRIED_
SEPARATELY
(
2
),
HEAD_OF_HOUSEHOLD
(
3
) to represent the statuses.
■
int[][] brackets
: Stores the tax brackets for each filing status.
■
double[] rates
: Stores the tax rates for each bracket.
■
double taxableIncome
: Stores the taxable income.
Provide the
get
and
set
methods for each data field and the
getTax()
method
that returns the tax. Also provide a no-arg constructor and the constructor
Tax(filingStatus, brackets, rates, taxableIncome)
.
Draw the UML diagram for the class and then implement the class. Write a test
program that uses the
Tax
class to print the 2001 and 2009 tax tables for taxable
income from $50,000 to $60,000 with intervals of $1,000 for all four statuses.
The tax rates for the year 2009 were given in Table 3.2. The tax rates for 2001 are
shown in Table 10.1.
**10.9
(
The
Course
class
) Revise the
Course
class as follows:
■
The array size is fixed in Listing 10.6. Improve it to automatically increase the
array size by creating a new larger array and copying the contents of the cur-
rent array to it.
■
Implement the
dropStudent
method.
■
Add a new method named
clear()
that removes all students from the course.
Write a test program that creates a course, adds three students, removes one, and
displays the students in the course.