Question
In a file Laptop.java, create a Laptop class and make the class implement the Comparable interface. The member variables should include the following laptop configuration
In a file Laptop.java, create a Laptop class and make the class implement the Comparable interface. The member variables should include the following laptop configuration details cpu, ram, hdd, graphics card (boolean 1=yes/0=no), screen size, weight, battery life (hours), and price. The constructor for the class should allow the initialization of all the member variables. The constructor for a Laptop instance should also calculate a score variable out of 10, which will be calculated as follows:
laptopScore = (2 * cpu/cpuMax) + (2 * ram/ramMax) + (1 * hdd/hddMax) + (graphics) + (1 * screen/screenMax) +
(1 * weight/weightMax) + (1 * battery/batteryMax) + (1 * price/priceMax)
Here, use the following max values:
cpuMax = 3.0, ramMax = 32, hddMax = 2048, screenMax = 17.0,
weightMax = 6, batteryMax = 9, priceMax = 2000
Create a method randomLaptopCreator to create a list of 5 laptops with randomly generated configurations for each of the specification variables. Specify the range for the random values for each specification item based on a (reasonably assumed) min value and the max value. You will also create a toString method, which will print out the configuration of a laptop (similar to the octagon problem above) including the laptop score. The overridden compareTo method in the Laptop class should compare the configurations of the laptops based on the laptop score. Next, you will use the Arrays.sort method to sort the list of randomly generated laptops, and print them out (using the toString method) in ascending order.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started