Lab #2: Using Data for Calculating Taxes and for Solving a System of Linear Equations

The goal of this lab is to write two programs that do some computing using data values embedded in the code. The two parts equally contributed to the lab grade.

Part (a) Tax Calculation

The goal of this part is to write a class Tax for calculating the income tax of an imaginary country of Bonzo. The tax is calculated from the income, the savings, the stock, the real estate, and the number of children in the family. The income, savings, stock, and real estate values are in dollars and are double variables and the number of children is an int. These variables shall be declared in the code and shall be given values. By changing the values assigned to these variables, different outcomes may result.

The tax formula is the sum of four subtaxes:

There shall be four double variables desginated for these four subtaxes as well as the variable designated for storing the total tax. The program shall compute the four subtaxes and then compute the total. The program then shall print out the outcome of calculation.

% java Tax
Savings amount is 10000
Stock amount is 20000
Real estate amount is 250000
Income is 85000
Number of children is 3
Savings tax is 100.0
Stocks tax is 400.0
Real estates tax is 7500.0
Income tax is 22800.0
Total Tax is 30800.0

You may use the template Tax.java, which produces the part other than the tax calculation and print out.

Part (b) Linear Equation

This part is for writing a class LinearEquation that computes the solution of a set of three diagonalized linear equations:

a1 x = d1,
a2 x + b2 y = d2,
a3 x + b3 y + c3 z = d3

where a1, d1, a2, b2, d2, a3, b3, c3, d3, x, y, and z are all double and the values of a1, d1, a2, b2, d2, a3, b3, c3, and d3 are embedded in the code.

The soltuon can be obtained in the following manner:

  1. use the first equation to compute x (needing one division)
  2. substitute x in the second equation with the value obtained in (1) and solve it for y
  3. substitute x and y in the third equation with the values obtained in (1) and (2), respectively, and solve it for z

The output of the code should look like:

% java LinEquation
The equations are:
4.0 x = 2.0
2.0 x + 3.0 y = -2.5
-3.0 x + 1.5 y + 1.0 z = 2.0
The solution is :
x = 0.5, y = -1.1666666666666667, z = 5.25

You may use the template LinearEquations.java.

Go back to the lab main page

Go back to the home page