Question
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: Laptop.java
public class Laptop { // instance variables private int size; private String brand; private double price;
/** * Constructor for objects of class Laptop */ public Laptop() { // initialise instance variables size = 0; brand=""; price=0.0; } /** * Constructor for objects of class Laptop */ public Laptop(String brand, int size, double price) { // initialise instance variables this.size = size; this.brand = brand; this.price = price; } //Getter method for brand public String getBrand() { return this.brand; }
//Getter method for size public int getSize() { return this.size; }
//Getter method for price public double getPrice() { return this.price; }
// returns true if price is greater than $2,000.00 public boolean isExensive() { //Checking price if(this.price > 2000) { return true; } return false; } }
File: LaptopList.java
import java.io.*; import java.util.*;
public class LaptopList { // instance variable private ArrayList
/** * Constructor for objects of class LaptopList */ public LaptopList() throws IOException { String brand; int size; double price; laptops = new ArrayList
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
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