Part 1 - Classes and objects

Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method.

Create a new class called Vehicle. In the Vehicle class write the code for:

  • Instance variables that store the vehicle's make, model, colour, and fuel type
  • A default constructor, and a second constructor that initialises all the instance variables
  • Accessor (getters) and mutator (setters) methods for all instance variables
  • A method called printDetails that prints the Vehicle details e.g. "The vehicle details are:" followed by all instance variables. The output must be formatted for readability

In the main method write the code to:

  • Create 2 vehicles, one using the default constructor, the other using the constructor that initialises all the instance variables for the vehicle.
  • Demonstrate the use of one accessor method, and one mutator method for one of the vehicles you created.
  • Print the vehicle's details using the printDetails method for one of the vehicles you created.

Part 2 - Inheritance, collections and polymorphism

Create a new Java project called usernamePart2 in NetBeans. Select the option to create a main method.

Create a new class called Car. Create a second class called Vehicle. Copy the code from the Vehicle class you created in Part 1 into the new Vehicle class.

Modify the new Car class so that it extends Vehicle (Vehicle is the superclass, Car is the subclass).

In the Car class write the code for:

  • The instance variables that store the transmission type, and body type
  • Accessor and mutator methods for the 2 instance variables
  • A default constructor, and a second constructor that initialises all the instance variables in the Car and the Vehicle classes using the super keyword
  • The Vehicle class has a method called printDetails that prints the Vehicle details. Override the printDetails method in the Car class and print all of the car's details. The printDetails method in the Car class must use the super keyword to call the printDetails method in the Vehicle class.
  • The Car class must also demonstrate the use of overloaded methods

In the main method write the code to:

  • Declare an ArrayList with a type parameter of Car
  • Add at least 2 Cars to the ArrayList
  • Use an Iterator (java.util.Iterator) to loop through the cars in the ArrayList and print out some of their details. Please note that use of any other kind of loop will not receive any marks.
  • Check if the ArrayList contains a particular car
  • Get a car from the ArrayList
  • Remove a car from the ArrayList
  • Print the size of the ArrayList
  • Clear the ArrayList

Please note that collections are covered in Topic 3 and 4. You may need to wait until we have covered these topics to implement your ArrayList.

Polymorphism

In the class that contains the main method, create a second method that takes a Vehicle as a parameter and write the code to print out the vehicle's fuel type using one of the vehicles accessor methods. Then create an object of type Car and an object of type Vehicle in the main method and use the method you have just created to demonstrate polymorphism.

Part 3 - Abstract classes

Create a new Java project called usernamePart3 in NetBeans. Select the option to create a main method.

Create a new class called Car. Create a second new class called Vehicle. Rewrite your code from Part2 so that:

  • The Vehicle class is abstract
  • Car extends Vehicle
  • The Vehicle class contains at least one abstract method

All methods, constructors and instance variables that were in the Car and Vehicle classes in part 2 must be included in part 3. You need to rewrite the Car and Vehicle classes from part 2 so that Vehicle is abstract and there are multiple ways to create a Car.

Check your code works by creating a new Car in your main method.

Part 4 - Interfaces

Create a new Java project called usernamePart4 in NetBeans. Select the option to create a main method.

Create a new class called Car. Create a new interface called Vehicle. Rewrite your code from Part 2 so that:

  • Vehicle is an interface
  • Car implements Vehicle
  • The Vehicle interface contains at least one abstract methods

All methods, constructors and instance variables that were in the Car and Vehicle classes in part 2 must be included in part 4. You need to rewrite the Car and Vehicle classes from part 2 so that Vehicle is an interface and there are multiple ways to create a Car.

In the main method of your project write the code to:

  • Declare a Stack with a type parameter of Car
  • Add at least 3 cars to the Stack
  • Demonstrate the use of:
    • peek()
    • pop()
    • empty()

Part 5 - UML

Create a word document called usernamePart5. Draw 2 UML diagrams to show the inheritance relationship for the Vehicle and Car in part 3 and part 4. Make sure that each diagram has a heading and the header of the word document contains your name and student ID.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.