In: Computer Science
In Java
Part A
Fred would like to sell his apartment. He would like to figure
out how much money he will spend at the closing. His lawyer needs
to be paid $1,800 for his services. He needs to pay the co-op $500.
Sellers pay a state and city combined transfer tax of 1.825 percent
if the sale price is over $500,000 or 1.4 percent for deals under
$500,000. The broker will collect 15% of the sale price at closing.
He has the option of removing his furniture himself or hiring the
broker to do it. If he would like the broker to remove the
furniture he needs to pay an additional $1,000 for the
service.
Part B
Write a program that stores the price of an apartment and whether
he would like the broker to remove the furniture and then will
calculate and output: the amount of tax to pay, the amount the
broker will collect, and the total amount he will pay at closing.
Make sure your program performs the calculations!
Part B
Modify your program as follows: Ask the user for the selling price of the apartment and whether they want to remove the furniture on their own as input, and then print out the same information as in the initial apartment sale assignment. Perform input validation to make sure the numbers entered by the user are reasonable (non-negative, not unusually large, etc). Let the calculations repeat for several apartment sales until the user wishes to quit the program. Remember: Use variables or named constants to store all numbers so that they can be changed later on if necessary. Do not repeat calculations unnecessarily! Test your program with different values for the variables to make sure it works in all scenarios!
Write the program in Java please
Program Code to Copy:
// PART A
public class ApartmentSale {
public static void main(String[] args) {
// constants
final double LAWYER_FEE =
1800;
final double COOP_FEE = 500;
final double TAX_RATE1 = 0.01825;
// 1.825%
final double TAX_RATE2 = 0.014; //
1.4%
final double BROKER_FURNITURE_FEE =
1000; // furniture
final double BROKER_RATE = 0.15; //
15%
// variables
double price;
boolean furnitureBroker;
double taxAmount;
double brokerAmount = 0;
double totalAmount;
// modify here to get different
results
price = 200000;
furnitureBroker = true;
// compute tax amount
if(price>=500000)
taxAmount =
price * TAX_RATE1;
else
taxAmount =
price * TAX_RATE2;
// compute broker amount
brokerAmount = price *
BROKER_RATE;
if (furnitureBroker)
brokerAmount +=
BROKER_FURNITURE_FEE;
// compute total amount
totalAmount = price + taxAmount +
brokerAmount + LAWYER_FEE + COOP_FEE;
// display results
System.out.println("Amount of tax
to pay: $"+taxAmount);
System.out.println("Amount the
broker will collect: $"+brokerAmount);
System.out.println("Total amount to
pay at closing: $"+totalAmount);
}
}
_______________________________________________
import java.util.Scanner;
// PART B
public class ApartmentSale {
public static void main(String[] args) {
// console input object
Scanner input = new
Scanner(System.in);
// ------CONSTANTS-----
final double LAWYER_FEE =
1800;
final double COOP_FEE = 500;
final double TAX_RATE1 = 0.01825;
// 1.825%
final double TAX_RATE2 = 0.014; //
1.4%
final double TAX_THRESHOLD_AMOUNT =
500000; // to decide TAX_RATE1 or TAX_RATE2
final double BROKER_FURNITURE_FEE =
1000; // furniture
final double BROKER_RATE = 0.15; //
15%
final double REASONABLE_MAX_PRICE =
5000000; // modify to any value
final double REASONABLE_MIN_PRICE =
LAWYER_FEE + COOP_FEE; // modify to any value
// -----VARIABLES-----
// computation variables
double price;
boolean furnitureBroker;
double taxAmount;
double brokerAmount;
double totalAmount;
// validation and decision
variables
boolean invalidInput;
boolean moreApartments;
// -----MAIN PROGRAM ------
// loop to deal several
apartments
do {
moreApartments =
false;
brokerAmount =
0;
// loop to deal
with input validation for selling price
do {
invalidInput = false;
System.out.println("Enter selling price:
");
price = input.nextDouble();
if (price<REASONABLE_MIN_PRICE ||
price>REASONABLE_MAX_PRICE) {
System.out.println("Invalid
input, give input between $"+
REASONABLE_MIN_PRICE+" and
$"+REASONABLE_MAX_PRICE);
invalidInput = true;
}
}while(invalidInput);
// after user
has entered valid selling price...
System.out.println("Do you want to remove the furniture on their
own? (Y/N): ");
furnitureBroker
= !(input.next().equalsIgnoreCase("Y"));
// compute tax
amount
if(price>=TAX_THRESHOLD_AMOUNT)
taxAmount = price * TAX_RATE1;
else
taxAmount = price * TAX_RATE2;
// compute
broker amount
brokerAmount =
price * BROKER_RATE;
if
(furnitureBroker)
brokerAmount += BROKER_FURNITURE_FEE;
// compute total
amount
totalAmount =
price + taxAmount + brokerAmount + LAWYER_FEE + COOP_FEE;
// display
results
System.out.println("Amount of tax to pay: $"+taxAmount);
System.out.println("Amount the broker will collect:
$"+brokerAmount);
System.out.println("Total amount to pay at closing:
$"+totalAmount);
// decide on
continuity
System.out.println("\nMore apartments? (Y/N): ");
moreApartments =
input.next().equalsIgnoreCase("Y");
}while(moreApartments);
// finally, no more
apartments
System.out.println("\nThanks for
using this service.");
}
}
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~