Join 132,095 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,266 people online right now. Registration is fast and FREE... Join Now!
I working on my InventoryPart6 final project and I need to get my other programs working correctly. here are the one I submitted for Part5 each of them had errors.
//main method begins execution of java application public static void main(final String args[])
{ int i;//variable for looping double total=0;//variable for total inventory final int dispProd=0;//variable for actionEvents
//Array Declartion finalProductAdd[] nwProduct = new ProductAdd[3];
//Instantiate objects for the array for(i=0;i<3;i++) {
nwProduct[0]= new ProductAdd("cd","275252j",100,20.60); nwProduct[1]= new ProductAdd("dvd","9945h",200,10.77); nwProduct[2]= new ProductAdd("tape","45454k",220,129.95); }
//Perform Calculations for(i=0;i<3;i++) total += nwProduct.length;//calculate total inventory cost
final JButton firstBtn = new JButton("First"); final JButton prevBtn = new JButton("previous"); final JButton nextBtn = new JButton("next"); final JButton lastBtn = new JButton("last"); final JLabel label;//logo final JTextArea textArea;//area for productlist final JPanel buttonJPanel;//panel holds buttons
//JLabel constructor for logo Icon logo = new ImageIcon("C:/logo.jpg");//load logo label = new JLabel(logo);//create label logo label.setToolTipText("Company Logo");//create tooltip
buttonJPanel = new MyJPanel();//set up panel buttonJPanel.setLayout(new GridLayout(1,4));//set layout //add buttons to buttonPanel buttonJPanel.add(firstBtn); buttonJPanel.add(prevBtn); buttonJPanel.add(nextBtn); buttonJPanel.add(lastBtn);
textArea = new JTextArea(nwProduct[3]+"\n");//create textArea for product display
//add total inventory value to GUI textArea.append("/nTotalvalue of Inventory "+new java.text.DecimalFormat("$0.00").format(total)+"\n\n"); textArea.setEditable(false); JFrame invFrame = new JFrame(); invFrame.setLayout(new BorderLayout()); invFrame.getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER);//add textArea to JFrame invFrame.getContentPane().add(buttonJPanel,BorderLayout.SOUTH);//add buttons to JFrame invFrame.getContentPane().add(label,BorderLayout.NORTH); invFrame.setTitle("CD,DVD & Tape inventory");//set JFrame title invFrame.setDefaultCloseOperations(JFrame.EXIT_ON_CLOSE);//termination command //invFrame.pack(); invFrame.setSize(600,600);//set size of JPanel invFrame.setLocationRelativeTo(null);//set screen location invFrame.setVisible(true);//display window
//assign actionListner and actionEvent for each button firstBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { textArea.setText(nwProduct[0]+"\n"); }//end firstBtn actionEvent
//main method begins execution of javaApplication public static void main(final String args[]) { // create a new GUI object that will display the inventory on the screen InventoryGUI theGUI = new InventoryGUI();
int i;//variable for looping double total=0;//variable for total inventory
//Array Declartion ProductAdd[] Inventory = new ProductAdd[3];
// Instantiate objects for the array for(i=0;i<3;++) {
nwProduct[0]= new ProductAdd("cd","275252j",100,20.60); nwProduct[1]= new ProductAdd("dvd","9945h",200,10.77); nwProduct[2]= new ProductAdd("tape","45454k",220,129.
//Perform Calculations for(i=0;i<3;i++) total += nwProduct.length;//calculate total inventory cost
//Total Inventory Value textArea.append("Total Inventory Value"+ new java.text.DecimalFormat("$0.00").format(dblTotalVal)+"\n\n"); textArea.setEditable(false);
class ProductAdd extends Product { private String feature;// variable for added feature
Public ProductAdd(productName,double itemNumber,double itemStock, double ItemPrice,String addFeat) { //call to superclass Product constructor super(name,number,stock,price);
feature = addFeat;
}//end constructor
public void setFeature)String addFeat)//method to add feature { feature = addFeat; } public double calcValueRstk()//method to set value and restock fee { return units * price * 0.10; } public String to String() {
return String.format("Product:%s\nItem Number:%.2f\nRestock Cost:$%.2f\n\n", getProductName(),getItemNumbers(),getitemStock(),getItemPrice(),getFeature(),cal c Value(),calc ValueRstk(); }
}//end class productAdd
class MyJPanel extends JPanel { //private static Random generator = new Random(); private ImageIcon picture;//image to be displayed
//load image public MyJPanel() { picture = new ImageIcon("mypicture.png");//set icon
}//end MyJPanel constructor
//display imageIcon on panel public void paintComponent(Graphics g) { super.paintComponent(g); picture.paintIcon(this, g, 0,0);//display icon
//Product inventory[] = new Product[3]; //public to ensure other components or classes can utilize this method. public void getNameVal()
{
System.out.println("\nPlease enter product name:");
ProductName = input.next();
//Loop terminator for the "stop" check is in the main loop. if(itemName.equalsIgnoreCase("stop")) { boolflag=true;
} }//End menthod
public void setProductName(String Name) { ProductName = Name; }
public String getName() { return ProductName; }
public void setItemNumber(double Number) { ItemNumber= Number; }
public void getItemNumber() { return ItemNumber; }
public void getItemStock() { return ItemStock; }
public void setItemStock(Double Stock) { return ItemStock = Stock; }
//get ItemPrice public double getItemPrice() { return ItemPrice; }
public void setPrice(Double Price); { ItemPrice = price; } //public to ensure other components or classes can utilize this method. public void getItemStockVal()
{
System.out.println("Please enter amount in stock:"); ItemStock= input.nextInt();
//Set hourly rate while(ItemStock <= 0) {
System.out.println("\nPlease enter a positive number.\n"); System.out.println("Number of items in stock");//prompt ItemStock = input.nextint();//read hourly rate
}//End while
}//End method
//public to ensure other components or classes can utilize this method. public void getItemPriceVal() {
System.out.println("Please enter item price:"); ItemPrice = input.nextDouble();
//set hourly rate while(ItemPrice <= 0) {
System.out.println("\nPlease enter a positive number.\n"); System.out.println("Enter price of item:");//prompt ItemPrice= input.nextDouble();//read hourly rate
}//End while
}//End Method
//public to ensure othe components or classes can utilize this method. public void getItemNumberVal() {
System.out.println("Please enter item number:"); ItemNumber = input.nextInt();
}//End method
//perform calculations public static double ValueOfInventory(double price,itemstock);
{ return price*stock;
}//End method
/*public Sting toString()
{ return new StringBuffer().append("Price:" + getItemPrice()00.toString();
}*/
}//End class Product
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>
I'm going to move this to the Java forum, where it belongs and can get the proper attention of our Java experts. For future reference, please put programming question in the appropriate language forum, this forum is for Introductions only
//Loop terminator for the "stop" check is in the main loop. if(itemName.equalsIgnoreCase("stop")) // you have an itemNumber that is a double but not any itemName { boolflag=true;
} }//End menthod
public void setProductName(String Name) { ProductName = Name; // productName with a small p }
public String getName() { return ProductName; // productName with a small p }
public void setItemNumber(double Number) { ItemNumber= Number; // itemNumber with a small i }
public void getItemNumber() { return ItemNumber; // itemNumber with a small i }
public void getItemStock() { return ItemStock; // itemstock without I or S }
public void setItemStock(Double Stock) { return ItemStock = Stock; // itemstock without I or S }
//get ItemPrice public double getItemPrice() { return ItemPrice; // itemPrice without a I }
public void setPrice(Double Price); { ItemPrice = price; } //public to ensure other components or classes can utilize this method. public void getItemStockVal()
{
System.out.println("Please enter amount in stock:"); ItemStock= input.nextInt();
//Set hourly rate while(ItemStock <= 0) {
System.out.println("\nPlease enter a positive number.\n"); System.out.println("Number of items in stock");//prompt ItemStock = input.nextint();//read hourly rate
}//End while
}//End method
//public to ensure other components or classes can utilize this method. public void getItemPriceVal() {
System.out.println("Please enter item price:"); ItemPrice = input.nextDouble();
//set hourly rate while(ItemPrice <= 0) {
System.out.println("\nPlease enter a positive number.\n"); System.out.println("Enter price of item:");//prompt ItemPrice= input.nextDouble();//read hourly rate
}//End while
}//End Method
//public to ensure othe components or classes can utilize this method. public void getItemNumberVal() {
System.out.println("Please enter item number:"); ItemNumber = input.nextInt();
}//End method
//perform calculations public static double ValueOfInventory(double price,itemstock);
{ return price*stock;
}//End method
/*public Sting toString()
{ return new StringBuffer().append("Price:" + getItemPrice()00.toString();
}*/
}//End class Product
How can you think making a ProductAdd class thhat extends Product if Product alone does not compile...
MyPanel is OK
CODE
//main method begins execution of javaApplication public static void main(final String args[]) { // create a new GUI object that will display the inventory on the screen InventoryGUI theGUI = new InventoryGUI();
The class InventoryGUI is not defined anywhere
CODE
// Instantiate objects for the array for(i=0;i<3;++) // it is not ++ but i++ { // nwProduct is not defined/declared anywhere nwProduct[0]= new ProductAdd("cd","275252j",100,20.60); nwProduct[1]= new ProductAdd("dvd","9945h",200,10.77); nwProduct[2]= new ProductAdd("tape","45454k",220,129. // missing closing ) and;