Parent class: Motovehicle
Public abstract class Motovehicle {
String No;
String brand;
String color;
String mileage;
int days;
public abstract float calcrent (int days); }
Sub-class 1:car
Public final class Car extends Motovehicle {
String type;
@Override
public float calcrent (int days) {
float rent = 0;
if (Type.equals ("Buick Business Class GL8")) {
Rent = 600*days;
}else if (type.equals ("BMW 550i")) {
Rent = 500*days;
}else if (type.equals ("Buick Boulevard")) {
Rent = 300*days;
}
return rent;
}
Public Car () {
Super ();
}
Public Car (String type) {
Super ();
This.type = type;
}
}
Sub-class 2:bus
Public final class Bus extends Motovehicle {
int seatcount;
@Override
public float calcrent (int days) {
float rent = 0;
if (seatcount<=16) {
Rent = 800*days;
}else{
Rent = 1500*days;
}
return rent;
}
Public Bus () {
Super ();
}
Public Bus (int seatcount) {
Super ();
This.seatcount = Seatcount;
}
}
Test class: Motovehicletext
Import Java.util.Scanner;
public class Motovehicletext {
public static void Main (string[] args) {
String kind;
float rent = 0;
Scanner input = new Scanner (system.in);
System.out.println ("Please enter the type of rental car");
Kind = Input.next ();
if (Kind.equals ("Car")) {
Car A = new car ();
System.out.println ("Please enter the rental time:");
A.days = Input.nextint ();
System.out.println ("Please enter the model number of the car rental:");
A.type = Input.next ();
Rent = a.calcrent (a.days);
}else if (kind.equals ("Bus")) {
Bus B = new bus ();
System.out.println ("Please enter the rental time:");
B.days = Input.nextint ();
System.out.println ("Please enter the number of seats for the rental car:");
B.seatcount = Input.nextint ();
Rent = b.calcrent (b.days);
}
System.out.println ("Your rental fee is +rent");
Input.close ();
}
}
Write a rental information for a leasing company in polymorphic form