Create a Java program that meets the below parameters with test class and getDat
ID: 3741944 • Letter: C
Question
Create a Java program that meets the below parameters with test class and getData class example included below.
(a) Understand the concepts cohesion, and how it can be used to decompose problem definition into separate components (classes).
(b) Understand t and coupling and how it is used to assemble the components (classes) into complete programs. The establishment called ABC Enterprise requires a Java program to keep a database of the inventory of the products that it sells. Each product is identified by its manufacturer, its name, the quantity, and unit price. Note: a manufacturer is characterized by its company’s name and address In addition to storing the information, the program should be able to make updates to the quantity and/or the price as time goes on. That is, when a sale is made, the quantity of that product must be reduced; similarly, when a product is re-ordered, the quantity of that product must be increased. Also, when there is a change in the price of a product, the price must be changed. The change must be interpreted as a replacement of the value. New products may be added to the inventory at any time; also, a product may be removed from the inventory at any time. Maintain a separate list the products that have been deleted from the database of active products. Your program must be able to produce three kinds of reports, namely:
(a) Locate a single product and display its name, price and quantity alone.
(b) The inventory report should be structured as follows:
Product Purchase Date Quantity Price Manufacturer State
Telephone 01/20/2013 10 254.99 Motorola FL
Computer 01/06/2013 15 756.99 CBS NY
: : : : : : : : : : : :
(c) A list of the deleted products should be structured as follows:
Product Date Manufacturer Paper reams
01/20/2013 Morgan Jewelry
: : :
In your design, convince yourself that you need a minimum of four classes, not including the test class – Product, Manufacturer, Address, and Database. You may use the class called GetData.java below, Use a scrollable panes to display your output.
1. import javax.swing.JOptionPane; 2. class GetData 4 public static double getDouble (String s) 6. 7. 8. return Double.parseDouble(getWord(s); public static int getInt (String s) 10. return Integer.parseInt(getWord(s): 12. public static String getWord (String s)Explanation / Answer
import java.util.*;
class Product
{
Manufac manu;
String name;
int quantity;
float price;
}
class Manufac
{
String namem;
Addr address;
public Manufac(Addr aa,String a)
{
this.namem=a;
this.address=aa;
}
}
class Addr{
String addre;
public Addr(String a)
{
this.addre=a;
}
}
class Inventory
{
String date;
String state;
Product pr;
public Inventory(String dat,String stat,Product p)
{
this.pr=p;
this.date=dat;
this.state=stat;
}
}
class main{
public static void main (String[] args) {
Addr addr1=new Addr("Random address 1");
Addr addr2=new Addr("Random address 2");
Manufac manu1=new Manufac(addr1,"Motorola");
Manufac manu2=new Manufac(addr2,"CBS");
Product prod1=new Product("Telephone",10,254.99,manu1);
Product prod2=new Product("Computer",15,756.99,manu2);
ArrayList<Inventory> list=new ArrayList<Inventory>();
ArrayList<Inventory> del_list=new ArrayList<Inventory>();
ArrayList<Product> prodlist=new ArrayList<Product>();
prodlist.add(prod1);
prodlist.add(prod2);
get_prod_details(prodlist,manu1); //finding the details of the product given the manufacturer name
Inventory i1=new Inventory(prod1,"01/20/2013", "FL");
list.add(i1);
Inventory i2=new Inventory(prod2,"01/06/2013", "NY");
list.add(i2);
show_inventory(list);
delete_prod(prod1,"01/20/2013",list,del_list);
show_deleted_inventory(del_list);
}
void delete_prod(Product pp,String a,ArrayList<Inventory> ar,ArrayList<Inventory> arr)
{
String nam=pp.name;
Inventory i=new Inventory(a,"",pp);
arr.add(i);
for(int i=0;i<ar.length();i++)
{
Inventory g=ar.get(i);
String temp=g.pr.name;
if(temp==nam)
{
arr.remove(i);
break;
}
}
}
void show_inventory(ArrayList<Inventory> ar)
{
for(int i=0;i<ar.length();i++)
{
Inventory i=ar.get(i);
String stat=i.state;
String dat=i.date;
Product p=i.pr;
String man_name=p.manu.namem;
String nam=p.name;
int quant=p.quantity;
float pric=p.price;
System.out.println("Name -- " + nam + "Purchase Date -- " + dat + "quantity --" + quant + " Price --" + pric+ "manufacturer --" + man_name+ "State --" + stat);
}
}
void show_deleted_inventory(ArrayList<Inventory> ar)
{
for(int i=0;i<ar.length();i++)
{
Product p=ar.get(i);
String name=p.manu.namem;
String datee=ar.get(i).date;
System.out.println("Date -- " + datee + "Name of manufacturer -- " + name);
}
}
void get_prod_details(ArrayList<Product> arr,Manufac man)
{
String temp1=man.namem;
for(int i=0;i<arr.length();i++)
{
Product temmpp=arr.get(i);
Manufac mmf=temmpp.manu;
String temp2=mmf.namem;
if(temp1.equals(temp2))
{
System.out.println("Name -- " + temmpp.name + "Quantity -- " + temmpp.quantity + "Price -- "+ temmpp.price);
break;
}
}
}
}
Points to be noted:-