Question: Java code for extra credit assignment. I have done the first part but need help on the second part(extra credit). below is my code for

Java code for extra credit assignment. I have done the first part but need help on the second part(extra credit). below is my code for the first part.

Java code for extra credit assignment. I have done the first part

but need help on the second part(extra credit). below is my code

public interface RentalCar { public String getDriverName(); public String getMake(); public String getModel();

public void describe(); }

import java.util.ArrayList; import java.util.Random;

public class RentalCarAgency { public ArrayList carList = new ArrayList(); public static void main(String[]args) { RentalCarAgency agency =new RentalCarAgency(); RentalCar a = agency.rentNewCar("Ava"); a.describe(); RentalCar b = agency.rentNewCar("Bella"); b.describe(); } private RentalCar rentNewCar(String name){ Random r = new Random(); RentalCar a = null; int x = Math.abs(r.nextInt() % 3); switch (x) { case 0: RentalCar Toyota = new ToyotaCorolla(name); return Toyota; case 1: RentalCar Honda = new HondaAccord(name); return Honda; default: RentalCar Ford = new FordMustang(name); return Ford; } } }

public abstract class AbstractRentalCar implements RentalCar{ private String driverName; private String make; private String model;

public AbstractRentalCar(String driverName) { this.driverName = driverName; }

public AbstractRentalCar(String driverName, String make, String model) { this.driverName = driverName; this.make = make; this.model = model; } @Override public String getDriverName() { return this.driverName; }

@Override public String getMake() { return this.make; }

@Override public String getModel() { return this.model; } @Override public void describe(){ System.out.println("I am a " + getMake() +" " + getModel() + ", being driven by " + getDriverName() +" "); } }

public class FordMustang extends AbstractRentalCar {

public FordMustang(String name) { super(name, "Ford", "Mustang"); }

}

public class HondaAccord extends AbstractRentalCar {

public HondaAccord(String name) { super(name, "Honda", "Accord"); } }

public class ToyotaCorolla extends AbstractRentalCar {

public ToyotaCorolla(String name) { super(name, "Toyota", "Corolla"); } }

What you need to do Create the interface RentalCar with the following methods o getDriver Name0 returns a String with the current driver's name (e.g., "Jake") o getMake0 returns a String with the car make (e.g., "Toyota") o getModel0 returns a String with the car model (e.g., "Corolla") Create an AbstractRentalCar that implements RentalCar o Defines 3 member variables driver Name (String make (String) model (String) o Has a constructor that allows the driverName, make and model to be set o Implements getDriverName getMake0, and getModel0 0, o Implements a void method called describe0 that prints something like "I am a Toyota Corolla, being driven by Sammy" The make, model, and driver name should be based on what getMake0. getModel0, and 0 return Create 3 classes (ToyotaCorolla, HondaAccord, Ford Mustang that extend AbstractRentalCar, with each also: o Implementing a constructor that takes a driver name only. o In the constructor, class should call parent class constructor with the appropriate driver, make and model information (e.g., Toyota Corolla should set the make to Toyota and model to Corolla, driver name should be set according to what the caller passed in) Create a class called RentalCarAgency o Has one factory style method: rentNewCaro that takes a driver name and returns an RentalCar o Rental Car that is returned is randomly selected, but is assigned to the driver Assuming you implemented the above, implement the following as the main method of 0 Rental CarAgency: public static void main (String[] args RentalcarAgency agency new RentalcarAgency() Rent alcar a agency. rentNewCar("Ava"); a. describe Rent alcar b agency. rentNewCar( Bella") b describe which should result in something like I am a Ford Mustang being driven by Ava I am a Honda Accord, being driven by Bella

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!