To get started Create a new Java project called username-assignment1 in IntelliJ using OpenJDK version 18 as the project

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: 899603
Joined: Mon Aug 02, 2021 8:13 am

To get started Create a new Java project called username-assignment1 in IntelliJ using OpenJDK version 18 as the project

Post by answerhappygod »

To get started
Create a new Java project called username-assignment1 inIntelliJ using OpenJDK version 18 as the project SDK.
In the src directory, create a new class calledAssignmentOne. In the AssignmentOne class create the mainmethod.
Part 1 – Creating abstract classes and interfaces
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 • Atleast one abstract method • At least one non-abstract method • Anyother methods that you feel are necessary for the class to beusable in a program
Part 2 – Using abstract classes and interfaces
Create a class that called Laptop that extends the abstractclass called Computer. The Laptop class should have the followingat a minimum: 3 • At least two instance variables (one of thesevariables must be a boolean as a boolean instance variable isrequired in a later section of the assignment) • A defaultconstructor • A second constructor that initialises all theinstance variables (including the instance variables in theabstract Computer class) • A method that prints the Computersdetails e.g. “The computers details are: “ followed by all instancevariables formatted for readability (including the instancevariables in the abstract Computer class) • Any other methods thatyou feel are necessary for the class to be usable in a program Inthe main method: • Add the following comment - // Part 2 – Usingabstract classes and interfaces • Create two Laptop objects, oneusing the default constructor and the second using the constructorthat sets all of the instance variables • Call the printDetailsmethod on the second object that was created using the constructorthat sets all of the instance variables • 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 asecond comment that explains how you are going to use the methodyou just created to demonstrate your understanding of polymorphism• Write the code to create an object and use the method you justcreated to demonstrate your understanding of polymorphism • Add thefollowing code -System.out.println("------------------------------"); NOTE: Do notremove the code in the main method for Part 2 (or any other part ofthe assignment). You can comment it out when you are developinghowever when you submit your assignment the main method mustcontain all of the code required for all parts of the assignmenti.e. your marker should be able to run your main method and allparts of your assignment should run in one go. 4 Module 2 –Generics and lambdas The following part of the assessment coversthe content in Module 2
Part 4 – Generic classes
In the main method write the code to: • Add the followingcomment - // Part 4 – Generic classes • Declare an ArrayList with atype parameter of Laptop • Add at least 5 Laptop objects to theArrayList • Add the following code -System.out.println("------------------------------"); NOTE: Do notremove the code in the main method for Part 2 or 3.
Part 5 – Generic methods
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. Onceyou have implemented the Comparable interface, in the main method:• Add the following comment - // Part 5 - Generic methods • Writethe code to sort the Arraylist that you created in Part 4. • Addthe 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 mainmethod: • Add the following comment - // Part 6 - Wildcards • Add asecond comment that explains how you are going to use the methodyou just created to demonstrate your understanding of wildcards •Write the code to create an object and use the method you justcreated to demonstrate your understanding of wildcards • Add thefollowing code -System.out.println("------------------------------"); 5
Part 7 – Simple lambda expressions
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 thefollowing comment - // Part 7 - Simple lambda expressions • Writethe code to pass the Arraylist that you created in Part 4 to theDemonstrateLambdas method. • Add the following code -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