Twitter Page 1: 1 2 Question 2 (35 points) public class Plan Demo 3 { {...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Twitter Page 1: 1 2 Question 2 (35 points) public class Plan Demo 3 { { public static void main(String[] args) CommercialPlan cp = new CommercialPlan(12345, "5001 Java blvd, San Diego, CA 92111", "Engineering", 350 0.5); = new Residential Plan (10035, "222 Java In, San Diego, CA 92000", 2, 2400.0); -- -- -- 4 5 ResidentialPlan rp rp.setNumberOfStories(4); System.out.println(cp); System.out.println(); System.out.println(rp); } } public class CommercialPlan { private int parcelNumber; private String address; private String business Type; Favor { private double area; public String approval Process() String result; if(area <3000) result = " \t1-Get permit from the city commercial unit"; else result = " \t1-Get permit from the city commercial unit \t2-Get approval from business office"; return result; public String toString() } } { public class ResidentialPlan tes AirDi Rece Appli Dow Red Page 1: 1 2 3 -- -- 4 5 -- - C (10 Points): Create a new class called Plan Demo2.java and in its main method implement the following: 1. Create two reference variables of type Plan called planCP and planRP. 2. Assign planCP to an instance of the new CommercialPlan class that you created in part B and assign planRP to an instance of the new ResidentialPlan class that you also created in part B. 3. Print both planCP and planRP variables and specify whether the toString() method of the Plan class is called or the toString() methods of the planCP and plan RP classes are called. a. Explain why the above has happened. b. In Object Oriented paradigm, what is this phenomenon called? 4. Call planRP. getNumberOfStories() in PlanDemo2.java. a. What is the result? Explain why it is happening. b. If there is an issue, just explain how it can be fixed (writing code to fix the issue is not necessary). 5. Submit Plan.java, CommercialPlan.java, ResidentialPlan.java, PlanDemo.java and PlanDemo2.java files in a zip file. hot 09 AM hot 27 AM hot 36 AM hot 37 PM Yello Paragraph BI U A/ Oran IIII O + hot 46 PM hot .01 PM Page 1: 1 1 2 1 1 4 5 1 3 H public class Residential Plan { private int parcelNumber; private String address; private int numberOfStories; private double area; public String approvalProcess() { return " \t1-Get permit from the city residential unit"; } public String toString() } In the above code, the Plan Demo class creates instances of Commercial Plan and Residential Plan classes, calls the setNumberOfStories method of the Residential Plan class instance and prints both instances. Your task is to complete the above classes as follows: A - (10 Points): 1. Copy the above classes into their corresponding java files in an IDE of your choice. 2. Complete Commercial Plan and Residential Plan classes by adding: a. Constructors i. Commercial Plan order of parameters: 1. (parcelNumber, String address, String business Type, double area) ii. Residential Plan order of parameters: 1. (parcelNumber, String address, int numberOfStories, double area) b. Setter and getter methods for all their instance variables c. Complete the toString method of each class 2. Run PlanDemo.java and verify that its output is shown without any errors. Although, PlanDemo.java runs fine, however, Commercial Plan and ResidentialPlan classes have a lot of duplicate code. B - (15 Points): Use Inheritance to reduce code duplication, as follows: 1. Create a class called Plan.java. This class will contain the code that is in common between Page 1: 1 2 4 5 1 3 B - (15 Points): Use Inheritance to reduce code duplication, as follows: 1. Create a class called Plan.java. This class will contain the code that is in common between Commercial Plan and ResidentialPlan classes. 2. Add a constructor method to the Plan class, which receives values for all instance variables of the Plan class as parameters. (Note: Do Not add a default constructor to the Plan class) 3. Add a toString() method to the Plan class, which prints all the instance variables of the class. 4. Modify Commercial Plan and Residential Plan classes to create new classes that inherit and use the common code from the Plan.java rather than duplicating them. 5. The approval Process () method, is a good candidate to be implemented as an abstract method. a. Explain why this method should be implemented as an abstract method. b. Implement this method as an abstract method. 6. Run the PlanDemo.java to verify that it runs correctly with your new classes. Specifically, make sure the toString() methods of the new Commercial Plan and Residential Plan classes are working correctly. Note: You should not change the PlanDemo.java class to answer part B. C- (10 Points): Create a new class called PlanDemo2.java and in its main method implement the following: 1. Create two reference variables of type Plan called planCP and plan RP. 2. Assign planCP to an instance of the new Commercial Plan class that you created in part B and assign planRP to an instance of the new ResidentialPlan class that you also created in part B. 3. Print both planCP and planRP variables and specify whether the toString() method of the Plan class is called or the toString() methods of the planCP and planRP classes are Twitter Page 1: 1 2 Question 2 (35 points) public class Plan Demo 3 { { public static void main(String[] args) CommercialPlan cp = new CommercialPlan(12345, "5001 Java blvd, San Diego, CA 92111", "Engineering", 350 0.5); = new Residential Plan (10035, "222 Java In, San Diego, CA 92000", 2, 2400.0); -- -- -- 4 5 ResidentialPlan rp rp.setNumberOfStories(4); System.out.println(cp); System.out.println(); System.out.println(rp); } } public class CommercialPlan { private int parcelNumber; private String address; private String business Type; Favor { private double area; public String approval Process() String result; if(area <3000) result = " \t1-Get permit from the city commercial unit"; else result = " \t1-Get permit from the city commercial unit \t2-Get approval from business office"; return result; public String toString() } } { public class ResidentialPlan tes AirDi Rece Appli Dow Red Page 1: 1 2 3 -- -- 4 5 -- - C (10 Points): Create a new class called Plan Demo2.java and in its main method implement the following: 1. Create two reference variables of type Plan called planCP and planRP. 2. Assign planCP to an instance of the new CommercialPlan class that you created in part B and assign planRP to an instance of the new ResidentialPlan class that you also created in part B. 3. Print both planCP and planRP variables and specify whether the toString() method of the Plan class is called or the toString() methods of the planCP and plan RP classes are called. a. Explain why the above has happened. b. In Object Oriented paradigm, what is this phenomenon called? 4. Call planRP. getNumberOfStories() in PlanDemo2.java. a. What is the result? Explain why it is happening. b. If there is an issue, just explain how it can be fixed (writing code to fix the issue is not necessary). 5. Submit Plan.java, CommercialPlan.java, ResidentialPlan.java, PlanDemo.java and PlanDemo2.java files in a zip file. hot 09 AM hot 27 AM hot 36 AM hot 37 PM Yello Paragraph BI U A/ Oran IIII O + hot 46 PM hot .01 PM Page 1: 1 1 2 1 1 4 5 1 3 H public class Residential Plan { private int parcelNumber; private String address; private int numberOfStories; private double area; public String approvalProcess() { return " \t1-Get permit from the city residential unit"; } public String toString() } In the above code, the Plan Demo class creates instances of Commercial Plan and Residential Plan classes, calls the setNumberOfStories method of the Residential Plan class instance and prints both instances. Your task is to complete the above classes as follows: A - (10 Points): 1. Copy the above classes into their corresponding java files in an IDE of your choice. 2. Complete Commercial Plan and Residential Plan classes by adding: a. Constructors i. Commercial Plan order of parameters: 1. (parcelNumber, String address, String business Type, double area) ii. Residential Plan order of parameters: 1. (parcelNumber, String address, int numberOfStories, double area) b. Setter and getter methods for all their instance variables c. Complete the toString method of each class 2. Run PlanDemo.java and verify that its output is shown without any errors. Although, PlanDemo.java runs fine, however, Commercial Plan and ResidentialPlan classes have a lot of duplicate code. B - (15 Points): Use Inheritance to reduce code duplication, as follows: 1. Create a class called Plan.java. This class will contain the code that is in common between Page 1: 1 2 4 5 1 3 B - (15 Points): Use Inheritance to reduce code duplication, as follows: 1. Create a class called Plan.java. This class will contain the code that is in common between Commercial Plan and ResidentialPlan classes. 2. Add a constructor method to the Plan class, which receives values for all instance variables of the Plan class as parameters. (Note: Do Not add a default constructor to the Plan class) 3. Add a toString() method to the Plan class, which prints all the instance variables of the class. 4. Modify Commercial Plan and Residential Plan classes to create new classes that inherit and use the common code from the Plan.java rather than duplicating them. 5. The approval Process () method, is a good candidate to be implemented as an abstract method. a. Explain why this method should be implemented as an abstract method. b. Implement this method as an abstract method. 6. Run the PlanDemo.java to verify that it runs correctly with your new classes. Specifically, make sure the toString() methods of the new Commercial Plan and Residential Plan classes are working correctly. Note: You should not change the PlanDemo.java class to answer part B. C- (10 Points): Create a new class called PlanDemo2.java and in its main method implement the following: 1. Create two reference variables of type Plan called planCP and plan RP. 2. Assign planCP to an instance of the new Commercial Plan class that you created in part B and assign planRP to an instance of the new ResidentialPlan class that you also created in part B. 3. Print both planCP and planRP variables and specify whether the toString() method of the Plan class is called or the toString() methods of the planCP and planRP classes are
Expert Answer:
Answer rating: 100% (QA)
Lets break down the tasks and address them one by one A Complete the CommercialPlan and ResidentialPlan classes Copy the provided code for CommercialPlan and ResidentialPlan into their respective java ... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
Data set Theory Assume an informational record with one association parent including matches (a, b) where a can't try not to be a parent of b. (a) Write a Datalog demand which gives the graph of...
-
Find the volumes of the solids generated by revolving the regions bounded by the lines and curves about the x-axis. The region between the curve and the x-axis from x = 1/4 to x = 4 y = 1/(2x)
-
What is the purpose of a partnership's obtaining life insurance policies on each of the partners?
-
Transcription factors usually contain one or more motifs that play key roles in their function. What is the function of the following motifs? A. Helix-turn-helix B. Zinc finger C. Leucine zipper
-
Using only the factor formulas given in Table 2.6, derive Equation 7.5 starting with Equation 7.3. TABLE 2.6 Summary of Discrete Compounding Interest Factors. To Find Given Factor Symbol Name P F...
-
Use the following selected data from Success Systems income statement for the three months ended March 31, 2010, and from its March 31, 2010, balance sheet to complete the requirements below:...
-
a.) The following questions refer to the optical cavity in the diagram below. It is excited by a variable frequency source and the detected intensity is displayed on an Optical Spectrum Analyzer....
-
A small, private company is contemplating an initial public offering (IPO) in which they will sell 40,000 shares of stock. The price of the stock at the IPO is uncertain, with the following...
-
A flat tax is a tax on income at the same rate for everyone regardless of how much income they earn. Estonia reduced its rate of flat tax from \(21 \%\) in 2014 to \(20 \%\) in 2015 . What effect can...
-
Haiti was hit by a devastating earthquake on January 12, 2010. A quarter of a million lives were lost and millions more were left injured and homeless. Many countries sent medical teams and medical...
-
A lump-sum tax is a fixed amount of tax per person. If a lump-sum tax, \(T\), raises the same amount of revenue for the government as a tax on earnings at the rate, \(t\), then \(t w H=T\), where...
-
A firm in the state of Karnataka in India can source one of its factors of production either within the state, \(F_{K}\), or from the neighboring state of Maharashtra, \(F_{M}\). Assume the quality...
-
In the Application A Beer Manufacturer's ShortRun Cost Curves," the short-run variable cost function for Japanese beer is \(V C=0.55 q^{1.67}\). If the fixed cost is 600 and the firm produces 550...
-
A store store is looking to stock the following: necklaces, bracelets, rings, and earrings. The objective function measuring profit and constraints are given below. Constraint 1 measures display...
-
Write out the formula for the total costs of carrying and ordering inventory, and then use the formula to derive the EOQ model. Andria Mullins, financial manager of Webster Electronics, has been...
-
What problem do we encounter when we try to construct an array of type E? How do we resolve this problem?
-
Write code to declare an ArrayList holding the first 10 multiples of 2: 0, 2, 4,..., 18. Use a loop to fill the list with the proper elements.
-
Write a reverse Hangman game in which the user thinks of a word and the computer tries to guess the letters in that word. The user tells the computer how many letters the word contains.
-
The expected effect on market efficiency of opening a securities market to trading by foreigners would be to: A. Decrease market efficiency. B. Leave market efficiency unchanged. C. Increase market...
-
Suppose that a speculative-grade bond issuer announces, just before bond markets open, that it will default on an upcoming interest payment. In the announcement, the issuer confirms various reports...
-
1. An analyst estimates that a securitys intrinsic value is lower than its market value. The security appears to be: A. Undervalued. B. Fairly valued. C. Overvalued. 2. A market in which assets...
Study smarter with the SolutionInn App