Question

In: Computer Science

In Java Part A Fred would like to sell his apartment. He would like to figure...

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

Solutions

Expert Solution

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~


Related Solutions

Jeremy would like to retire in 25 years. He would like his retirement income to be...
Jeremy would like to retire in 25 years. He would like his retirement income to be $250,000, and this figure should grow at the same rate as inflation, expected to be 2 percent annually. He expects to live 30 years after he retires, and plans to leave $3 million to TYU after he dies. Jeremy currently has $1,000,000 in his retirement fund. The fund is expected to earn 6 percent annually. Assuming that Jeremy increases his annual retirement savings by...
Michael will sell his bike because he will move and he has decided to sell it...
Michael will sell his bike because he will move and he has decided to sell it to the first person who offers at least 200 $. Suppose that each price offer given for Michael's bike is independent and exponentially distributed RVs(random variable) with mean $ 100 each. a)   Michael sold his bike on the Kth offer. Find PMF(probability mass function) and mean of K b)   Let the amount of offer which is sold by Michael be X $. Find PDF(Probability...
Fred Flintstone makes a written offer to sell his car to Barney for $5,000 and delivers...
Fred Flintstone makes a written offer to sell his car to Barney for $5,000 and delivers his offer to Barney's office. Barney reads the offer, decides not to accept, and throws the paper in trashcan. Barney's coworker, Perry Prehistoric picks the paper out of the trash, reads the offer and signs the paper indicating his acceptance. He drives to Fred's office to present his acceptance. Is there a contract between Fred and Perry? Briefly explain using legal terms.
Fred, a 40 year old man, goes to see his doctor. He tells her he is...
Fred, a 40 year old man, goes to see his doctor. He tells her he is experiencing weight loss, polyuria, polydipsia, and extreme fatigue. The doctor notes he has a fruity smell to his breath so she orders a fasting glucose for the next day. The fasting glucose was 150 mg/dL (normal range 70-99 mg/dL). Choose the treatment option(s) that best fit this patient's condition. a. a calculated diet and exercise b. metformin HCl (Glucophage) c. vasopressin d. a and...
An investor was afraid that he would become like King Lear in his retirement and beg...
An investor was afraid that he would become like King Lear in his retirement and beg hospitality from his children, so he purchased grain "tithes," or shares in farm output, for 700 pounds. The tithes paid him 73 pounds per year for 30 years. What interest rate did he receive on this investment? (Do not round intermediate calculations and enter your answer as a percent rounded to 2 decimal places, e.g., 32.16.)
Fred Footloose is at it again. In 2019, he returned to his Waterloo home after spending...
Fred Footloose is at it again. In 2019, he returned to his Waterloo home after spending three (3) years in Moose Jaw. When he moved to Moose Jaw in 2016, he had leased his house to a group of university students — you know, the really responsible accounting students. It was good to be back in the Waterloo home that was purchased in 2011 for $200,000. To live in Moose Jaw, he had purchased a house in the “nice” part...
Bilbo Baggins wants to save money to meet his retirement objectives. He would like to be...
Bilbo Baggins wants to save money to meet his retirement objectives. He would like to be able to retire 30 years from now with a retirement income of $13,174 per month for 20 years, with the first payment received 30 years and 1 month from now. After he passes on at the end of the 20 years of withdrawals, he would like to leave an inheritance of $751,229 to his nephew Frodo. Before his retirement, he plans to deposit $2,000...
Macon would like to begin planning for retirement. He has as of his 60th birthday collected...
Macon would like to begin planning for retirement. He has as of his 60th birthday collected $150,000 which he plans to deposit in a bank account earning 4.5% per year compounded yearly. Macon is also willing to begin saving an amount on his 61st birthday, and increase that amount by 3.5% every year. He would like to avail $45,000 on his 70th birthday and keep getting an amount greater than that by 6% every year till his 75th birthday. How...
A bank manager would like the know the mean wait time for his customers. He randomly...
A bank manager would like the know the mean wait time for his customers. He randomly selects 25 customers and record the amount of time wait to see a teller. The sample mean is 7.25 minutes with a standard deviation of 1.1 minutes. Construct a 99% confidence interval for the mean wait time. Round your answers to 2 decimal places. Lower Limit = Upper Limit = Write a summary sentence for the confidence interval you calculated
Your client would like to subdivide his property into 60-acre parcels. He owns the NE ¼...
Your client would like to subdivide his property into 60-acre parcels. He owns the NE ¼ of section 12, and the S ½ of the NW ¼ of section 12. Diagram a solution for the subdivisions?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT