Question: Part 2 Inheritance, collections and polymorphism Create a new Java project called firstName_lastName_Part2 in Netbeans. Select the option to create a main method. Create a

Part 2 Inheritance, collections and polymorphism Create a new Java project called firstName_lastName_Part2 in Netbeans. Select the option to create a main method.

Create a new class called Computer. Create a second new class called Laptop. Modify the new Laptop class so that it extends Computer (Computer is the superclass; Laptop is the subclass).

Rewrite the program you created in Part 1 so that:

The instance variables and accessor and mutator methods for the make and model are in the Computer class

The two other instance variables and accessor and mutator methods are in the Laptop class 3

The 2 constructors in the Laptop class call the appropriate constructors in the Computer class using the super keyword. The constructor in the Laptop class that takes parameters must initialise the make and model in the Computer class

The Computer class has a method called printDetails that prints the make and model of the computer. Override the printDetails method in the Laptop class and print all of the laptop details as you did in part 1. The printDetails method in the Laptop class must use the super keyword to call the printDetails method in the Computer class

In the main method write the code to:

Declare an ArrayList with a type parameter of Laptop

Add at least 2 laptops to the ArrayList

Use an Iterator (java.util.Iterator) to loop through the laptops in the ArrayList and print out the make and model. Please note that use of any other kind of loop will not receive any marks.

Check if the ArrayList contains a particular laptop

Get a laptop from the ArrayList

Remove a laptop from the ArrayList

Print the size of the ArrayList

Clear the ArrayList In the class that contains the main method, create a second method that takes a Computer as a parameter. Write the code to print out the computers make and model using the Computer accessor methods. Then create an object of type Laptop and an object of type Computer in the main method and use the method you have just created to demonstrate polymorphism

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!