In: Computer Science
Write and test a user-defined class (requiring conditions).
Write an application (client) program that uses an instance(s) of a user-defined class.
The federal income tax that a person pays is a function of the person's taxable income. The following table contains formulas for computing a single person's tax.
Bracket |
Taxable Income |
Tax Paid |
1 |
$22,100 or less |
15% |
2 |
More than $22,100 but $53,500 or less |
$3,315 plus 28% of the taxable income over $22,100 |
3 |
More than $53,500 but $115,000 or less |
$12,107 plus 31% of the taxable income over $53,500 |
4 |
More than $115,000 but $250,000 or less |
$31,172 plus 36% of the taxable income over $115,000 |
5 |
Over $250,000 |
$79,772 plus 39.6% of the taxable income over $250,000 |
Create a FederalTax class with the following:
Code then test (complete and check against Expected Result below) your methods by creating application (client) class FederalTaxApp.java to test your FederalTax class.
Complete the test plan below.
Implement your pseudocode in java. Be sure your program is appropriately documented. Accept user input from the keyboard.
Compile and run your program to see if it runs (no run-time errors).
Test your program with the test plan below. If you discover mistakes in your program, correct them and execute the test plan again.
Test plan |
|||
Test case |
Sample input data |
Expected result |
Verified |
Tax Bracket 1 |
|||
Tax Bracket 2 |
|||
Tax Bracket 3 |
|||
Tax Bracket 4 |
|||
Tax Bracket 5 |
Here is some sample output for a few of the test cases above, you must test them all.
Sample output: |
Default FederalTax Object Taxable Income: $0.00 Tax Paid: $0.00 Enter your taxable income: 52000 Updated FederalTax Object Taxable Income: $52,000.00 Tax Paid: $11,687.00 Enter another taxable income: 137000 Non-Default FederalTax Object Taxable Income: $137,000.00 Tax Paid: $39,092.00 Test a negative Income Taxable Income: $0.00 Tax Paid: $0.00 |
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
// FederalTax.java
import java.text.NumberFormat;
public class FederalTax {
final double LESS22K = 22100;
final double TAXLESS22K = 15;
final double MORE22LESS53 = 3315;
final double TAXMORE22LESS53 = 28;
final double MORE53LESS115 = 12107;
final double TAXMORE53LESS115 = 31;
final double MORE115LESS250 = 31172;
final double TAXMORE115LESS250 = 36;
final double MORE250 = 79772;
final double TAXMORE250 = 39.6;
double taxableIncome;
// Creating NumberFormat Instance
NumberFormat fmt =
NumberFormat.getCurrencyInstance();
/**
*
*/
public FederalTax() {
this.taxableIncome = 0;
}
/**
* @param taxableIncome
*/
public FederalTax(double taxableIncome) {
setTaxableIncome(taxableIncome);
}
/**
* @return the taxableIncome
*/
public double getTaxableIncome() {
return taxableIncome;
}
/**
* @param taxableIncome
* the taxableIncome to set
*/
public void setTaxableIncome(double taxableIncome)
{
if (taxableIncome < 0)
this.taxableIncome = 0.0;
else
this.taxableIncome = taxableIncome;
}
// This method will calculate the tax
public double taxPaid() {
double taxPaid = 0.0;
if (taxableIncome <= LESS22K)
{
taxPaid =
(TAXLESS22K / 100) * taxableIncome;
} else if (taxableIncome > 22100
&& taxableIncome <= 53500) {
taxPaid =
MORE22LESS53 + (TAXMORE22LESS53 / 100) *
(taxableIncome-22100);
} else if (taxableIncome > 53500
&& taxableIncome <= 115000) {
taxPaid =
MORE53LESS115 + (TAXMORE53LESS115 / 100) *
(taxableIncome-53500);
} else if (taxableIncome >
115000 && taxableIncome <= 250000) {
taxPaid =
MORE115LESS250 + (TAXMORE115LESS250 / 100)*
(taxableIncome-115000);
} else if (taxableIncome >
250000) {
taxPaid =
MORE250 + (TAXMORE250 / 100) * (taxableIncome-250000);
}
return taxPaid;
}
@Override
public String toString() {
return "Taxable
Income:"+fmt.format(taxableIncome)+" Tax Paid
:"+fmt.format(taxPaid());
}
}
======================================
======================================
// Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args)
{
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
System.out.println("Default FederalTax Object");
FederalTax ft=new FederalTax();
System.out.println(ft.toString());
System.out.print("Enter your taxable income:");
double taxableIncome=sc.nextDouble();
ft.setTaxableIncome(taxableIncome);
System.out.println("Updated FederalTax Object");
System.out.println(ft.toString());
System.out.println("Non-Default FederalTax Object");
System.out.print("Enter your taxable income:");
taxableIncome=sc.nextDouble();
ft=new FederalTax(taxableIncome);
System.out.println(ft.toString());
System.out.println("Test a negative Income");
ft.setTaxableIncome(-45000);
System.out.println(ft.toString());
}
}
==========================================
==========================================
Output:
=====================Could you plz rate me well.Thank You