Answer:
// GetData.java
import javax.swing.JOptionPane;
public class GetData
{
public static double getDouble(String s)
{
return Double.parseDouble(getWord(s));
}
public static int getInt(String s)
{
return Integer.parseInt(getWord(s));
}
public static String getWord(String s)
{
return JOptionPane.showInputDialog(s);
}
public static String getString(String s)
{
return JOptionPane.showInputDialog(s);
}
}
// Address.java
public class Address
{
private String street, city, state, zip;
public Address(String str, String city, String st, String zip)
{
street = str;
this.city = city;
state = st;
this.zip = zip;
}
public String getStreet()
{
return street;
}
public String getCity()
{
return city;
}
public String getState()
{
return state;
}
public String getZip()
{
return zip;
}
}
// Manufacturer.java
public class Manufacturer
{
private String companyName;
private Address companyAddress;
public Manufacturer()
{
this.companyName = "";
this.companyAddress = null;
}
public Manufacturer(String compName, Address address)
{
this.companyName = compName;
this.companyAddress = address;
}
public String getCompanyName()
{
return companyName;
}
public void setCompanyName(String companyName)
{
this.companyName = companyName;
}
public Address getCompanyAddress()
{
return companyAddress;
}
public void setCompanyAddress(Address address)
{
this.companyAddress = address;
}
}
// Product.java
import java.text.SimpleDateFormat;
import java.util.Date;
public class Product
{
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
Manufacturer manufacture;
String productName;
int quantity;
double unitPrice;
Date productCreated;
public Product()
{
this.productName = "";
this.quantity = 0;
this.unitPrice = 0.0;
this.productCreated = null;
this.manufacture = null;
}
public Product(String prodName, int quantity, double unitPrice,
Date productCreated, Manufacturer manufact)
{
this.productName = prodName;
this.quantity = quantity;
this.unitPrice = unitPrice;
this.productCreated = productCreated;
this.manufacture = manufact;
}
public Date getProductCreated()
{
return productCreated;
}
public void setProductCreated(Date productCreated)
{
this.productCreated = productCreated;
}
// to get the Manufacturer object
public Manufacturer getManufacture()
{
return manufacture;
}
// to set the Manufacturer object
public void setManufacture(Manufacturer manufacture)
{
this.manufacture = manufacture;
}
// to get the name of the product
public String getProductName()
{
return productName;
}
// to set the name of the product
public void setProductName(String prodName)
{
this.productName = prodName;
}
// to get the quantity of the product
public int getQuantity()
{
return quantity;
}
// to set the quantity of the product
public void setQuantity(int quantity)
{
this.quantity = quantity;
}
// to get the unit price of the product
public double getUnitPrice()
{
return unitPrice;
}
// to set the unit price of product
public void setUnitPrice(double unitPrice)
{
this.unitPrice = unitPrice;
}
// to update the quantity of the product
public void upDateQuantity(int quantity_upDate)
{
quantity += quantity_upDate;
}
// to update the price of the product
public void upDatePrice(double price_upDate)
{
this.unitPrice = price_upDate;
}
public String getProductInfomation()
{
String result = "";
result += String.format("%-30s", productName);
String dateForm = sdf.format(productCreated);
result += String.format("\t %s", dateForm);
result += String.format("%10d", quantity);
result += String.format("\t%15.2f", unitPrice);
result += String.format("\t%15s",
manufacture.getCompanyName());
result += String.format("\t%20s",
manufacture.getCompanyAddress().getState());
return result;
}
}
Explanation:
- Create a manufacturer class to store and get information about company name and company address.
- Create a product class to hold the manufacturer object, product name and other relevant information.