Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this question...I am really stuck at this(especially second part) and I need the answer for first and second parts please so

Please help me with this question...I am really stuck at this(especially second part) and I need the answer for first and second parts please so that I will understand it better. Thank you!!!

Below:

A home inspection & repair company offers three types of service: inspection service, repair service and

emergency service, e

ach with specific costs associated.

-

For the inspection service, it charges a fixed fee per visit.

-

For the repair service, it charges an hour-based fee (hours worked * hourly rate).

-

For the emergency service,

it charges the service cost by multiplying an emergency rate with the hour-

based cost (hours worked * hourly rate * emergency rate).

-

In addition, the company also give certain qualified customers discount.

Use OOP concept of Inheritance to create an inheritance hierarchy to represent various types of services

according the following diagram.

a)

Super class

Service.java

-

It has private instance variables representing the service invoice number, first and last name of the

customer, status of discount qualification, and discount rate.

-

It

includes constructors, getters, setters, and toString methods.

o

The discount rate should be validated in the constructor and setter.

-

It also has a method

calculateCost()

that is supposed to return a double indicating

the cost

associated with the service. This method should re

turn 0.0 in the superclass. (It is up to the subclasses

how to implement it.)

b)

Subclass

InspectionService.java

-

It inherits the functionality of super

Service

, but also includes one data member that represents the

service charge.

-

It includes constructors, getters, setters, and toString methods.

o

The service charge should be validated in the constructor and setter.

-

It should override

calculateCost()

method so that the service charge is returned.

o

If the customer is qualified for a discount, give it to the customer based on discount rate.

c)

Subclass

RepairService.java

-

It inherits the functionality of super

Service

, but also includes two data members that represent the

hours worked and the hourly rate.

-

It includes constructors, getters, setters, and toString methods.

o

The hours worked and hourly rate should be validated in the constructor and setter.

-

It should override

calculateCost()

method so that it returns the hourly-based service charged.

o

If the customer is qualified for a discount, give it to the customer based on discount rate.

d)

Subclass

EmergencyService.java

-

It inherits the functionality of super class

RepairService

, but also includes one data member that

represents a rate that the company charges for the emergency service.

-

It includes constructors, getters, setters, and toString methods.

o

The emergency rate should be validated in the constructor and setter.

-

It should override method

calculateCost()

so that it returns the service charge by multiplying an

emergency rate with the hour-based cost.

o

If the customer is qualified for a discount, give it to the customer based on discount rate.

e)

Write a menu-driven program to test the classes defined above:

Sample Run:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedSecond part:

image text in transcribed

Sample run: run: - - - - - - - - - Welcome to Home Inspection & Repair Co. - - - - - - - - - - - - - - - - - - - - - 1: Inspection Service 2: Repair Service 3: Emergency Service 0: Exit Enter a command: 1 This is an inspection service Enter invoice: 109001 Enter first name: Jon Enter last name: Moore Is the customer qualified for a discount? (Y or N): Y Enter discount rate (12 for 12%): 8 Enter the inspection fee $: 85.99 Invoice #: 109001 Customer Name: Jon Moore Discount Status: true Discount Rate: 8.0% Inspection Fee: $85.99 Inspection Charge with Discount: $79.11 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Welcome to Home Inspection & Repair Co. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: Inspection Service 2: Repair Service 3: Emergency Service 0: Exit Enter a command: 2 This is a repair service Enter invoice: 109002 Enter first name: Tom Enter last name: Jones Is the customer qualified for a discount? (Y or N): Y Enter discount rate (12 for 12%): 13 Enter hours worked: 2.5 Enter hourly rate $: 75 Invoice #: 109002 Customer Name: Tom Jones Discount Status: true Discount Rate: 13.0% Hours Worked: 2.5 Hourly Rate: 75.0 Repair Charge with Discount: $163.13 s Q Weld 0 ID | ! 1 1 1 ----------------------------------- lcome to Home tion & Re pair Co. -------------------- 1: Inspection Service 2: Repair Service 3: Emergency Service 0: Exit Enter a command: 2 This is a repair service Enter invoice: 109003 Enter first name: Jim Enter last name: Smith Is the customer qualified for a discount? (Y or N): N Enter hours worked: 1.5 Enter hourly rate $: 80 Invoice #: 109003 Customer Name: Jim Smith Discount Status: false Discount Rate: 0.0% Hours Worked: 1.5 Hourly Rate: 80.0 Repair Charge: $120.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Welcome to Home Inspection & Repair Co. 1: Inspection Service 2: Repair Service 3: Emergency Service 0: Exit ---------------------------------- Enter a command: 3 This is an emergency service Enter invoice: 109004 Enter first name: Mary Enter last name: Benson Is the customer qualified for a discount (Y or N): Y Enter discount rate (12 for 12%): 15 Enter hours worked: 2 Enter hourly rate $ : 85 Enter emergency rate: 1.5 Invoice #: 109004 Customer Name: Mary Benson Discount Status: true Discount Rate: 15.0% Hours Worked: 2.0 Hourly Rate: 85.0 Emergency Rate: 1.5 Emergency Charge with Discount: $216.75 - - - - - - - - - - - - - - - - - - - ------------ Welcome to Home Inspection & Repair Co. --- --------------- 1: Inspection Service 2: Repair Service 3: Emergency Service 0: Exit - - - - - - - - - - - - - - - - - - Enter a command: 0 Thank you for using this program. 2) OOP Polymorphism / Abstract Class and Method Incorporated the abstract method/class and polymorphism concepts in the home inspection & repair company program you have completed in Assignment 4. The calculateCost method should be an abstract method in the super class. The subclasses must override the superclass' abstract method. Modify the client program to incorporated the polymorphism in the program. - - Use a super class ArrayList to store the subclass objects. Loop through the ArrayList to process all the objects polymorphically. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Welcome to Home Inspection & Repair Co. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: Inspection Service - print the object and add it to the ArrayList 2: Repair Service - print the object and add it to the ArrayList 3: Emergency Service - print the object and add it to the ArrayList 4: Loop through the ArrayList to process the objects polymorphically 0: Exit

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions