Question

In: Computer Science

JAVA PLEASE In this project, we are going to build a tiny database organized as a...

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.

  1. (5 points) Implementing a constructor for ProductList which creates a product list using the information provided in a file. An example is given in the attachment by the file products.txt.
  2. (5 points) Implementing a constructor for ProductList which creates a new but identical product list based on the given list.
  3. (5 points) Implementing a method in ProductList which shows (displays) the products in the list in the ascending order of the current price.
  4. (5 points) Implementing a method in ProductList which shows (displays) the products in the list in the ascending order of the discount which is calculated as

(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.

  1. (5 points) Implementing a constructor for ProductList which creates a product list using the information provided in a file. An example is given in the attachment by the file products.txt.
  2. (5 points) Implementing a constructor for ProductList which creates a new but identical product list based on the given list.
  3. (5 points) Implementing a method in ProductList which shows (displays) the products in the list in the ascending order of the current price.
  4. (5 points) Implementing a method in ProductList which shows (displays) the products in the list in the ascending order of the discount which is calculated as

(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.

Solutions

Expert Solution

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) {
    }


}

Related Solutions

Java Language Only Use Java FX In this project we will build a BMI calculator. BMI...
Java Language Only Use Java FX In this project we will build a BMI calculator. BMI is calculated using the following formulas: Measurement Units Formula and Calculation Kilograms and meters (or centimetres) Formula: weight (kg) / [height (m)]2 The formula for BMI is weight in kilograms divided by height in meters squared. If height has been measured in centimetres, divide by 100 to convert this to meters. Pounds and inches Formula: 703 x weight (lbs) / [height (in)]2 When using...
Java For this project, we want to build a calculator program that can perform simple calculations...
Java For this project, we want to build a calculator program that can perform simple calculations and provide an output. If it encounters any errors, it should print a helpful error message giving the nature of the error. You may use any combination of If-Then statements and Try-Catch statements to detect and handle errors. Program Specification Input Our program should accept input in one of two ways: If a command-line argument is provided, it should read input from the file...
Suppose you are responsible for a project to build an application that is going to collect...
Suppose you are responsible for a project to build an application that is going to collect all the training opportunities for any summer training program. The purpose of the application is to allow the user to search for the most suitable opportunity for him using different search criteria such as GPA and salary. How you would make a Risk Management plan for such a project? I want a Risk Management plan for this project. thanks.
We started creating a Java class for Car. In this lab we are going to complete...
We started creating a Java class for Car. In this lab we are going to complete it in the following steps: 1- First create the Car class with some required instance variables, such make, model, year, price, speed, maxSpeed, isOn, isMoving, and any other properties you like to add. 2- Provide couple of constructors for initializing different set of important properties, such as make, model, year, and price. Make sure that you do not repeat initialization of instance variables in...
In this activity, we are going to implement the previous algorithm in Java. Just in case,...
In this activity, we are going to implement the previous algorithm in Java. Just in case, here is problem again: This program calculates and displays a person's body mass index (BMI). The BMI is calculated as the weight times 703 divided by the height squared where the weight is measured in pounds and the height in inches. The program should display a message indicating whether the person has optimal weight (BMI between 18.5 and 25), is underweight (BMI is less...
Java Programming Please describe the roles of the following classes in processing a database: Connection ResultSet
Java Programming Please describe the roles of the following classes in processing a database: Connection ResultSet
In this project we are going to model the Ball Toss with a quadratic function. So...
In this project we are going to model the Ball Toss with a quadratic function. So at 30 cm intervals, we draw 4 vertical lines extending from the eraser tray to the top of the marker board. We number the lines with their distances from the left most vertical line (which serves as the y-axis).Each of our volunteers selects a line and stand facing it at close proximity to the board. Between the board and the volunteers, I toss the...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
1. You plan to build a toy house with a tiny light bulb inside that can...
1. You plan to build a toy house with a tiny light bulb inside that can be lit with 1 amp of current, for your little brother to entertain him! You have two D-size (1.5 V each) batteries and two 6-ohm resistors. How can you arrange the resistors to get the desired current? A) resistors should be connected in parallel to each other and this combination in series with batteries B) resistors may be connected in series with each other...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT