Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 [20 points] Implement the class Vehicle only. The code of the classes Bicycle and Car is provided below. Vehicle # brand: String #

Question 1 [20 points]

Implement the class Vehicle only. The code of the classes Bicycle and Car is provided below.

Vehicle

# brand: String

# model: String

# price: double

# checkIn: ArrayList

+ Vehicle ( )

+ Vehicle (---All parameters---)

+ addCheckInLocation (p: String)

+ removeCheckInLocation (p: String)

+ toString( ): String

Bicycle (Do not implement this class)

- gearCount :int

+ Bicycle (---All parameters---)

+toString( ): String

Car

- fuelType : String

+Car(---All parameters----)

+ toString( ):String

  1. The Vehicle class is characterized by four data fields: a String brand, a String model, a double price and an array list of strings checkIn. Write the following methods:

  1. Two constructors (as shown in the UML).
  2. Getters and setters (only for the attributes brand and price).
  3. addCheckInLocation method that takes as parameter the name of a location to be added to the array list. If this name already exist in the list the message EXIST must be displayed.
  4. removeCheckInLocation method that takes as parameter the name of the location to be deleted from the array list.
  5. A toString method to return information about all data fields.

  1. The Bicycle class inherits from the class Vehicle. The code is below:

import java.util.ArrayList;

public class Bicycle extends Vehicle {

private int gearCount;

public Bicycle(int gearCount, String brand, String model, double price, ArrayList checkIn){

super(brand, model, price, checkIn);

this.gearCount = gearCount;

}

public String toString( ) {

return super.toString() + ", the gear count is " + gearCount;

}

}

  1. The Car class inherits from the class Vehicle. The code is below:

import java.util.ArrayList;

public class Car extends Vehicle {

private String fuelType;

public Car(String fuelType, String brand, String model, double price, ArrayList checkIn){

super(brand, model, price, checkIn);

this.fuelType = fuelType;

}

public String toString( ) {

return super.toString() + ", the fuel type is " + fuelType;

}

}

Write a client class (application) in which you:

  1. Define an array (not an ArrayList) of 7 Vehicles, and fill it with 4 Cars and 3 Bicycles objects using values assigned by the programmer. Do not ask the user to enter the values.
  2. Write a static method ArrayList getLocations(Vehicle[ ] vehicles, String location) that takes as parameter an array of vehicles and a String location. This method returns an array list containing the cars (in the array vehicles) checked in the location.
  3. In the main method, use the getLocations method to display the cars checked in Beirut.
  4. Display the information of the most expensive vehicle (the vehicle with the biggest price).

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

Step: 3

blur-text-image

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

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions