In: Computer Science
Dream House Question Part 1 You have graduated from HKBU and now have a great job! You have move to the Central district and decide that you want to start saving to buy a house. As housing prices are very high in Hong Kong especially in Central District, you realize you are going to have to save for several years before you can afford to make the down payment on a house. In this exercise, we are going to determine how long it will take you to save enough money to make down payment given the following assumptions: 1. Call the cost of your dream home t_cost . User input 2. Call the portion of the cost needed for a down payment portion_dp. Assume the portion_dp is 10%. 3. Call the amount that you have saved thus far c_savings. Assume the initial c_savings is $0. 4. Assume that you invest your current savings wisely, with an annual return rate is a_rate (in other words, at the end of each month, you receive an additional c_savings*a_rate/12 funds). User input. 5. Assume your monthly salary is m_salary. User input. 6. Assume you are going to dedicate a certain amount of your salary each month to saving for the down payment. Call that portion_saved . User input. 7. At the end of each month, your c_savings will be increased by the return on your investment, plus a percentage of your m_salary. Write a program to calculate how many months it will take you to save up enough money for a down payment. You will want your main variables to be floats, so you should cast user inputs to floats. Your program should ask the user to enter the following variables: A) The starting monthly salary (m_salary) B) The portion of salary to be saved (portion_saved) C) The cost of your dream home (t_cost) D) The annual return rate of investment (a_rate) Your programs need to provide a reasonable answer for the number of months required to pay the down payment Policy for Collaboration may collaborate with anyone, required to write code independently and write names of all collaborators on submission. *** Will check the similarity of program code submitted
here i am uploading the code for this program
****************** code DreamHouse.java*****************
import java.util.Scanner; public class DreamHouse { static void user_input() { float m_salary; int portion_saved; float t_cost; int a_rate; float portion_dp; float c_savings = 0; // initially current saving is $0 int required_month; System.out.println("\nyour initial current saving is: "+c_savings); Scanner scanner = new Scanner(System.in); System.out.print("\nEnter your monthly salary is: "); m_salary = scanner.nextFloat(); System.out.print("Enter the portion you want to save from your monthly salary (percent): "); portion_saved = scanner.nextInt(); // current saving updated by how many percent of your monthly salary you want to save plus your initial current saving c_savings = c_savings + (float)(m_salary*(portion_saved*0.01)); System.out.println("\nyour current saving is "+c_savings+" after "+portion_saved+" percent saving from your monthly salary"); System.out.print("\nEnter cost of your dream home: "); t_cost = scanner.nextFloat(); portion_dp = (float) (t_cost*0.1); // as the downPayment is 10% of our dream home cost System.out.print("\nyour down payment will be: "+portion_dp); System.out.print("\nEnter annual return rate of investment: "); a_rate = scanner.nextInt(); // after investing my money very wisely c_savings = c_savings + (c_savings*a_rate)/(12*100); // now this is actual saving of per month System.out.println("\nafter investing my saving with annual return rate of "+a_rate+" percent my current saving is: "+c_savings); required_month = (int) (portion_dp/c_savings); System.out.println("\n"+required_month+" month required for making "+portion_dp+" down payment"); } public static void main(String[] args) { user_input(); } }
*************** end of code *********************
now i am uploading the sinppet of the output of this program
snippet1: