Question
Pleas e implement the required methods in Store.java and Supply.java. In Store.java, you will practice operates on one dimensional array. In Supply.java, you will practice
Pleas e implement the required methods in Store.java and Supply.java. In Store.java, you will practice operates on one dimensional array. In Supply.java, you will practice operates on two-dimensional array. We are working on fundamental array structure, no class from Java Collection Framework (such as ArrayList) should be used here.
JAVA PROGRAMMING LANGUAGE
Please Help With
1. Implement the 6 required methods in Store.Java
2. Implement the 6 required methods in Supply.Java
Product.Java :
public class Product { public String name; private String barCode; private int number;
public Product(String barCode) { this.barCode = barCode; this.number=0; }
public Product(String barCode, int number) { this.barCode = barCode; this.number = number; }
public Product(String name, String barCode, int number) { this.name = name; this.barCode = barCode; this.number = number; }
public int getNumber() { return number; }
public void setNumber(int number) { this.number = number; }
public String getBarCode() { return barCode; }
@Override public boolean equals(Object obj) { //use this method to compare if two products are equal if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Product other = (Product) obj; if (barCode == null) { if (other.barCode != null) return false; } else if (!barCode.equals(other.barCode)) return false; return true; }
@Override public String toString() { return "["+name+"_"+number+"]\t"; } }
Store.Java:
import java.util.Scanner;
public class Store { private String name; private String address; private int currNum;//record the number of stored products, initialize to 0 private int maxNum; // record the maximum capacity of the array private Product[] products;//an array stores all products of the store
public Store(String name, String address, int maxNum) { //provide a constructor that initialize the array and data field based on provided information }
//check is produce item is stored in products or not, return the index of the item if found, otherwise return -1 public int isSold(Product item) { //check if Product p is sold-- if any element in products equals p //for each element in products //if the element equals to item, return the index //return -1 }
//add a newItem into the products array if it is found. Return true if newItem inserted successfully, otherwise, return false //you can use currNum to trace the index of next available spot, update this number whenever insert a new item public boolean addProduct(Product newItem) { //if newItem can not found in products, return false //else add it to products array, then return true }
//remove a targetItem from the products array if found, return true if remove successfully, otherwise, return false //fill the blank and update currNum if you use currNum in addProduct to trace the next available spot public boolean removeProduct(Product targetItem) { //if targetItem can not found in products, return false //else //for each element in products //if the element equals to targetItem //remove the element and then return true--you may need to do more depends on how you implement your addProduct } //return the barCode of the product with maximum stock level public String maxStock() { //initial a var to the first product //for each element in products //if the stock level of the element is higher than stock level of var, update var to the element //return the barcode of the product with maximum stock level }
//print the detailed store info, name, address and products sell in the store public void print(){ //print the name and address //use a for loop to print out all elements in products array }
}
Supply.Java:
public class Supply{ int numP;//total number of products int numS;//total number of supplier private int[][] supplyRecords;//this two d array is used to show the relation that if a product is supplied by a supplier. //twoDarray[5][6] is 0 means products indexed 5 is not supplied by supplier indexed at 6. TwoDarray[5][6] is 1 means the supply relationship exists. //The row is the products information, the column is the suppliers information
//**********************Your task starts here****************************** public Supply(int numP, int numS) { super(); this.numP = numP; this.numS = numS; supplyRecords = new int[this.numP][this.numS]; for(int i=0;i //if product indexed at productID is not supplied by supplied indexed at supplyID, change the value to 1 to establish the supply relation. return true if insert successfully, otherwise, return false public boolean insert(int productID, int supplyID) { //if supplyID is a supplier of productID //return false //otherwise, set supplyID as productID's supplier } //if product indexed at productID is supplied by supplied indexed at supplyID, change the value to 0 to remove the supply relation. return true if remove successfully, otherwise, return false public boolean remove(int studID, int courseID) { } //check the number of supplier for product indexed at productID --operate one row on two D array public int supplySum(int productID) { //sum the element at row indexed at productID to return the total number of supplier that provides supply for product indexed at productID } //check the number of products supplied by supplier indexed at supplyID --operate one column on two D array public int productSum(int supplyID) { //sum the element at column indexed at supplyID to return the total number of products that supplied by this supplier } //find and return the index of the supplier that supplies the maximum of products--return the column index with the highest column sum public double maxSupplier() { //for each column, get the column sum //return the column with maximum sum } //print supplyRecords--use nested for loop to print the contents of supplyRecords public void print() { //for each row //for each column //print the element //change line so that next row will be printed at next line } } testDriver.Java: public class testDriver { public static void main(String[] args) { Product p1= new Product("ice cream","000", 10); Product p2= new Product("Bob", 1); Product p3= new Product("Charlie", 2); Product p4= new Product("Bob", 1); Product p5= new Product("Charlie", 2); Store store = new Store("Test Store", "012road", 4);//create a store can at most sell 4 products store.addProduct(p1); store.addProduct(p2); store.addProduct(p3); store.addProduct(p4); store.print(); System.out.println(store.addProduct(p5)); System.out.println(store.removeProduct(p5)); System.out.println(store.removeProduct(p4)); System.out.println(store.isSold(p4)); System.out.println(store.isSold(p3)); store.print(); System.out.println(store.maxStock()); Supply supply = new Supply(4, 3); supply.insert(0, 0); supply.insert(0, 2); supply.insert(1, 0); supply.insert(2, 0); supply.insert(2, 1); supply.insert(3, 1); supply.print(); System.out.println(supply.productSum(2)); System.out.println(supply.supplySum(0)); System.out.println(supply.maxSupplier()); System.out.println(supply.remove(2, 1)); System.out.println(supply.remove(3, 2)); supply.print(); } }
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