Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views2 pages

Lab Copied

The document defines an interface ICar and an abstract class CarRent, which includes properties for type and color. It also contains two subclasses, Days and Months, which implement the getPrice method for calculating rental costs based on the number of days or months. A main method demonstrates the creation of car rental instances and prints their details.

Uploaded by

danhm8108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Lab Copied

The document defines an interface ICar and an abstract class CarRent, which includes properties for type and color. It also contains two subclasses, Days and Months, which implement the getPrice method for calculating rental costs based on the number of days or months. A main method demonstrates the creation of car rental instances and prints their details.

Uploaded by

danhm8108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

} public interface ICar

;()double getPrice
{

} public abstract class CarRent implements ICar


;protected String type
;protected String color

} public CarRent(String type, String color)


;this.type = type
;this.color = color
{

;()public abstract double getPrice

Override@
} ()public String toString
;()return "Type: " + type + ", Price: " + getPrice
{
{

} public class Days extends CarRent


;private int noOfDays

} public Days(String type, String color, int noOfDays)


;super(type, color)
;this.noOfDays = noOfDays
{

Override@
} ()public double getPrice
;return noOfDays * 100
{

Override@
} ()public String toString
;return super.toString() + ", No. of Days: " + noOfDays
{
{
} public class Months extends CarRent
;private int noOfMonths

} public Months(String type, String color, int noOfMonths)


;super(type, color)
;this.noOfMonths = noOfMonths
{

Override@
} ()public double getPrice
;return noOfMonths * 1500
{

Override@
} ()public String toString
;return super.toString() + ", No. of Months: " + noOfMonths
{
{

} public class CarRentalApplication


} public static void main(String[] args)
;CarRent carRent1 = new Days("Sedan", "Red", 5)
;CarRent carRent2 = new Months("SUV", "Blue", 2)

;System.out.println(carRent1.toString())
;System.out.println(carRent2.toString())
{
{

You might also like