Concept explainers
Given Program:
The program given in the textbook is given here with comments for better understanding.
File Name: TaxReturn.java
// Class definition
public class TaxReturn
{
// Declare and initialize the required variables
public static final int SINGLE = 1;
public static final int MARRIED = 2;
private static final double RATE1 = 0.10;
private static final double RATE2 = 0.25;
private static final double RATE1_SINGLE_LIMIT = 32000;
private static final double RATE1_MARRIED_LIMIT = 64000;
private double income;
private int status;
/*Constructs a TaxReturn object for a given income and marital status.
@param anIncome the taxpayer income
@param aStatus either SINGLE or MARRIED */
// Method definition
public TaxReturn(double anIncome, int aStatus)
{
income = anIncome;
status = aStatus;
}
// Method definition
public double getTax()
{
// Declare and initialize the required variables
double tax1 = 0;
double tax2 = 0;
/* If the entered status is "Single", compute income tax based on their income */
if (status == SINGLE)
{
/* Check whether the income is less than or equal to $32000 */
if (income <= RATE1_SINGLE_LIMIT)
{
// If it is, compute the tax
tax1 = RATE1 * income;
}
/* If the income is greater than or equal to $32000, compute the tax */
else
{
tax1 = RATE1 * RATE1_SINGLE_LIMIT;
tax2 = RATE2 * (income - RATE1_SINGLE_LIMIT);
}
}
/* If the entered status is "Married", compute income tax based on their income */
else
{
/* Check whether the income is less than or equal to $64000 */
if (income <= RATE1_MARRIED_LIMIT)
{
// If it is, compute the tax
tax1 = RATE1 * income;
}
/* If the income is greater than or equal to $64000, compute the tax */
else
{
tax1 = RATE1 * RATE1_MARRIED_LIMIT;
tax2 = RATE2 * (income - RATE1_MARRIED_LIMIT);
}
}
// Return the tax to the main function
return tax1 + tax2;
}
}
File Name: TaxCalculator.java
// Import the required package
import java.util.Scanner;
/**
This program calculates a simple tax return.
*/
// Class definition
public class TaxCalculator
{
// Main class declaration
public static void main(String[] args)
{
// Create an object for scanner class
Scanner in = new Scanner(System.in);
// Prompt the user to enter the income
System.out.print("Please enter your income: ");
// Store the entered income in the variable
double income = in.nextDouble();
// Prompt the user to enter marital status
System.out.print("Are you married? (Y/N) ");
// Store the entered value in a variable
String input = in.next();
// Declare the variable
int status;
/* Check whether the user input value for marital status is "Y" */
if (input.equals("Y"))
{
/* If it is "Y", store the taxreturn value for a married person in the variable */
status = TaxReturn.MARRIED;
}
/* Check whether the user input value for marital status is "N" */
else
{
/* If it is "N", store the taxreturn value for a single person in the variable */
status = TaxReturn.SINGLE;
}
// Create an object for TaxReturn class
TaxReturn aTaxReturn = new TaxReturn(income, status);
// Display the tax return value based on the user input
System.out.println("Tax: "
+ aTaxReturn.getTax());
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Big Java Late Objects
- The following data give the starting salary for students who recently graduated from a local university and accepted jobs soon after graduation. The starting salary, grade-point average (GPA), and major (business or other) are provided. SALARY $29,500 $46,000 $39,800 $36,500 GPA 3.1 3.5 3.8 2.9 Major Other Business Business Other SALARY $42,000 $31,500 $36,200 GPA 3.4 2.1 2.5 Major Business Other Business Using a computer, develop a regression model that could be used to predict a starting salary based on GPA and major. Use this model to predict the starting salary for a business major with a GPA of 3.0. What does the model say about the starting salary for a business major compared to a non-business major? Do you believe this model is useful in predicting the starting salary? Justify your answer, using the information provided in the computer output.arrow_forwardCalculate the pf(12%) after taking the basic salary, HRA, DA from the user in c programming languagearrow_forwardPLISE ONLY TYPE ANSWERarrow_forward
- what is a suitable name and data type for "the percentage of people that can program computers"?arrow_forwardTable (A) shows the individual income tax rates for assessment year 2020. Table (A): Income tax rates assessment year 2020 Chargeable Income (RM) 0- 5,000 Calculation (RM) On the First 5,000 On the First 5,000 Next 15,000 On the First 20,000 Rate % Таx (RM) 5,001 – 20,000 1 150 150 20,001 – 35,000 3 Next 15,000 450 On the First 35,000 Next 15,000 600 35,001 – 50,000 8 1,200 Write a complete C program to prompt the user to enter the total chargeable income (RM), and then calculate the tax based on the calculation given in Table (A). For example: Prem's chargeable income = RM30,000 (RM20,000 + RM10,000) Total tax = RM150 (for first RM20,000) + RM300 (3% x RM10,000) = RM450 The program will then display the result which is the total amount tax needed to be paid in Ringgit Malaysia (RM), up to three significant digits after the decimal point. Requirements: Apply one return value function, include parameter list if necessary - Apply one non-return value function, include parameter list if…arrow_forwardCASE STUDY AITAM LIBRARY MANAGEMENT SYSTEM AITAM Public Library is the biggest library in Koforidua. Currently, it has about 300 members. A person who is 18 or above can become a member. There is a membership fee of GHC400 for a year. There is a form to be filled in which person fills personal details. These forms are kept in store for maintaining members’ records and knowing the membership period. A member can issue a maximum of three books. He/she has three cards to issue books. Against each card a member can issue one book from library. Whenever a member wishes to issue a book and there are spare cards, then the book is issued. Otherwise that request is not entertained. Each book is to be returned on the specified due date. If a member fails to return a book on the specified date, a fine of GHC 2 per day after the due return date is charged. In case a card gets lost, then a duplicate card is issued. Accounts are maintained for the membership fees and money collected from the fines.…arrow_forward
- dont use others answersarrow_forwardLUNCH SALES Days of Week Lunch Sold Qty Unit Price Total Sold Monday Chicken 25 15.00 $ 375.00 Monday Pork 15 20.00 $ 300.00 Monday Fish 20 25.00 $ 500.00 Tuesday Mutton 15 23.00 $ 345.00 Tuesday Fish 30 25.00 $ 750.00 Wednesday Chicken 55 15.00 $ 825.00 Thursday Turkey 45 18.00 $ 810.00 Friday Turkey 60 18.00 $ 1,080.00 Saturday Chicken 15 15.00 $ 225.00 Saturday Mutton 45 23.00 $ 1,035.00 Saturday Fish 55 25.00 $ 1,375.00 Saturday Turkey 50 18.00 $ 900.00 Saturday Pork 20 20.00 $ 400.00 Sunday Fish 55 25.00 $ 1,375.00 Sunday Mutton 35 23.00 $ 805.00 Sunday Chicken 30 15.00 $ 450.00 #NAME? Fruit # of Days Sold Total Sold Sum of Total Sold Chicken Mutton Fish Turkey Pork Instructions: (Fill in the columns of the "Calculations Table") 1.…arrow_forwardexplain with 0 plagiarismarrow_forward
- COMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE LNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:CengageOperations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole