Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

First, create a new java file named House.java. At the beginning of this file, copy the program header from line 1~11 in file CorrectSequence.java to

First, create a new java file named House.java. At the beginning of this file, copy the program header from line 1~11 in file CorrectSequence.java to House.java, then change line 1, 3, 4, and line 7~10, to make these lines suitable for file House.java. Then right after the program header, please write down the definition line for public class House. Then in the body of this class House, do the following:

1. define two private data member: total price of double type (for example, a value of 168000 indicates that this house is worth 168000 dollars), and total square feet of double type (for example, a value of 2398 indicates that this house has 2398 square feet in total).

2. define two public constructors, the first one is the default constructor with no parameter, and the second one has two formal parameters to initialize the two private data members of this class.

3. for every data member, provide a public getter and a public setter, so there are two getters and two setters in total. Refer to the BookOrder.java for examples of getter and setter methods

. 4. provide a public method named calcPricePerSqf . This method returns the average price per square foot of the house by dividing the total price by the total square feet. The return type of this method is double. This method does NOT need any formal parameter, because as a public member method, this method can directly access the private data members of the same class.

5. provide a public method named calcPropertyTax. This method returns a double type value, which is the property tax of this house. This method needs only ONE formal parameter, which is a double type variable named taxPercentage. The property tax of the house is calculated by multiplying the total price of the house (a private data member of the class) with the tax percentage (the formal parameter of this method). For example, if the tax percentage is 1.25 percent for a house of 160000 dollars, then the property tax is 160000 * 1.25 * 0.01 = 2000 dollars. Notice that the 0.01 in the above formula is to convert the 1.25 percent to the real value. Attention: taxPercentage is a formal parameter of this method, and it is NOT a data member of the House class, therefore, do not make the mistake of setting taxPercentage as a private data member of the House class, and if you do that, you are in the wrong track!!!!

Secondly, in the same Eclipse project you created earlier for this homework, new a second java file named JohnDoeHw4.java, which has the application class JohnDoeHw4 (replace JohnDoe with your first and last name). At the beginning of JohnDoeHw4.java, copy the program header from file CorrectSequence.java (line 1~11) to JohnDoeHw4.java , then modify line 1, 3, 4, and line 7~10 to make them suitable for JohnDoeHw4.java. This class has only one method name main, then provide a line like this as the first line inside the main method, which outputs your name, course meeting time, and class and semester info, such as: System.out.println("Spring 2018, Java, Wedn 5:30pm, John Doe, hw4"); Then after this first line inside the main method, do the following:

1. create two House objects using the constructor with two parameters, plug in the data below as the actual parameters of the constructor. Each line below contains the two actual parameters for one object: 295000.0 3395.0 189000.0 1675.0 , where the 1st column is total price, and the 2nd column is total square feet. Notice how myOrder object is created in file TestBookOrder.java, and see which constructor is used. create the third House object using the default constructor. Then ask the user to input the two parameters with a Scanner type variable. Then use the setters to set the user input values into the third object object. No data type or range checking of the input parameters is needed. Notice how hisOrder object is created in file TestBookOrder.java, and which constructor is used, and how to customize the object with the desire parameters using setter methods

. 2. Prompt the user to input a tax percentage. For example, a user input of 1.25 means 1.25%. This property tax value will be used in the next step to calculate the property taxes for all three house objects.

3. For each individual House object, invoke two methods: calcPricePerSqf () and calcPropertyTax() and store the results in two local variables, respectively. For method calcPropertyTax, you need to plug in the tax percentage variable obtained in step 3 above. In summary, you have 6 variables that store the results for three house objects.

4. For each house object, output its total square feet, total price, average price per square feet, and the property tax. If the output information exceeds 80 columns, you need to output them in multiple lines, with each line less than 80 columns. Use System.out.printf() method, and format the total square feet with one digits after the decimal point, and the other three output items with two digits after the decimal point (because they are money values). Assume that the total square feet in each house object is less than 10000 square feet, and the total price of each house is less than 1000000 dollars. Hint: %8.1f can be used for one digit of precision output, and %8.2f can be used for two digits of precision output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Create a workflow analysis.

Answered: 1 week ago