edesign LaptopList class from previous project public class LaptopList { private class LaptopNode //inner class { public String brand; public double price; public LaptopNode next;
- Redesign LaptopList class from previous project
public class LaptopList
{
private class LaptopNode //inner class
{
public String brand;
public double price;
public LaptopNode next;
public LaptopNode(String brand, double price)
{
// add your code
}
public String toString()
{
// add your code
}
}
private LaptopNode head; // head of the linked list
public LaptopList(String fname) throws IOException
{
File file = new File(fname);
Scanner scan = new Scanner(file);
head = null;
while(scan.hasNextLine())
{
// scan data
// create LaptopNode
// call addToHead and addToTail alternatively
}
}
private void addToHead(LaptopNode node)
{
// add your code
}
private void addToTail(LaptopNode node)
{
// add your code
}
private void print_reverse(LaptopNode node)
{
// add your code, it must be recursive method
}
public void print_reverse()
{
print_reverse(head);
}
public String toString()
{
// add your code, it must be recursive method
}
}
-----Laptop.java-------
class Laptop implements Comparable
{
public enum SortSearchMode {brand, price};
private int size;
private String brand;
private double price;
private static SortSearchMode mode = SortSearchMode.brand;
public Laptop(String brand, int size, double price)
{
this.size = size;
this.brand = brand;
this.price = price;
}
public static void setSortSerach(SortSearchMode mode1)
{
mode = mode1;
}
@Override
public int compareTo(Laptop other)
{
if (mode == SortSearchMode.price) {
return this.price - other.price > 0 ? 1 : this.price - other.price < 0 ? -1 : 0;
} else {
return this.brand.compareTo(other.brand);
}
}
public boolean equals(Object other)
{
if (this == other) {
return true;
}
Laptop temp = (Laptop) other;
if (mode == SortSearchMode.price) {
if (this.price == temp.price) {
return true;
}
return false;
} else {
if (this.brand.equals(temp.brand)) {
return true;
}
return false;
}
}
@Override
public String toString()
{
return this.brand + " " + this.price + " " + this.size + "\"\n";
}
}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









