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
- Mr. and Mrs. John Smith have signed a purchase agreement for a 4 bedroom house with separate garage. The purchase price is $500,000. They plan on putting a down payment of 20 percent. They are with their lender who shows the couple how much their monthly mortgage payment would be if they took out a 30-year mortgage, a 20-year mortgage, or if they took out a 15-year mortgage. The interest rate is 2.5% to take out the loan. Write a JAVA program that will help the Smiths and any other customer of the lender determine their monthly mortgage payment based on the following input: - Purchase Price - Down Payment - Loan Amount (purchase price - down payment) - Interest rate in decimal form - Number of years for mortgage The program will also include entry of the name(s) for the mortgagee (person taking out the loan for the mortgage) and the date the calculations were made. The program will also ask if the client wants to run the program again [that way the Smiths' will be able to…arrow_forwardtry to solve using pythonarrow_forwardhelp i dont watn ai to answer itarrow_forward
- .....arrow_forwardYou are in the process of getting a new car but are not sure if you should buy or lease. The price of the car you want is $18,000, but you do not want to spend more than $250 a month on car payments. If you lease the car, the terms of the lease will be 48 months at an annual interest rate of 5%. The residual value of the car will be set at $9,000. If you buy the car, your bank will offer you a 7-year loan at an annual interest rate of 6%. You are not required to make a down payment with either the lease or loan options, and payments are made at the end of the month for both options. Instructions Should you lease or buy the car given your budget limit of $250 a month? Create a new workbook and design a worksheet that shows the difference between leasing and buying the car in terms of monthly payments. Use proper formatting so your worksheet is easy to read. Remember to use column and row headings, add a title to your worksheet, and rename the worksheet tab with an appropriate label.…arrow_forwardA farmer in Georgia has a 100-acre farm on which to plant watermelons and cantaloupes. Every acre planted with watermelons requires 50 gallons of water per day and must be prepared for planting with 20 pounds of fertilizer. Every acre planted with cantaloupes requires 75 gallons of water per day and must be prepared for planting with 15 pounds of fertilizer. The farmer estimates that it will take 2 hours of labor to harvest each acre planted with watermelons and 2.5 hours to harvest each acre planted with cantaloupes. He believes that watermelons will sell for about $3 each, and cantaloupes will sell for about $1 each. Every acre planted with watermelons is expected to yield 90 salable units. Every acre planted with cantaloupes is expected to yield 300 salable units. The farmer can pump about 6,000 gallons of water per day for irrigation purposes from a shallow well. He can buy as much fertilizer as he needs at a cost of $10 per 50-pound bag. Finally, the farmer can hire laborers to…arrow_forward
- Banks lend money to each other. In tough economic times, if a bank goes bankrupt, it may not be able to pay back the loan. A bank’s total assets are its current balance plus its loans to other banks. The diagram in Figure 11.9 shows five banks. The banks’ current balances are 25, 125, 175, 75, and 181 million dollars, respectively. The directed edge from node 1 to node 2 indicates that bank 1 lends 40 million dollars to bank 2. If a bank’s total assets are under a certain limit, the bank is unsafe. The money it borrowed cannot be returned to the lender, and the lender cannot count the loan in its total assets. Consequently, the lender may also be unsafe if its total assets are under the limit. Write a program to find all unsafe banks. Your program should read the input as follows. It first reads two integers n and limit, where n indicates the number of banks and limit is the minimum total assets for keeping a bank safe. It then reads n lines that describe the information for n banks…arrow_forwardA computer manufacturing company is trying to decide whether to purchase specialized assembly equipment todayor to wait 6 years from now, when the equipment will be first needed.If you were to purchase the equipment today it would cost: $704,0006 years from now the equipment would cost: $1,000,962The bank is paying 6.00% interest per year, compounded monthly.Should you buy the equipment now or wait 6 years to buy the equipment?arrow_forwardImagine you are an avid movie goer and you prepared a list of n movies you are considering watching. As a thorough researcher, you prepared a list of k friends, whose movie advice you trust. For each movie, you are debating whether to either see it or speak to all of your friends and hear their recommendations. A more efficient approach is to choose between watching the movie and speaking with at least one trusted movie recommender friend. This approach will take a total of t hours. Prove that the problem is NP-hard.arrow_forward
- Kevin bought a new moulding machine for $3,000. The machine deteriorates with age and requires to trade in for a new one every fifth year of usage. The resale value and the running cost are given in below table. Age of machine (year) 1 3 4 5 Maintenance cost ($) 600 700 800 900 1,000 Resale value ($) 2,000 1,333 1,000 750 500arrow_forwardYou found an exciting summer job for five weeks. It pays, say, $15.50 per hour. Suppose thatthe total tax you pay on your summer job income is 14%. After paying the taxes, you spend10% of your net income to buy new clothes and other accessories for the next school yearand 1% to buy school supplies. After buying clothes and school supplies, you use 25% of theremaining money to buy savings bonds. For each dollar you spend to buy savings bonds,your parents spend $0.50 to buy additional savings bonds for you. Write a flowchart that prompts the user to enter the number of hours you worked each week. The program thenoutputs the following:a. Your income before and after taxes from your summer job.b. The money you spend on clothes and other accessories.c. The money you spend on school supplies.d. The money you spend to buy savings bonds.e. The money your parents spend to buy additional savings bonds for you.arrow_forwardThe graph below represents the possible routes that can be built in a city to improve mobility between neighborhoods, the label on the sides is the number of houses that must be knocked down to build the route. What is the minimum number of houses that must be demolished to build the routes between neighborhood A and the neighborhood L?arrow_forward
- Operations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole