Hello,
Can anyone please help me... I need to create a GUI program that holds product inventory.
I have five errors and I can't figure out what they are... I need a second look from someone... Thanks in advance!
import javax.swing.*;
import java.awt.*;
import java.text.NumberFormat;
import java.util.Locale;
public class Product extends JFrame {
public Product()
{
super("Product Inventory");
Container container = getContentPane();
container.setLayout(new FlowLayout());
ProductList[] inventory = new ProductList[4];
inventory[0] = new ProductList( "CEB32000", "Highlighter", 30, 5.75, .05 );
inventory[0] = new ProductList( "CEB32001", "Manila Folder", 45, 3.25, .05 );
inventory[0] = new ProductList( "CEB32002", "Scissors", 36, 2.75, .05 );
inventory[0] = new ProductList( "CEB32003", "Comb Bind", 50, 5.35, .05 );
inventory[0] = new ProductList( "CEB32004", "Glue Sticks", 24, 1.29, .05 );
//Sorted ProductList
Supplies supplies = new Supplies();
supplies.sortSupplies(inventory);
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
for(int j1=0; j1 < inventory.length; ++j1)
{
String labelText =
" Item Number: " + inventory[j1].getItemNumber() +
" Product Name: " + inventory[j1].getProductName() +
" Quantity: " + inventory[j1].getQuantity() +
" Unit Price: " + inventory[j1].getUnitPrice() +
" Restock Fee: " + inventory[j1].getRestockFee() +
" Total Value: " + inventory[j1].value();
JLabel textLabel = new JLabel(labelText, JLabel.LEFT);
container.add(textLabel);
}
String labelText =
"<html><br>Total value of all printers in stock: " + (supplies.getTotalValue(inventory));
JLabel TotalValue = new JLabel(labelText, JLabel.CENTER);
container.add(TotalValue);
}//end HPprinters constructor
class Supplies {
private String itemNumber;
private String itemName;
private int quantity;
private double unitPrice;
public Supplies() {
}
public Supplies( String itemNumber, String itemName, int quantity, double unitPrice ) {
itemNumber = itemNumber;
itemName = itemName;
quantity = quantity;
unitPrice = unitPrice;
} //end four-argument constructor
public void setItemNumber(String itemNumber) {
itemNumber = itemNumber;
} //end method
public String getItemNumber() {
return itemNumber;
} //end method
public void setItemName(String itemName) {
itemName = itemName;
} //end method
//return
public String getItemName() {
return itemName;
} //end method
public void setQuantity(int quantity) {
quantity = quantity;
} //end method
//return
public int quantity() {
return quantity;
} //end method
public void setUnitPrice(double unitprice) {
unitPrice = unitPrice;
} //end method
//return
public double unitprice() {
return unitPrice;
} //end method
//calculate inventory value
public double value() {
return unitPrice * quantity;
} //end method value
public double getTotalValue(Supplies [] inventory)
{
double total = 0.0;
for(int i = 0; i < inventory.length; i++)
{
total += inventory[i].value();
}
return total;
}
public Supplies[] sortSupplies(Supplies[] inventory)
{
Supplies temp[] = new Supplies[1];
int i, k;
for (i=1; i <inventory.length; i++)
{
for (k=0; k < inventory.length-i; k++)
{
if(inventory[k].getItemNumber().compareToIgnoreCase(inventory[k+1].getItemNumber())>0)
{
// exchange elements
temp [0] = inventory[k];
inventory[k] = inventory[k+1];
inventory[k+1] = temp[0];
}
}
}
return inventory;
}
}//end class Supplies
class ProductList extends Supplies {
double restockFee;
public ProductList(String itemNumber, String itemName, int quantity, double unitPrice, double restockFee )
{
super(itemNumber, itemName, quantity, unitPrice);
this.restockFee = restockFee;
}
public double Fee(){
return super.unitPrice() * restockFee;
}
public double value() {
return super.value() + (super.value() * restockFee);
}
}
public static void main(String args []) {
Product product = new Product();
//get Content Pane
product.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
product.setSize(1100,300);
product.setVisible(true);
}
}//end class Product