In: Computer Science
JAVA PLEASE
In this project, we are going to build a tiny database organized as a singly linked list for storing and retrieving the information of a group of products on sale. The information of each product includes the following items: Product ID, Name, Seller, Quantity In Stock, Average Shipping Time, Original Price, Current Price. We assume that a node in the linked list should be defined by the following class.
class Product
{
long ID;
String name;
String seller;
long quantityInStock;
int averageShippingTime; // number of days
double originalPrice;
double currentPrice;
// implement the constructors and methods if necessary
}
Then please implement a class ProductList for the linked list according to the following requirements. Also, you need to appropriately define the constructors and methods in the class Product.
(original price - current price)/original price
You need to decide the implementation and usage of any auxiliary methods. You may decide which sorting algorithm is used in sorting a product list. Please provide a main method to show the test cases for all above items and make sure that your source code can be successfully compiled and there is no exception in the run your program.
(20 points) In this project, we are going to build a tiny database organized as a singly linked list for storing and retrieving the information of a group of products on sale. The information of each product includes the following items: Product ID, Name, Seller, Quantity In Stock, Average Shipping Time, Original Price, Current Price. We assume that a node in the linked list should be defined by the following class.
class Product
{
long ID;
String name;
String seller;
long quantityInStock;
int averageShippingTime; // number of days
double originalPrice;
double currentPrice;
// implement the constructors and methods if necessary
}
Then please implement a class ProductList for the linked list according to the following requirements. Also, you need to appropriately define the constructors and methods in the class Product.
(original price - current price)/original price
You need to decide the implementation and usage of any auxiliary methods. You may decide which sorting algorithm is used in sorting a product list. Please provide a main method to show the test cases for all above items and make sure that your source code can be successfully compiled and there is no exception in the run your program.
public class product { long ID; String name; String seller; long quantityInStock; int averageShippingTime; // number of days int originalPrice; int currentPrice; void set(long id,String name,String seller,long quantityInStock, int averageShippingTime, int originalPrice, int currentPrice ){ this.ID=id; this.name=name; this.seller=name; this.quantityInStock=quantityInStock; this.averageShippingTime=averageShippingTime; this.originalPrice=originalPrice; this.currentPrice=currentPrice; } }
/********************** productList***************/
import java.util.LinkedList; import java.util.Arrays; import java.util.Comparator; public class productList { productList(){ LinkedList<product> ll = new LinkedList<product>(); } productList(LinkedList<product> l1){ LinkedList<product> n = new LinkedList<product>(); n=l1; } void ascCurr(LinkedList<product> l){ int x=l.size(); int i=0; product[] p=new product[x]; for(product p1:l) { p[i]=new product(); p[i]=p1;i++; } sortByprice(p); for( i=0;i<x;i++) { System.out.println(p[i].ID+" "+p[i].currentPrice); } } void ascdisc(LinkedList<product> l){ int x=l.size(); int i=0; product[] p=new product[x]; for(product p1:l) { p[i]=new product(); p[i]=p1;i++; } sortBydisc(p); for( i=0;i<x;i++) { System.out.println(p[i].ID+" "+p[i].currentPrice); } } public static void sortByprice(product[] pairs) { Arrays.sort(pairs, new Comparator<product>() { public int compare(product p1, product p2) { return p1.currentPrice.compareTo(p2.currentPrice); } }); } public static void sortBydisc(product[] pairs) { Arrays.sort(pairs, new Comparator<product>() { public int compare(product p1, product p2) { return ((p1.originalPrice-p1.currentPrice)/p1.originalPrice).compareTo(((p2.originalPrice-p2.currentPrice)/p2.originalPrice)); } }); } public static void main(String[] args) { } }