Note: Please read the full question beforeanswering. The answer is already available on answers but thatanswer is not the right one so please Do not Copyand Paste here. Only attempt this question If you know how to solveit.
Module 1 - Advanced class design
Part 1- Creating abstract classes andinterfaces
1. Create a new interface called ElectronicDevice with at leasttwo generic methods that would be suitable for any electronicdevice.
2. Create an abstract class called Computer that implements theinterface called ElectronicDevice. The idea behind the Computerabstract class is that it could be used as the super class for morespecific classes of computer devices e.g. laptop, desktop etc. TheComputer class should have the following at a minimum:
• At least two instance variables
• A default constructor
• A second constructor that sets all the instance variables
• At least one abstract method
• At least one non-abstract method
• Any other methods that you feel are necessary for the class tobe usable in a program
Part 2– Using abstractclasses and interfaces
Create a class that called Laptop that extends the abstractclass called Computer. The Laptop class should have the followingat a minimum:
• At least two instance variables (one of these variables mustbe a boolean as a boolean instance variable is required in a latersection of the project)
• A default constructor
• A second constructor that initialises all the instancevariables (including the instance variables in the abstractComputer class)
• A method that prints the Computers details e.g. “The computersdetails are: “ followed by all instance variables formatted forreadability (including the instance variables in the abstractComputer class)
• Any other methods that you feel are necessary for the class tobe usable in a program
In the main method:
• Add the following comment - // Part 2 – Using abstract classesand interfaces
• Create two Laptop objects, one using the default constructorand the second using the constructor that sets all of the instancevariables
• Call the printDetails method on the second object that wascreated using the constructor that sets all of the instancevariables
• Add the following code -System.out.println("------------------------------");
Part 3 – Polymorphism
In the AssignmentOne class, write a method calledDemonstratePolymorphism that takes a Computer or ElectronicDeviceas a parameter. In the method write some code to do something withthe parameter e.g. use its methods in some way.
In the main method:
• Add the following comment - // Part 3 – Polymorphism
• Add a second comment that explains how you are going to usethe method you just created to demonstrate your understanding ofpolymorphism
• Write the code to create an object and use the method you justcreated to demonstrate your understanding of polymorphism
• Add the following code -System.out.println("------------------------------");
Note: In the src directory, create a newclass called AssignmentOne. In the AssignmentOne class create themain method.
Module 2 – Generics and lambdas
The following part of the assessment covers the content inModule 2
Part 4 – Genericclasses
In the main method write the code to:
• Add the following comment - // Part 4 – Generic classes
• Declare an ArrayList with a type parameter of Laptop
• Add at least 5 Laptop objects to the ArrayList
• Add the following code -System.out.println("------------------------------");
NOTE: Do not remove the code in the main method for Part 2 or3.
Part 5 – Genericmethods
Implement the Comparable interface in the Laptop class. When youimplement the compareTo() method from the Comparable interface youmust use at least two instance variables in the comparison.
Once you have implemented the Comparable interface, in the mainmethod:
• Add the following comment - // Part 5 - Generic methods
• Write the code to sort the Arraylist that you created in Part4.
• Add the following code -System.out.println("------------------------------");
Part 6 – Wildcards
In the AssignmentOne class, create a method calledDemonstrateWildcards that takes an ArrayList generic parameter . Inthe method call one of the methods from Computer.
In the main method:
• Add the following comment - // Part 6 - Wildcards
• Add a second comment that explains how you are going to usethe method you just created to demonstrate your understanding ofwildcards
• Write the code to create an object and use the method you justcreated to demonstrate your understanding of wildcards
• Add the following code -System.out.println("------------------------------");
Part 7 – Simple lambdaexpressions
In the AssignmentOne class, create a method calledDemonstrateLambdas that takes an ArrayList of Laptops and aPredicate as a parameter. In the method test the Boolean instancevariable from the Laptop class and print a suitable message basedon whether it is true or false.
in the main method:
• Add the following comment - // Part 7 - Simple lambdaexpressions
• Write the code to pass the Arraylist that you created in Part4 to the DemonstrateLambdas method.
• Add the following code -System.out.println("------------------------------");
Submission
You should now have the following in your main method:
// Part 2 – Using abstract classes and interfaces
Code demonstrating part 2
System.out.println("------------------------------");
// Part 3 – Polymorphism Code demonstrating part 3
System.out.println("------------------------------");
// Part 4 – Generic classes Code demonstrating part 4
System.out.println("------------------------------");
// Part 5 - Generic methods Code demonstrating part 5
System.out.println("------------------------------");
// Part 6 – Wildcards Code demonstrating part 6
System.out.println("------------------------------");
// Part 7 - Simple lambda expressions 6
Code demonstrating part 7
Make sure that none of the code demonstrating each part incommented out.
System.out.println("------------------------------");
//////////////////////////////////////////////////////////////////////////////////
Note: Please read the full question before answering. The answer is already available on answers but that answer is not th
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Note: Please read the full question before answering. The answer is already available on answers but that answer is not th
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!