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 list. Program should work for input file containing info for any number of laptops. Use notepad (or any text editor) to create input file "inData.txt". Store input file in the same folder where all files from BlueJ for this program are located.

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 type. Variable list is initialized in the constructor by reading data for each laptop from an input file. Each line in the input file "inData.txt" contains price, brand and size separated by white space. Input file should contain 8 laptops. The data for the first three and last two laptops in the input file should be as follows:

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!