Note: Please read the full question before answering. "Module 1" of the this question is already solved and available on

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Note: Please read the full question before answering. "Module 1" of the this question is already solved and available on

Post by answerhappygod »

Note: Please read the full question beforeanswering. "Module 1" of the this question is already solved andavailable on answers so please do not copy and paste already answeredquestion from answers. You just need to solve "Module 2" part, Ialso added the code of "Module 1" at the end of this question foryour ease. Copy and Paste will not give you positive rating.Thanks
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("------------------------------");
//////////////////////////////////////////////////////////////////////////////////
Code of Module 1 following:
public interface ElectronicDevice {public void Memory(int RAM,int ROM);public void graphicCard();}
public abstract class Computer implements ElectronicDevice {private int RAM;private int ROM;public Computer() {System.out.println("Default constructor called");}public int getRAM() {return RAM;}public void setRAM(int rAM) {RAM = rAM;}public int getROM() {return ROM;}public void setROM(int rOM) {ROM = rOM;}public Computer(int ROM, int RAM) {this.ROM=ROM;this.RAM=RAM;}public void configurations() {};public void graphicCard(String cardspecs) {System.out.println("The graphic card used is :"+cardspecs);}}
public class Laptop extends Computer {String model_name;String company_name;boolean windows_10;public Laptop() {System.out.println("Defauklt constructor called");}public Laptop(String model_name,String company_name,int RAM, intROM) {super(RAM,ROM);this.model_name=model_name;this.company_name=company_name;this.windows_10=true;}public void display() {System.out.println("The Company of Laptop is:"+this.company_name);System.out.println("The model of laptop is:"+this.model_name);if(windows_10) {System.out.println("The windows of the laptop iswindows_10");}System.out.println("RAM Random Access Memory:"+super.getRAM());System.out.println("ROM Read Only Memory :"+super.getROM());}public static void main(String args[]) {// using abstract class and intefaces.System.out.println("---------------------------------------------------------");
System.out.println("The First object");Laptop obj1=new Laptop() ;obj1.model_name="IDEAPAD 530S";obj1.company_name="LENOVO";obj1.setRAM(4);obj1.setROM(16);obj1.display();System.out.println("---------------------------------------------------------");
System.out.println("The second object");Laptop obj2=new Laptop("DELL","WORKPAD",8,32);obj2.graphicCard("NVIDIA");obj2.display();System.out.println("---------------------------------------------------------");}@Overridepublic void Memory(int RAM, int ROM) {int tm=RAM+ROM;}
@override
public void contigurations(){ System.out.print("The total memory:"+tm);}}
public class AssignmentOne {public void demonstratePolymorphism(Laptop obj1) {obj1.display();}public static void main(String args[]) {// polymorphism// here we have just passed the object of LAPTOP and calling thedisplay method to display the fields created in previousclass.AssignmentOne obj=new AssignmentOne();System.out.println("---------------------------------------------------------");
Laptop obj1=new Laptop("Apple","Macbook",8,32);obj.demonstratePolymorphism(obj1);System.out.println("---------------------------------------------------------");}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply