Question

In: Computer Science

Write and test a user-defined class (requiring conditions). Write an application (client) program that uses an...

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:

  • Declaration of an instance variable for the taxable income, a real number
  • Declaration of constants for all the tax bracket income levels, the tax paid base amounts for each bracket, and the percents for each bracket
  • Declaration of a constant NumberFormat to format all dollars
  • Constructors - default (zero for the taxable income) & non-default
  • Accessors - returns value of the instance variable
  • Mutators - assigns new value to the instance variable, verify that the taxable income is non-negative, or assign zero
  • a "public double taxPaid()" method that uses the above table to compute the tax
  • a "public String toString()" method that displays the value of the instance variable AND the taxPaid.

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

Solutions

Expert Solution

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


Related Solutions

Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A...
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the tic-tac-toe board. This game should involve one human player vs....
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A...
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the tic-tac-toe board. This game should involve one human player vs....
Write a program that uses the defined structure and all the above functions. Suppose that the...
Write a program that uses the defined structure and all the above functions. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the...
Write a program that asks the user to enter five test scores. The program should display...
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage: This method should accept five test scores as arguments and return the average of the scores. determineGrade: This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale: Score Letter Grade 90-100...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
3. write a program that uses a class called "garment" that is derived from the class...
3. write a program that uses a class called "garment" that is derived from the class "fabric" and display some values of measurement. 20 pts. Based on write a program that uses the class "fabric" to display the square footage of a piece of large fabric.           class fabric            {                private:                    int length;                    int width;                    int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT