Question

In: Computer Science

Instructions Using the installed software for this course create a generic class called VehicleRental which accepts...

Instructions

Using the installed software for this course create a generic class called VehicleRental which accepts any generic type of Vehicle ( create an instance of Car, Van and MotorCycle classes)

Each type of Vehicle object has methods called drive, start and stop ( add simple print statement)

The VehicleRental class has a method called rent which accept a generic type of Vehicle object, this method will call drive method of passed Vehicle object

The solution will produce the following:

  1. VehicleRental class
  2. Vehicle interface from which following classes will implement
  3. Car, Van and MotorCycle classes
  4. VehicleRentalTest class with main method

Solutions

Expert Solution

Since you have not mentioned the language of your preference, I am providing the code in Java.

CODE

interface Vehicle {

void drive();

void start();

void stop();

}

class Van implements Vehicle {

@Override

public void drive() {

System.out.println("Driving the van...");

}

@Override

public void start() {

System.out.println("Starting the van...");

}

@Override

public void stop() {

System.out.println("Stopping the van...");

}

}

class Car implements Vehicle {

@Override

public void drive() {

System.out.println("Driving the car...");

}

@Override

public void start() {

System.out.println("Starting the car...");

}

@Override

public void stop() {

System.out.println("Stopping the car...");

}

}

class MotorCycle implements Vehicle {

@Override

public void drive() {

System.out.println("Driving the motorcycle...");

}

@Override

public void start() {

System.out.println("Starting the motorcycle...");

}

@Override

public void stop() {

System.out.println("Stopping the motorcycle...");

}

}

class VehicleRental<T extends Vehicle> {

public void rent(Vehicle v) {

v.drive();

}

}

public class Main {

public static void main(String[] args) {

VehicleRental<Car> vr1 = new VehicleRental<>();

vr1.rent(new Car());

VehicleRental<Van> vr2 = new VehicleRental<>();

vr2.rent(new Van());

VehicleRental<MotorCycle> vr3 = new VehicleRental<>();

vr3.rent(new MotorCycle());

}

}

OUTPUT


Related Solutions

1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class this class should contain the following private data types: - name (string) - id number (string) - email (s) - phone number (string) - number of courses (int) - a dynamic array of course objects. the user will specify how many courses are there in the array. the following are public members of the student class: - default constructor (in this constructor, prompt the...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed:...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed: int id, String firstName, String middleName, String lastName, String email, String ssn, int age. The Person class should have getters and setters for all properties other than id. (You may use Eclipse to help you auto-generate these.) Person class should also have a getter for id Create a no-arg constructor for Person In addition to these getters and setters, Person should have the following...
Generic types A class or interface that declares one or more generic variables is called a...
Generic types A class or interface that declares one or more generic variables is called a generic type. In this portion of the activity, you will make a class generic. Open GenericsC.java in jGRASP then compile it. At this point you should be familiar with the two type-safety warnings given by the compiler. You should be able to understand the source of the error: the use of the raw types List and Collection. Since the List being declared (al) is...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
***Given a class called Student and a class called Course that contains an ArrayList of Student....
***Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called dropStudent() as described below. Refer to Student.java below to learn what methods are available.*** Course.java import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{ /** collection of Students */ private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/ public Course(){ roster = new ArrayList<Student>(); } /***************************************************** Remove student with the...
Using Java: Create a class called MyNumber with an integer private attribute. Create a constructor that...
Using Java: Create a class called MyNumber with an integer private attribute. Create a constructor that defines an integer parameter to set the private integer attribute. Create a setter that validates the attribute does not accept a value lower than 2 or the method will throw a IllegalArgumetException. Create a getter to return the private integer attribute value. Define a public method that is called isPrime() that returns a boolean and implements the Sieve of Eratosthenes method. Define a public...
Please solve using jupyter notebook . 10.10- (Invoice Class) Create a class called Invoice that a...
Please solve using jupyter notebook . 10.10- (Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as data attributes—a part number (a string), a part description (a string), a quantity of the item being purchased (an int) and a price per item (a Decimal). Your class should have an __init__ method that initializes the four data attributes....
Create a class called Student which stores • the name of the student • the grade...
Create a class called Student which stores • the name of the student • the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into the grade field. • Calculate the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT