Results 1 to 6 of 6
  1. #1
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default [SOLVED] GUI Inventory Program

    Hello,

    I need help with my code... For some reason, it is saying that the class was a bad class. I am new to java and I am very confused. I'd appreciate any help..

    Here is my code...
    Java Code:
    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());
    
      		Product[] product = new Product[5];
    
      		product highlighter = new Product( "CEB32000", "Highlighter", 30, 5.75, .05 );
    		product manilaFolder = new Product( "CEB32001", "Manila Folder", 45, 3.25, .05 );
    		product scissors = new Product( "CEB32002", "Scissors", 36, 2.75, .05 );
    		product combbind = new Product( "CEB32003", "Comb Bind", 50, 5.35, .05 );
      		product gluesticks = new Product( "CEB32004", "Glue Sticks", 24, 1.29, .05 );
    
      		product[0] = highlighter;
      		product[1] = manilaFolder;
      		product[2] = scissors;
      		product[3] = combbind;
      		product[4] = gluesticks;
    
    
    
            //Sort 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();
    
    			JTextArea textArea = new JTextArea (80,70);
    			textArea.setText(" ");
    			textArea.setEditable(false);
    
    			JFrame frame = new JFrame();
    			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    			frame.pack();
    			frame.setLocationRelativeTo(null);
    			frame.setVisible(true);
    		}
    
    
      		String labelText =
      		"<html><br>Total value of Supply Inventory: " + (supplies.getTotalValue(inventory));
      		JLabel TotalValue = new JLabel(labelText, JLabel.CENTER);
      		container.add(TotalValue);
    
       }//end Product 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)
    		            {
    						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);
    		}
    
    	}
    
    }//end class Product

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Please post the error message and indicate some how which line(s) are causing the error to be thrown.

  3. #3
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default Error Message

    Hi Fubarable,

    Sorry, I just got home... I don't understand why it is saying that product class is a bad class. Thank you so much!

    But here is the error code:

    C:\Documents and Settings\McDonley\My Documents\InventoryProgramPart3\Product.java:25: cannot access product
    bad class file: .\product.class
    class file contains wrong class: Product
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    product highlighter = new Product( "CEB32000", "Highlighter", 30, 5.75, .05 );
    ^
    1 error

    Tool completed with exit code 1

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I'm wondering... is the product class named Product.java or product.java?

    Also, what package is it in?

  5. #5
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default Gui

    Hi Fubarable,

    I got it to compile but my problemnow is when I run it, It is not showing the inventory. Can you please help me?

    here is my code..

    Java Code:
    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[5];
    
      		inventory[0] = new ProductList( "CEB32000", "Highlighter", 30, 5.75, .05 );;
      		inventory[1] = new ProductList( "CEB32001", "Manila Folder", 45, 3.25, .05 );
      		inventory[2] = new ProductList( "CEB32002", "Scissors", 36, 2.75, .05 );
      		inventory[3] = new ProductList( "CEB32003", "Comb Bind", 50, 5.35, .05 );
      		inventory[4] = new ProductList( "CEB32004", "Glue Sticks", 24, 1.29, .05 );
    
      		JTextArea textArea = new JTextArea (40,30);
    		textArea.setText(" ");
    		textArea.setEditable(false);
    
    		for( int i = 0; i < inventory.length; i++)
    		{
    			textArea.append("Product" + i + ": \t" + inventory[i] + "\n");
    		}
    
    		JFrame frame = new JFrame();
    		frame.getContentPane().add(new JScrollPane(textArea));
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    
            //Sort 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].getItemName() +
    			" *** Quantity: " + inventory[j1].quantity() +
    			" *** Unit Price: $" + inventory[j1].unitPrice() +
    			" *** Restock Fee: $" + inventory[j1].restockFee() +
    			" *** Total Value: $" + inventory[j1].value();
    		}
    
    			String labelText =
    			 "<html><br>Total value of Supply Inventory: " + (supplies.getTotalValue(inventory));
    			  JLabel TotalValue = new JLabel(labelText, JLabel.CENTER);
    			  container.add(TotalValue);
    
    
       }//end Product 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++){
    
    				}
    			}
    		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 restockFee(){
    			return super.unitPrice() * restockFee;
    		}
    
    		public double value() {
    			return  super.value() + (super.value() * restockFee);
    		}
    
    	}
    
    
    	public static void main(String args[])
        {
        	Product product = new Product();
        }
    
    }//end class Product

  6. #6
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

Similar Threads

  1. Inventory Program Part 3 ~ please help!
    By marMcD in forum New To Java
    Replies: 13
    Last Post: 02-25-2009, 05:57 AM
  2. Help with Errors in Inventory Program
    By ljk8950 in forum AWT / Swing
    Replies: 3
    Last Post: 08-08-2008, 11:49 PM
  3. Inventory Program modification help
    By badness in forum Java Applets
    Replies: 1
    Last Post: 01-17-2008, 05:24 AM
  4. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 07:00 AM
  5. Inventory program
    By Nexcompac in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •