Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING BLUEJ Do folowing changes in LaptopList class 1. Remove public int countExpensive() public Laptop[] expensiveLaptops() 2. Make recursive. public void printList() public void printListReverse()

USING BLUEJ

Do folowing changes in LaptopList class

1. Remove

public int countExpensive()

public Laptop[] expensiveLaptops()

2. Make recursive.

public void printList()

public void printListReverse()

public Laptop mostExpensive()

Redesign main method in TestLaptopList class to:

1. Instantiate an object from LaptopList class

2. Invoke all of the two methods from LaptopList methods mention before

MY CODE:::

File: LaptopList.java

import java.io.*; import java.util.*;

public class LaptopList { // instance variable private ArrayList laptops;

/** * Constructor for objects of class LaptopList */ public LaptopList() throws IOException { String brand; int size; double price; laptops = new ArrayList(); //Opening input file for reading Scanner reader = new Scanner(new File("d:\\Java\\inData.txt")); //Reading data while(reader.hasNext()) { price = reader.nextDouble(); brand = reader.next(); size = reader.nextInt(); //Creating Laptop object Laptop temp = new Laptop(brand, size, price); //Adding to array list laptops.add(temp); } } // prints brand followed by price public void printList() { System.out.println(" Laptop brands and their prices: "); //Iterating over laptops for(int i=0; i mostExp.getPrice()) { //Updating most expensive mostExp = laptops.get(i); } } return mostExp; } // returns count of expensive laptops public int countExpensive() { int cnt=0; //Iterating over laptops for(int i=0; i 2000) { //Incrementing count cnt = cnt + 1; } } return cnt; } // returns an array of expensive laptops public Laptop[] expensiveLaptops() { //Creating an array Laptop[] expLaptops = new Laptop[countExpensive()]; int j=0; //Iterating over laptops for(int i=0; i 2000) { //Storing in array expLaptops[j] = laptops.get(i); j++; } } return expLaptops; } }

File: TestLaptopList.java

import java.io.*;

public class TestLaptopList { //Main method public static void main(String[] args) throws IOException { //LaptopList object LaptopList laptopsLst = new LaptopList(); //Calling methods laptopsLst.printList(); Laptop mostExpen = laptopsLst.mostExpensive(); System.out.println("Most Expensive Laptop is: Brand: " + mostExpen.getBrand() + ", Size: " + mostExpen.getSize() + ", Price: $" + mostExpen.getPrice()); //Array of expensive laptops Laptop[] expensiveArr = laptopsLst.expensiveLaptops(); System.out.println(" Most Expensive Laptops: "); for(int i=0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions