Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Plzzzzzzz do fast Question 3 [20 marks] You should be able to answer this question after you have completed Unit 9. (a) Write a class

Plzzzzzzz do fast

image text in transcribed

image text in transcribed

Question 3 [20 marks] You should be able to answer this question after you have completed Unit 9. (a) Write a class Chair which has two private attributes manufacturer and price. Then add a constructor with two parameters, namely manufacturer and price. It initializes the attributes with the corresponding parameters. You need to use the keyword this to achieve the operations. Copy the content of the class as the answers to this part. [3] (b) Add the getter and setter methods of the attributes manufacturer and price to Chair. Also add the toString() method which returns a string in the form "Chair: Manufacturer A, $200" if the manufacturer is "Manufacturer A" and the price is 200. Copy the content of the methods as the answers to this part c) Write another class TestChair which creates an object chair of the class Chair with manufacturer "Manufacturer A" and price 200. Print out the information of the chair directly using System.out.println() by passing the object chair1 as a parameter. Copy the content of the class and the output as the answers to this part. [2] (d) Change the class Chair to an abstract class. Write down the error(s) indicated. Why such an error occurs? Change it back to a normal class. [2] (e) Add a new class DisplayChair, which has a real attribute discount Percent, as a subclass of Chair. Write the getter and setter methods of discountPercent. Also add a constructor with three parameters (manufacturer, price and discountPercent) and it should call super() with suitable parameters to initialize manufacturer and price. It should also initialize the attribute discount Percent. Add a toString() method which retums a string of the form "Chair. Manufacturer B, $350 and 40.0%", where "Manufacturer B", 350 and 40. are the manufacturer, price and discount percentage respectively. It should call the toString() method of Chair to obtain the first part of the string. Copy the content of the class as the answers to this part. [4] (1) Add statements to the class TestChair to create an object of DisplayChair (with values "Manufacturer 8", 350 and 40.) and assigns it to a Chair variable/reference chair2. Print out the information of this chair directly using System.out.println() by passing the Chair reference as a parameter. Copy the newly added content of the class and output as the answers to this part [21] (9) Add a class method averagePrice(Chair[] chairs) to Chair which returns the average price of the chairs in the array chairs. Discount price (price*(1- discount Percent/100)) should be used for display chair. Each price should be obtained by calling a getPrice() method and the one in the class Chair should be overridden by a new one in the class DisplayChair. Copy the newly added content as the answers to this part. [4] (h) In the class TestChair, add a Chair array chairs of size 2. Assign chair1 to the first eleme and assign chair2 to the second. Print out the average price of the chairs. Copy the newly added content of the class and output as the answers to this part. [2]

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_2

Step: 3

blur-text-image_3

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions