Question: Use BlueJ to write a program that reads a sequence of data for several Laptop objects from an input file. It stores the data in
Use BlueJ to write a program that reads a sequence of data for several Laptop objects from an input file. It stores the data in an ArrayList
Class Laptop describes one laptop object and has variables brand of String type, size of int type and price of double type. Besides constructor, class Laptop has methods:
public String getBrand() // returns brand
public int getSize() // returns size
public int getPrice() // returns price
public boolean isExensive() // returns true if price is greater than $2,000.00
Design class LaptopList that has instance variable list which is of ArrayList
1200.99 Dell 11
2100.00 Alien 15
1800.00 Sony 12
Insert here remaining four laptops of your choice, two should be expensive.
2550.50 Apple 17
1639.99 Asus 11
Class LaptopList also has the following methods:
- public void printList() // prints brand followed by price
- public Laptop mostExpensive() // returns most expensive laptop.
- public int countExpensive() // returns count of expensive laptops.
- public Laptop[] expensiveLaptops() // returns an array of expensive laptops
Class TestLaptopList will have main method. In it, instantiate an object from LaptopList class and use it to invoke each of the four methods from LaptopList class. If method mostExpensive encounters more than one candidates returns the laptop with bigger size.
NOTE: Do not forget to append throws IOException to the constructor of LaptopList class and main method in class TestLaptopList. In addition, you have to provide
import java.io.*;
import java.util.*;
in order to use File, Scanner and ArrayList classes from Java.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
