Inventory program part 5 help

This is what I need,
Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display.
Add a company logo to the GUI using Java graphics classes.
This is what I have so far,
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat; // used to format currency
import javax.swing.*;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
class InventoryMain implements ActionListener
    CD[] product;
    JTextField[] fields;
    NumberFormat nf;
    public void actionPerformed(ActionEvent e)
        int index = ((JComboBox)e.getSource()).getSelectedIndex();
        populateFields(index);
    public static void main(String[] args)
        try
            UIManager.setLookAndFeel(
                    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        catch (Exception e)
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        InventoryMain test = new InventoryMain();
        test.initCD();
        test.showGUI();
        test.populateFields(0);
    public void initCD() {
        //Create an array   
        product = new CD[10];
        //fill in the classes
        product[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722");
        product[1] = new CD( 2, "Pantera" , 20.00, 10, "00263");
        product[2] = new CD( 3, "Ozzy" , 15.00, 10, "00142");
        product[3] = new CD( 4, "Soulfly" , 18.00, 10, "00553");
        product[4] = new CD( 5, "Down", 24.00, 10, "00789");
        product[5] = new CD( 6, "God Forbid" , 10.00, 10, "00712");
        product[6] = new CD( 7, "Black Label Society" , 16.00, 10, "00458" );
        product[7] = new CD( 8, "Saint Vitus" , 15.00, 10, "00889");
        product[8] = new CD( 9, "Clearlight" , 15.00, 10, "00897");
        product[9] = new CD( 10, "Testament" , 15.00, 10, "00656");       
        //Sort elements in array in alphabetical order by product name
//        product[0].sortItems(product);
    final JButton firstBtn = new JButton("First"); // first button
final JButton prevBtn = new JButton("Previous"); // previous button
final JButton nextBtn = new JButton("Next"); // next button
final JButton lastBtn = new JButton("Last"); // last button
final JLabel label; // logo
final JTextArea textArea; // text area for product list
final JPanel buttonJPanel; // panel to hold buttons
//JLabel constructor for logo
Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
label = new JLabel(logo); // create logo label
label.setToolTipText("Company Logo"); // create tooltip
    private void showGUI() {
        JLabel l;
        JButton b;
        fields = new JTextField[9];
        JComboBox combo = new JComboBox();
        for(int j = 0; j < product.length; j++)
            combo.addItem(product[j].getName());
        combo.addActionListener(this);
        JFrame f = new JFrame("InventoryGUI");
        Container cp = f.getContentPane();
        cp.setLayout(new GridBagLayout());
        cp.setBackground(UIManager.getColor("control"));
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = 0;
        c.gridy = GridBagConstraints.RELATIVE;
        c.gridwidth = 1;
        c.gridheight = 1;
        c.insets = new Insets(2, 2, 2, 2);
        c.anchor = GridBagConstraints.EAST;
        cp.add(l = new JLabel("Item Number:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('a');
        cp.add(l = new JLabel("Item Name:", SwingConstants.CENTER), c);    l.setDisplayedMnemonic('b');
        cp.add(l = new JLabel("Number of Units in Stock:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('c');
        cp.add(l = new JLabel("Price per Unit: $", SwingConstants.CENTER), c);       l.setDisplayedMnemonic('d');
        cp.add(l = new JLabel("Total cost of This Item: $", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('e');
        cp.add(l = new JLabel("Total Value of All Merchandise in Inventory: $",
                               SwingConstants.CENTER), c);   l.setDisplayedMnemonic('f');
        cp.add(l = new JLabel("Item Code:", SwingConstants.CENTER), c);   l.setDisplayedMnemonic('g');
        cp.add(l = new JLabel("Product Restocking Fee: $", SwingConstants.CENTER), c);  l.setDisplayedMnemonic('h');
        cp.add(combo, c);
        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 1.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.CENTER;
        cp.add(fields[0] = new JTextField(), c);
        fields[0].setFocusAccelerator('a');
        c.gridx = 1;
        c.gridy = GridBagConstraints.RELATIVE;
        cp.add(fields[1] = new JTextField(), c);         fields[1].setFocusAccelerator('b');
        cp.add(fields[2] = new JTextField(), c);         fields[2].setFocusAccelerator('c');
        cp.add(fields[3] = new JTextField(), c);         fields[3].setFocusAccelerator('d');
        cp.add(fields[4] = new JTextField(), c);         fields[4].setFocusAccelerator('e');
        cp.add(fields[5] = new JTextField(), c);         fields[5].setFocusAccelerator('f');
        cp.add(fields[6] = new JTextField(), c);         fields[6].setFocusAccelerator('g');
        cp.add(fields[7] = new JTextField(), c);         fields[7].setFocusAccelerator('h');
        cp.add(fields[8] = new JTextField(), c);         fields[8].setFocusAccelerator('i');
        c.weightx = 0.0;
        c.fill = GridBagConstraints.NONE;
        cp.add(b = new JButton("OK"), c);
        cp.add(b = new JButton("First"),c); // set up panel
        cp.add(b = new JButton("Prev"),c);
        cp.add(b = new JButton("Next"),c);
        cp.add(b = new JButton("Last"),c);
        b.setMnemonic('o');
        f.pack();
        f.addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent evt)
                System.exit(0);
        f.setVisible(true);
    private void populateFields(int index) {
        CD cd = product[index];
        fields[0].setText(Long.toString(cd.getNumberCode()));
        fields[1].setText(cd.getName());
        fields[2].setText(Long.toString(cd.getUnits()));
        fields[3].setText(Double.toString(cd.getPrice()));
        fields[4].setText(Double.toString(cd.getSum()));
        fields[5].setText(Double.toString(cd.totalAllInventory(product)));
        fields[6].setText(cd.getCode());
        fields[7].setText(Double.toString(cd.getSum()*.05));       
class CD {
    int itemNumber;
    String name;
    int units;
    double price;
    String itemCode;
    public CD(int n, String name, double price, int units, String itemCo) {
        itemNumber = n;
        this.name = name;
        this.price = price;
        this.units = units;
        itemCode = itemCo;
    public int getNumberCode() { return itemNumber; }
    public String getName() { return name; }
    public int getUnits() { return units; }
    public double getPrice() { return price; }
    public double getSum() { return units*price; }
    public String getCode() { return itemCode; }
    public double totalAllInventory(CD[] cds) {
        double total = 0;
        for(int j = 0; j < cds.length; j++)
            total += cds[j].getSum();
        return total;
public class InventoryI {
     String productnumber;
     String name;
     int numberofunits;
     double priceperunit;
        String itemcode;
     // Create a new instance of Inventory
     // main constructor for the class
     public InventoryI(String Item_Number, String Item_Name, int Items_in_Stock,
               double Item_Price, String Item_Code) {
          productnumber = Item_Number;
          name = Item_Name;
          numberofunits = Items_in_Stock;
          priceperunit = Item_Price;
                itemcode = Item_Code;
     public void setItemName(String Item_Name) {
     // sets the items name
          name = Item_Name;
     public void setItemCode(String Item_Code) {
     // sets the items name
          itemcode = Item_Code;
        public void setItemNumber(String Item_Number) { // Sets the Product =Number
     // for the item
          productnumber = Item_Number;
     public void setItemsInStock(int Items_in_Stock) { // sets the =number of
     // units in stock
          numberofunits = Items_in_Stock;
     public void setItemPrice(double Item_Price) { // sets the price of =the
     // item
          priceperunit = Item_Price;
        public String getItemName() { // returns the Product Name of this item
          return name;
      public String getItemCode() { // returns the Product Name of this item
          return itemcode;
        public String getItemNumber() { // returns the Product Number of the =item
          return productnumber;
     public int getItemsInStock() { // returns how many units are in stock
          return numberofunits;
     public double getItemPrice() { // returns the price of the item
          return priceperunit;
     public double getInventoryIValue() { // returns the total value of =the stock
     // for this item
          return priceperunit * numberofunits;
     public static double getTotalValueOfAllInventory(InventoryI [] inv) {
             double tot = 0.0;
          for(int i = 0; i < inv.length; i++)  
               tot += inv.getInventoryIValue();
          return tot;
     public static InventoryI[] sort(InventoryI [] inventory)
          InventoryI temp[] = new InventoryI[1];
          //sorting the array using Bubble Sort
          for(int j = 0; j < inventory.length - 1; j++)
          for(int k = 0; k < inventory.length - 1; k++)
          if(inventory[k].getItemName().compareToIgnoreCase(inventory[k+1].getItemName()) > 0)
          temp[0] = inventory[k];
          inventory[k] = inventory[k+1];
          inventory[k+1] = temp[0];
          }//end if
          }//end for loop
          }//end for loop
          return inventory;
     public String toString()
          StringBuffer sb = new StringBuffer();
          sb.append("CD Title: \t").append(name).append("\n");
sb.append("Item Code: \t").append(itemcode).append("\n");
          sb.append("Item #:      \t").append(productnumber).append("\n");
          sb.append("Number in stock:\t").append(numberofunits).append("\n");
          sb.append("Price: \t").append(String.format("$%.2f%n", priceperunit));
          sb.append("Inventory Value:\t").append(String.format("$%.2f%n", this.getInventoryIValue()));
          return sb.toString();
Thank you in advance for any help.

    public String toString() {
        return(
             "CD Title        :\t"+name+"\n"
            +"Item Code       :\t"+itemcode+"\n"
            +"Item #          :\t"+productnumber+"\n"
            +"Number in stock :\t"+numberofunits+"\n"
            +"Price           :\t"+String.format("$%.2f%n", priceperunit)
            +"Inventory Value :\t"+String.format("$%.2f%n", this.getInventoryIValue()
    }There's some help. Have fun appreciating it.
Well... you did ask the silliest question of all. "Please fix my homework." And you forgot the please.
keith.

Similar Messages

  • Inventory Program Part 3

    Hi. I'd like to thank all who replied to my Inventory 2 program. Today I am working on Inventory Program Part 3 and need a little help with this also.
    Assignment Description:
    CheckPoint: Inventory Program Part 3
    ?h Resource: Java: How to Program
    ?h Due Date: Day 7 [Individual] forum
    ?h Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.
    ?h Modify the output to display this additional feature you have chosen and the restocking fee.
    ?h Post as an attachment in java format.
    I think that I have most of the code correct, however I still have errors withing my code that I have changed around multiple times and still can't figure out how to correct the errors.
    Here is my code for Inventory Program Part 3:
    package inventoryprogram3;
    import java.util.Scanner;
    import java.util.ArrayList;
    public class InventoryProgram3
         * @param args the command line arguments
        public static void main(String[] args)
            Scanner input = new Scanner (System.in);
            DVD[] dvd = new DVD[10];
            dvd[0] = new DVD("We Were Soilders","5","19.99","278");
            dvd[1] = new DVD("Why Did I Get Married","3","15.99","142");
            dvd[2] = new DVD("I Am Legend","9","19.99","456");
            dvd[3] = new DVD("Transformers","4","19.99","336");
            dvd[4] = new DVD("No Country For Old Men","4","16.99","198");
            dvd[5] = new DVD("The Kingdom","6","15.99","243");
            dvd[6] = new DVD("Eagle Eye","2","16.99","681");
            dvd[7] = new DVD("The Day After Tomorrow","4","19.99","713");
            dvd[8] = new DVD("Dead Presidents","3","19.99","493");
            dvd[9] = new DVD("Blood Diamond","7","19.99","356");
            double dvdValue = 0.0;
                for (int counter = 0; > DVD.length ;counter++);
            System.out.printf("\nInventory value is: $%,2f\n",dvdValue);
    class DVD
        protected String dvdTitle;
        protected double dvdPrice;
        protected double dvdStock;
        protected double dvditemNumber;
         public DVD(String title, double price, double stock, double itemNumber)
            this.dvdTitle = title;
            this.dvdPrice = price;
            this.dvdStock = stock;
            this.dvditemNumber = itemNumber;
        DVD(String string, String string0, String string1, String string2) {
            throw new UnsupportedOperationException("Not yet implemented");
         public void setDVDTitle(String title)
            this.dvdTitle = title;
        public String getDVDTitle()
            return dvdTitle;
        public void setDVDPrice(double price)
            this.dvdPrice = price;
        public double getDVDPrice()
            return dvdPrice;
        public void setDVDStock(double stock)
            this.dvdStock = stock;
        public double getDVDStock()
            return dvdStock;
        public void setDVDitemNumber(double itemNumber)
            this.dvditemNumber = itemNumber;
        public double getDVDitemNumber()
            return dvditemNumber;
        public double getValue()
            return this.dvdStock * this.dvdPrice;
        System.out.println();
        *_System.out.println( "DVD Title:" + dvd.getDVDTitle());_*
        *_System.out.println("DVD Price:" + dvd.getDVDPrice());_*
        *_System.out.println("DVD units in stock:" + dvd.getDVDStock());_*    _System.out.println("DVD item number: " + dvd.getDVDitemNumber());_    System.out.printf("The total value of dvd inventory is: $%,.2f\n" ,_*dvdValue*_);
    class MovieGenre extends InventoryProgram3
        private String movieGenre;
        _*public movieGenre(String title, double price, double stock, double itemNumber, String movieGenre)_*
            *_super(dvdTitle, dvdPrice, dvdStock, dvditemNumber, dvdmovieTitle);_*
            *_movieGenre = genre;_    }*
        public void setmovieTitle(String title)
            this.movieGenre = _*genre*_;
        public String getmovieGenre()
            return _*moviegenre*_;
        public double getValue()
            return getValue() * 1.05;
        public double gerestockingFee()
            return getValue() * .05;
        public String toString(Object[] dvdValue)
            return String.format("%s %s\nTotal value of inventory is: %s", dvdValue);
    }I ran the program just to see the error messages:
    Exception in thread "main" java.lang.NoClassDefFoundError: inventoryprogram3/DVD (wrong name: inventoryprogram3/dvd)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    at inventoryprogram3.InventoryProgram3.main(InventoryProgram3.java:20)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    I really don't understand what's going on here and would appreciate help from anyone who knows and understands Java.
    Thanks in advance.

    You say you "ran" it. I think you mean compiled it? The public class is InventoryProgram3, not DVD.
    If you did mean you tried to run it, then additionally, instead ofjava inventoryprogram3/InventoryProgram3
    Should be
    java inventoryprogram3.InventoryProgram3

  • Need help with Inventory program part 6

    if any one can help or give me a clue to how to do this Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item.
    ? Add a Save button to the GUI that saves the inventory to a C:\data\inventory.dat file.
    ? Use exception handling to create the directory and file if necessary.
    ? Add a search button to the GUI that allows the user to search for an item in the inventory by the product name. If the product is not found, the GUI should display an appropriate message. If the product is found, the GUI should display that product?s information in the GUI.
    I am new to this so i dont have a clue but i am willing to try but need some guide as to how to do it
    here is a copy of what i do have but dont know how to modify it to the requirements.
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class Inventory2
    static int dispProd = 0; // variable for actionEvents
    //main method begins execution of java application
    public static void main(final String args[])
    int i; // varialbe for looping
    double total = 0; // variable for total inventory
    // Instantiate a product object
    final ProductAdd[] nwProduct = new ProductAdd[5];
    // Instantiate objects for the array
    for (i=0; i<5; i++)
    nwProduct[0] = new ProductAdd("Paper", 101, 10, 1.00, "Box");
    nwProduct[1] = new ProductAdd("Pen", 102, 10, 0.75, "Pack");
    nwProduct[2] = new ProductAdd("Pencil", 103, 10, 0.50, "Pack");
    nwProduct[3] = new ProductAdd("Staples", 104, 10, 1.00, "Box");
    nwProduct[4] = new ProductAdd("Clip Board", 105, 10, 3.00, "Two Pack");
    for (i=0; i<5; i++)
    total += nwProduct.length; // calculate total inventory cost
    final JButton firstBtn = new JButton("First"); // first button
    final JButton prevBtn = new JButton("Previous"); // previous button
    final JButton nextBtn = new JButton("Next"); // next button
    final JButton lastBtn = new JButton("Last"); // last button
    final JLabel label; // logo
    final JTextArea textArea; // text area for product list
    final JPanel buttonJPanel; // panel to hold buttons
    //JLabel constructor for logo
    Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
    label = new JLabel(logo); // create logo label
    label.setToolTipText("Company Logo"); // create tooltip
    buttonJPanel = new JPanel(); // 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("\nTotal value of Inventory "+new java.text.DecimalFormat("$0.00").format(total)+"\n\n");
    textArea.setEditable(false); // make text uneditable in main display
    JFrame invFrame = new JFrame(); // create JFrame container
    invFrame.setLayout(new BorderLayout()); // set layout
    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); // add logo to JFrame
    invFrame.setTitle("Office Min Inventory"); // set JFrame title
    invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // termination command
    //invFrame.pack();
    invFrame.setSize(400, 400); // set size of JPanel
    invFrame.setLocationRelativeTo(null); // set screem location
    invFrame.setVisible(true); // display window
    // assign actionListener and actionEvent for each button
    firstBtn.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    dispProd = 0;
    textArea.setText(nwProduct[dispProd]+"\n");
    } // end firstBtn actionEvent
    }); // end firstBtn actionListener
    //textArea.setText(nwProduct[4]+"n");
    prevBtn.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    dispProd--;
    if (dispProd < 0)
    dispProd = 0;
    //dispProd = (nwProduct.length+dispProd-1) % nwProduct.length;
    textArea.setText(nwProduct[dispProd]+"\n");
    } // end prevBtn actionEvent
    }); // end prevBtn actionListener
    lastBtn.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    dispProd = nwProduct.length-1;
    textArea.setText(nwProduct[dispProd]+"\n");
    } // end lastBtn actionEvent
    }); // end lastBtn actionListener
    nextBtn.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    dispProd++;
    if (dispProd >= nwProduct.length)
    dispProd = nwProduct.length-1;
    textArea.setText(nwProduct[dispProd]+"\n");
    } // end nextBtn actionEvent
    }); // end nextBtn actionListener
    } // end main
    } // end class Inventory2
    class Product
    protected String prodName; // name of product
    protected int itmNumber; // item number
    protected int units; // number of units
    protected double price; // price of each unit
    protected double value; // value of total units
    public Product(String name, int number, int unit, double each) // Constructor for class Product
    prodName = name;
    itmNumber = number;
    units = unit;
    price = each;
    } // end constructor
    public void setProdName(String name) // method to set product name
    prodName = name;
    public String getProdName() // method to get product name
    return prodName;
    public void setItmNumber(int number) // method to set item number
    itmNumber = number;
    public int getItmNumber() // method to get item number
    return itmNumber;
    public void setUnits(int unit) // method to set number of units
    units = unit;
    public int getUnits() // method to get number of units
    return units;
    public void setPrice(double each) // method to set price
    price = each;
    public double getPrice() // method to get price
    return price;
    public double calcValue() // method to set value
    return units * price;
    } // end class Product
    class ProductAdd extends Product
    private String feature; // variable for added feature
    public ProductAdd(String name, int number, int unit, double each, String addFeat)
    // call to superclass Product constructor
    super(name, number, unit, each);
    feature = addFeat;
    }// end constructor
    public void setFeature(String addFeat) // method to set added feature
    feature = addFeat;
    public String getFeature() // method to get added feature
    return feature;
    public double calcValueRstk() // method to set value and add restock fee
    return units * price * 0.05;
    public String toString()
    return String.format("Product: %s\nItem Number: %d\nIn Stock: %d\nPrice: $%.2f\nType: %s\nTotal Value of Stock: $%.2f\nRestock Cost: $%.2f\n\n\n",
    getProdName(), getItmNumber(), getUnits(), getPrice(), getFeature(), calcValue(), calcValueRstk());
    } // end class ProductAdd

    Try these modifications at your own risk:
    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class Inventory2
        static int dispProd = 0; // variable for actionEvents
        // main method begins execution of java application
        static JTextArea textArea;
        public static void main(final String args[])
            int i; // varialbe for looping
            double total = 0; // variable for total inventory
            // Instantiate a product object
            final ProductAdd[] nwProduct = new ProductAdd[5];
            // Instantiate objects for the array
            for (i = 0; i < 5; i++)
                nwProduct[0] = new ProductAdd("Paper", 101, 10, 1.00, "Box");
                nwProduct[1] = new ProductAdd("Pen", 102, 10, 0.75, "Pack");
                nwProduct[2] = new ProductAdd("Pencil", 103, 10, 0.50, "Pack");
                nwProduct[3] = new ProductAdd("Staples", 104, 10, 1.00, "Box");
                nwProduct[4] = new ProductAdd("Clip Board", 105, 10, 3.00,
                        "Two Pack");
            for (i = 0; i < 5; i++)
                total += nwProduct.length; // calculate total inventory cost
            final JButton firstBtn = new JButton("First"); // first button
            final JButton prevBtn = new JButton("Previous"); // previous button
            final JButton nextBtn = new JButton("Next"); // next button
            final JButton lastBtn = new JButton("Last"); // last button
            final JButton addBtn = new JButton("Add");
            final JButton deleteBtn = new JButton("Delete");
            final JButton modifyBtn = new JButton("Modify");
            final JLabel label; // logo
            //final JTextArea textArea; // text area for product list
            final JPanel buttonJPanel; // panel to hold buttons
            // JLabel constructor for logo
            Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
            label = new JLabel(logo); // create logo label
            label.setToolTipText("Company Logo"); // create tooltip
            buttonJPanel = new JPanel(); // set up panel
            buttonJPanel.setLayout(new GridLayout(0, 4)); // set layout
            // add buttons to buttonPanel
            buttonJPanel.add(firstBtn);
            buttonJPanel.add(prevBtn);
            buttonJPanel.add(nextBtn);
            buttonJPanel.add(lastBtn);
            buttonJPanel.add(addBtn);
            buttonJPanel.add(deleteBtn);
            buttonJPanel.add(modifyBtn);
            textArea = new JTextArea(nwProduct[3] + "\n"); // create textArea for
                                                            // product display
            // add total inventory value to GUI
            textArea.append("\nTotal value of Inventory "
                    + new java.text.DecimalFormat("$0.00").format(total) + "\n\n");
            textArea.setEditable(false); // make text uneditable in main display
            JFrame invFrame = new JFrame(); // create JFrame container
            invFrame.setLayout(new BorderLayout()); // set layout
            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); // add logo
                                                                        // to JFrame
            invFrame.setTitle("Office Min Inventory"); // set JFrame title
            invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // termination
                                                                        // command
            // invFrame.pack();
            invFrame.setSize(400, 400); // set size of JPanel
            invFrame.setLocationRelativeTo(null); // set screem location
            invFrame.setVisible(true); // display window
            // assign actionListener and actionEvent for each button
            firstBtn.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    dispProd = 0;
                    textArea.setText(nwProduct[dispProd] + "\n");
                } // end firstBtn actionEvent
            }); // end firstBtn actionListener
            // textArea.setText(nwProduct[4]+"n");
            prevBtn.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    dispProd--;
                    if (dispProd < 0)
                        dispProd = 0;
                    // dispProd = (nwProduct.length+dispProd-1) % nwProduct.length;
                    textArea.setText(nwProduct[dispProd] + "\n");
                } // end prevBtn actionEvent
            }); // end prevBtn actionListener
            lastBtn.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    dispProd = nwProduct.length - 1;
                    textArea.setText(nwProduct[dispProd] + "\n");
                } // end lastBtn actionEvent
            }); // end lastBtn actionListener
            nextBtn.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    dispProd++;
                    if (dispProd >= nwProduct.length)
                        dispProd = nwProduct.length - 1;
                    textArea.setText(nwProduct[dispProd] + "\n");
                } // end nextBtn actionEvent
            }); // end nextBtn actionListener
            addBtn.addActionListener(new extraBtnAxnL());
            deleteBtn.addActionListener(new extraBtnAxnL());
            modifyBtn.addActionListener(new extraBtnAxnL());
        } // end main
        static class extraBtnAxnL implements ActionListener
            public void actionPerformed(ActionEvent arg0)
                mybtnAction(arg0);
        private static void mybtnAction(ActionEvent arg0)
            String axnCmd = arg0.getActionCommand();
            Font oldFont = textArea.getFont();
            textArea.setFont(new Font(oldFont.getName(), Font.BOLD, 16));
            if (axnCmd.equalsIgnoreCase("add"))
                textArea.setText(new String(asqasp));
            else if (axnCmd.equalsIgnoreCase("delete"))
                textArea.setText(new String(iow));
            else if (axnCmd.equalsIgnoreCase("modify"))
                textArea.setText(new String(dyogdhw));
        private static byte[] asqasp =
                0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x6f, 0x72, 0x75, 0x6d, 0x20,
                0x69, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20,
                0x74, 0x6f, 0x20, 0x61, 0x73, 0x6b, 0x20, 0x73, 0x70, 0x65, 0x63,
                0x69, 0x66, 0x69, 0x63, 0x20, 0x0a, 0x71, 0x75, 0x65, 0x73, 0x74,
                0x69, 0x6f, 0x6e, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20,
                0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x20, 0x70, 0x72,
                0x6f, 0x62, 0x6c, 0x65, 0x6d, 0x73, 0x2e, 0x0a, 0x0a, 0x4e, 0x6f,
                0x74, 0x20, 0x61, 0x20, 0x73, 0x69, 0x74, 0x65, 0x20, 0x74, 0x6f,
                0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x6a,
                0x65, 0x63, 0x74, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65,
                0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x0a, 0x61, 0x6e, 0x64, 0x20,
                0x61, 0x73, 0x6b, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x67, 0x65, 0x6e,
                0x65, 0x72, 0x61, 0x6c, 0x20, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x69,
                0x6f, 0x6e, 0x73, 0x2e
        private static byte[] iow =
                0x49, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x77, 0x6f,
                0x72, 0x64, 0x73, 0x2e, 0x2e, 0x2e
        private static byte[] dyogdhw =
                0x44, 0x6f, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e,
                0x20, 0x67, 0x6f, 0x64, 0x2d, 0x64, 0x61, 0x6d, 0x6e, 0x20, 0x68,
                0x6f, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x21
    } // end class Inventory2Message was edited by:
    petes1234

  • Inventory Program Part 1

    I am so lost with Part 1 of the Inventory Program for my Java class. I am receiving an error and cannot figure out where it is comming from. The assignment is to:
    Choose a product that lends itself to an inventory (for example, products at your
    workplace, office supplies, music CDs, DVD movies, or software).
    � Create a product class that holds the item number, the name of the product, the number
    of units in stock, and the price of each unit.
    � Create a Java application that displays the product number, the name of the product, the
    number of units in stock, the price of each unit, and the value of the inventory (the
    number of units in stock multiplied by the price of each unit). Pay attention to the good
    programming practices in the text to ensure your source code is readable and well
    documented.
    Here is the code I have so far:
    import java.util.Scanner; // program uses class Scanner
    public class Inventory
         private static void Quit()
    System.out.println("Goodbye");
         System.exit (0);
    // main method begins execution of Java application
    public static Void main (String args [] )
         // create Scanner to obtain input from command window
    Scanner input = new Scanner(System.in);
         Product Prod = new Product();
         System.out.printf (Prod.toString () );
         System.out.print("\nEnter Prod Name (stop to quit): "); // prompt for name
    Prod.setName(input.nextLine()); // get name
         if(Prod.getName().compareToIgnoreCase("stop") == 0)
    System.out.println("Stop entered, Thank you");
    Quit();
    } //end if
    System.out.print("Enter Prod number for " + Prod.getName() + ": "); // prompt
    Prod.setitemNum(input.nextLine()); // read Prod number from user
    System.out.print("Enter Units on hand: "); // prompt
    Prod.setunits(input.nextDouble()); // read second number from user
         if(Prod.getunits() <= 0)
              System.out.println ("Invalid amount, Units on hand worked must be positive");
              System.out.print("Please enter actual units on hand: ");
              Prod.setunits(input.nextDouble());
         } //end if
         System.out.print("Enter Unit Price: $ "); // prompt
    Prod.setprice(input.nextDouble()); // read third number from user
         if(Prod.getprice() <= 0)
              System.out.println ("Invalid amount, Unit Price must be positive");
              System.out.print("Please enter actual unit price: $ ");
              Prod.setprice(input.nextDouble());
         } //end if
         String fmtStr = "\n%-7s %-10s %12s %12s %12s\n";
         System.out.printf(fmtStr, "Prod #", "Prod Name",
    "Units On Hand", "Unit Cost", "Total Cost");
    for(int i = 0; i<5; i++);
    string Product[] prodArray = new string[5]; *******************
         //Prod[] myArray = new Prod[5]; // allocates memory for 5 strings
    prodArray[0] = "Book"; // initialize first element
    prodArray[1] = "Mag"; // initialize second element
    prodArray[2] = "Hat"; // etc.
    prodArray[3] = "Scarf";
    prodArray[4] = "Rain Gauge";
    System.out.println("Element at index 0: " + prodArray[0]);
    System.out.println("Element at index 1: " + prodArray[1]);
    System.out.println("Element at index 2: " + prodArray[2]);
    System.out.println("Element at index 3: " + prodArray[3]);
    System.out.println("Element at index 4: " + prodArray[4]);
         }//end for
    }//end while
    } //end main
    }// end class Inventory
    // Class Product holds Product information
    class Product
    private String name;
    private String itemNum;
    private double units;
    private double price;
    //default constructor
    public Product()
    name = "";
    itemNum = "";
    units = 0;
         price = 0;
    }//end default constructor
    //Parameterized Constructor
    public Product(String name, String itemNum, double units, double price)
    this.name = name;
    this.itemNum = itemNum;
    this.units = units;
         this.price = price;
    }//end constructor
         public void setName(String name) {
    this.name = name;
         String getName()
              return name;
    public void setitemNum ( String itemNum )
    this.itemNum = itemNum;
    public String getitemNum()
         return itemNum;      }
    public void setunits ( double units )
    this.units = units;
    public double getunits()
              return units;
    public void setprice ( double price )
    this.price = price;
    public double getprice()
         return price;
    public double getvalue()
         return (units * price);
    }//end Class Product
    I am receiving an error on Line 61 ( I have place a few asterisks beside it). The error says inventory.java:61: ';' expected string Product[] prodArray = new string[5]
    Does anyone have an idea what I am doing wrong.

    I reformatted the code and put it inside code tags to retain formatting, anywhere there is a comment, take a pause and compare it to your original to see the differences. Any questions don't hesitate to post them.
    import java.util.Scanner;
    public class Inventory implements Runnable{
        private Product[] prodArray = new Product[5];
        public Inventory() {
            int arraySize = 5;
            prodArray = new Product[arraySize];
            //the for loop did not make sense, since you were loading each object with different information.
            //This is an array of Product Objects
            //anything between two double quotes is a String literal
            //essentially an Object of type String
            //Use your setter methods in the Product class to set the properties of each "new" Product Object.
            //Or use the Parameterized version of your constructor to set the variables inside each "new" object
            //everytime you use the "new" keyword you get a brand spanking new object
            prodArray[0] = new Product();//"Book"; // initialize first element
            //Since you use an empty constructor none of the variable in your Product object have the values you want.
            //Set them after you create your object and assign it to the array.
            prodArray[0].setName("Book");
            //prodArray[0].setprice(0.00);
            //etc...
            prodArray[1] = new Product();//"Mag"; // initialize second element
            prodArray[1].setName("Mag");
            prodArray[2] = new Product();//"Hat"; // etc.
            prodArray[2].setName("Hat");
            prodArray[3] = new Product();//"Scarf";
            prodArray[3].setName("Scarf");
            prodArray[4] = new Product();//"Rain Gauge";
            prodArray[4].setName("Rain Gauge");
            //You never override the toString() method of Product to your output will be the String representation of the
            //Object's reference.
            //I have overidden the toString() method of Product for you using your format, look at it closely.
            System.out.println("Element at index 0: " + prodArray[0]);
            System.out.println("Element at index 1: " + prodArray[1]);
            System.out.println("Element at index 2: " + prodArray[2]);
            System.out.println("Element at index 3: " + prodArray[3]);
            System.out.println("Element at index 4: " + prodArray[4]);
        public void run() {
            showHeader();
            //You never set the name of the Product here and toString doesn't return anything you want to see.
            Scanner input = new Scanner(System.in);
            Product prod = new Product();
            //This show nothing we want to see, try overriding the toString() method in the Product class if you
            //want to see a specific variable of the Product class displayed with the toString() method.
    //        System.out.printf (prod.toString () );
            String inputString;
            int inputInt;
            double inputDouble;
            while( true ) {
                //Don't set invalid data into your Product Object, check to see if it meets your criteria first and then
                //set it.
                System.out.print("\nEnter prod Name (stop to quit): "); // prompt for name
                inputString = input.nextLine();
                if( inputString.compareToIgnoreCase("stop") == 0 ) {
                    System.out.println("Stop entered, Thank you");
                    quit();
                } else {
                    prod.setName(input.nextLine()); // get name
                System.out.print("Enter prod number for " + prod.getName() + ": "); // prompt
                prod.setitemNum(input.nextLine()); // read prod number from user
                System.out.print("Enter Units on hand: "); // prompt
                inputInt = input.nextInt(); // read second number from user
                //to do this check, put your input into a loop, not an if statement.
                //and get an integer from the Scanner not a double,  doubles are not precise and cannot be checked
                //consistently with a loop or if condition
                while ( inputInt <= 0) {
                    System.out.println ("Invalid amount, Units on hand worked must be positive");
                    System.out.print("Please enter actual units on hand: ");
                    inputInt = input.nextInt();
                prod.setunits( inputInt );
                //There are better ways to store currency such as an integer, but there are a lot of conversion you need to do
                // to display them, so just use double for now.
                System.out.print("Enter Unit Price: $ "); // prompt
                inputDouble = input.nextDouble(); // read third number from user
                //while loop here as well and you don't want your products to be $0.00 do you?
                while ( inputDouble < 0.01) {
                    System.out.println ("Invalid amount, Unit Price must be positive");
                    System.out.print("Please enter actual unit price: $ ");
                    prod.setprice(input.nextDouble());
                } //end if
                prod.setprice( inputDouble );
                System.out.println( prod.toString() );
                //You never store the input from the user consider implementing an ArrayList
        private void showHeader() {
            String fmtStr = "\n%-7s%-10s%12s%12s%12s\n";
            System.out.printf(fmtStr, "prod #", "prod Name", "Units On Hand", "Unit Cost", "Total Cost");
        private void quit() {
            System.out.println("Goodbye");
            System.exit (0);
        //Void is not the same as the reseerved word "void"
        //Be sure you watch your capitalizations, all Java reserved words (void, public, static, etc.) are lowercase
        public static void main (String args [] ) {
            //Create an object of type inventory
            Inventory i = new Inventory();
            //start the run method of that object;
            i.run();
    * Class Product holds Product information
    class Product {
        private String name;
        private String itemNum;
        private int units;
        private double price;
         * Constructor
        public Product() {
            //To save space and your sanity you could initialize these variables when they're declared like this.
            // private String name = "";
            name = "";
            //private String item = ""; etc.
            itemNum = "";
            units = 0;
            price = 0;
         * Constructor
         * @param name
         * @param itemNum
         * @param units
         * @param price
        public Product(String name, String itemNum, int units, double price) {
            this.name = name;
            this.itemNum = itemNum;
            this.units = units;
            this.price = price;
        public void setName(String name) {
            this.name = name;
        //This method because it does not have the public keyword is now Package private,
        // it cannot be used outside the current Package.
        String getName() {
            return name;
        public void setitemNum( String itemNum ) {
            this.itemNum = itemNum;
        public String getitemNum(){
            return itemNum;
        //Try to be consistent with your variable and method names, they should start with lower case and each subsequent
        //word should be capitalized like this
        //public void setUnits( double units ) {
        public void setunits( int units ) {
            this.units = units;
        public double getunits() {
            return units;
        public void setprice ( double price ) {
            this.price = price;
        public double getprice() {
            return price;
        public double getvalue() {
            return (units * price);
        public String toString() {
            String fmtStr = "%-7s%-10s%12d%12.2f%12.2f";
            return String.format(fmtStr, itemNum, name, units, price, getvalue() );
    }

  • Inventory Program Part 6 - Please Help

    My last assignment is due in about two hours and I am completely lost. I have been trying to figure out how to add functionality to my JButtons all week.
    I have added the following buttons but they do not work: save, delete, modify, save, search, add.
    I also need to add a company logo. I hope someone can please help me understand.
    Here is my current code:
    public class DVD {
         protected int itemNum;     // item number
         protected String name;     // item name
         protected int unit;          // number of units of the item
         protected double price;     // price of each unit
         public DVD() {}          // Default constructor
         public DVD(int itemNum, String name, int unit, double price) {
              // Constructor with input
              this.itemNum = itemNum;
              this.name = name;
              this.unit = unit;
              this.price = price;
         // Getter and Setter methods
         public void setItemNum(int itemNum) {
              this.itemNum = itemNum;
         public int getItemNum() {
              return itemNum;
         public void setName(String name) {
              this.name = name;
         public String getName() {
              return name;
         public void setUnit(int unit) {
              this.unit = unit;
         public int getUnit() {
              return unit;
         public void setPrice(double price) {
              this.price = price;
         public double getPrice() {
              return price;
         // Get the value of the inventory
         public double calculateInventory() {
              return unit * price;
         // Get the value of all inventory
         public static double calculateEntireInventory(DVD [] prod) {
              double sum = 0;
              for (int i = 0; i < prod.length; i++)
                   sum += prod.getUnit() * prod[i].getPrice();
              return sum;
         // Sort inventory by name
         public static Movie [] sortInventory(Movie [] prod) {
         boolean doMore = true;
    while (doMore) {
    doMore = false; // last pass over array
    for (int i=0; i<prod.length-1; i++) {
    if (prod[i].getName().compareTo(prod[i+1].getName()) > 0) {
    Movie temp = prod[i]; prod[i] = prod[i+1]; prod[i+1] = temp;
    doMore = true;
         return prod;
    public class Movie extends DVD{
         //instant variable
         protected String dvdTitle;
    public Movie(int itemNum, String name, int unit, double price, String dvdTitle) {
         super(itemNum, name, unit, price);
         this.dvdTitle = dvdTitle;
    public String getdvdTitle() {
              return dvdTitle;
         // Get the value of the inventory
         public double calculateInventory(DVD[] dvd) {
              double sum = 0;
              for (int i = 0; i < dvd.length; i++)
                   sum += 0.05* dvd[i].getUnit() * dvd[i].getPrice();
              return sum;
    public double calculateRestockFee(){
         return price*0.05;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.text.DecimalFormat;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    public class Inventory extends JApplet {
         private JLabel itemNumLabel = new JLabel("Item Number: ");
         private JTextField itemNum = new JTextField();
         private JLabel itemNameLabel = new JLabel("Category: ");
         private JTextField itemName = new JTextField();
         private JLabel unitLabel = new JLabel("Number of Units: ");
         private JTextField unit = new JTextField();
         private JLabel priceLabel = new JLabel("Unit Price: ");
         private JTextField price = new JTextField();
         private JLabel dvdTitleLabel = new JLabel("DVD Title: ");
         private JTextField dvdTitle = new JTextField();
         private JLabel rfLabel = new JLabel("Restocking Fee");
         private JTextField rfValue = new JTextField();
         private JLabel inventoryLabel = new JLabel("Inventory value: ");
         private JTextField inventoryValue = new JTextField();
         private JLabel totalValue = new JLabel();
         private JButton previous = new JButton("Previous");
         private JButton next = new JButton("Next");
         private JButton last = new JButton("Last");
         private JButton first = new JButton("First");
         private JButton add = new JButton("Add");
         private JButton delete = new JButton("Delete");
         private JButton modify = new JButton("Modify");
         private JButton save = new JButton("Save");
         private JButton search = new JButton("Search");
         private JLabel totalInventory = new JLabel();
         private Movie[] DVDArray = null;
         private int current = 0;
         private int total = 0;
         class ButtonListener implements ActionListener {
              public void actionPerformed(ActionEvent e) {
                   JButton button = (JButton) e.getSource();
                   if (button == previous) current = (current + total - 1) % total;
                   if (button == next) current = (current + 1) % total;
                   if (button == last) current = (current = 5) % total;
                   if (button == first) current = (current =0) % total;
                   if (button == modify) itemName.setVisible(true);
         private void display() {
              Movie movie = DVDArray[current];
              DecimalFormat df=new DecimalFormat("$#.00");
              itemNum.setText(movie.getItemNum()+""); itemNum.setEditable(false);
              itemName.setText(movie.getName()); itemName.setEditable(false);
              unit.setText(movie.getUnit()+""); unit.setEditable(false);
              price.setText(df.format(movie.getPrice())); price.setEditable(false);
              dvdTitle.setText(movie.getdvdTitle()); dvdTitle.setEditable(false);
              rfValue.setText(df.format(movie.calculateRestockFee())); rfValue.setEditable(false);
              inventoryValue.setText(df.format(movie.calculateInventory())); inventoryValue.setEditable(false);
              totalValue.setText("The total inventory value is " + df.format(DVD.calculateEntireInventory(DVDArray)));
         final JLabel label; // logo
    //JLabel constructor for logo
    Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
    label = new JLabel(logo); // create logo label
    label.setToolTipText("Company Logo"); // create tooltip
         public void init() {
              DVDArray = new Movie [6];
              // Add DVD items into the list
              DVDArray[0] = new Movie (15, "Action", 65,12.00,"Frequency");
              DVDArray[1]= new Movie(33, "Comedy", 12, 21.00, "Norbit");
              DVDArray[2] = new Movie(13, "Disney",33,14.00,"Flubber");
              DVDArray[3] = new Movie(22, "Drama", 48, 18.00,"Citizens Kane");
              DVDArray[4] = new Movie(47, "Horror", 42, 19.00,"Pycho");
              DVDArray[5] = new Movie(26, "Sci-Fi", 27, 26.00,"The Abyss");
    total = 6;
    current = 0;
    ButtonListener buttonListener = new ButtonListener();
    previous.addActionListener(buttonListener);
    next.addActionListener(buttonListener);
    last.addActionListener(buttonListener);
    first.addActionListener(buttonListener);
    add.addActionListener(buttonListener);
    delete.addActionListener(buttonListener);
    modify.addActionListener(buttonListener);
    save.addActionListener(buttonListener);
    search.addActionListener(buttonListener);
    JPanel up = new JPanel();
    up.setLayout(new GridLayout(7,2));
    up.add(itemNumLabel); up.add(itemNum);
    up.add(itemNameLabel); up.add(itemName);
    up.add(dvdTitleLabel); up.add(dvdTitle);
    up.add(unitLabel); up.add(unit);
    up.add(priceLabel); up.add(price);
    up.add(rfLabel); up.add(rfValue);
    up.add(inventoryLabel); up.add(inventoryValue);
    display();
    JPanel middle = new JPanel();
    middle.setLayout(new FlowLayout());
    middle.add(previous); middle.add(next);middle.add(last);middle.add(first);
    middle.add(add);middle.add(delete);middle.add(modify);middle.add(search);
    middle.add(save);
    JPanel down = new JPanel();
    down.setLayout(new BorderLayout());
    down.add(BorderLayout.CENTER, totalValue);
    JPanel all = new JPanel();
    all.setLayout(new BoxLayout(all, BoxLayout.Y_AXIS));
    all.add(up);
    all.add(down);
    all.add(middle);
    Container cp = getContentPane();
    cp.add(BorderLayout.NORTH, all);
    public static void main(String args []) {
    JApplet applet = new Inventory();
    JFrame frame = new JFrame("DVD Inventory");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    Container cp=frame.getContentPane();
    cp.add(applet);
    frame.setSize(600,330);
    applet.init();
    frame.setVisible(true);
    // Icon logo = new ImageIcon(getResource( "logo.gif" ) );
    } //end main
    } // end class Inventory                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Your code has some good spots and some bad spots or problems, and I'll try to hit on some of the more obvious problems (the ones that I can see immediately) so that you can try to fix it.
    1) Your DVD class overall looks pretty good until we get to the end. The method public static double calculateEntireInventory(DVD[] prod) shouldn't be part of the DVD class since it has nothing to do with an individual DVD (which is what this class is all about) and everything to do with a collection of DVDs. You should move this to another class, a non-GUI Inventory class.
    2) The method public static Movie[] sortInventory(Movie[] prod) also shouldn't be in your DVD class for the same reason as noted above, and also because it deals with Movie objects which are objects that descend from DVD. The parent really shouldn't have to depend on the child class to function, and leaving this in would likely break your code at some time or another. Again, put this in a non-GUI Inventory class. You probably should use a DVD parameter, not a Movie parameter. Another option is to have your DVD and Movie classes implement the Comparable interface, since if you do this, sorting any collection of these is a breeze by using Arrays.sort(...) or Collections.sort(...).
    3) Again (starting to sound like a broken record) the method public double calculateInventory(DVD[] dvd) shouldn't be part of the Movie class for the very same reasons noted above.
    4) You need to create a non-GUI Inventory class, shoot, you can call it NonGuiInventory if you'd like (though I'd call it Inventory and call the GUI class GuiInventory) that has all the important functionality that the GUI will display. This class holds a collection of DVDs (or Movies), has an int index that points to the current Movie of interest, has a next() method that advances this index and returns the next Movie in the collection (or the first if you're at the last), has a previous() method that does the opposite, has a first() method that sets the index to zero and returns the first Movie in the collection, a last() method that advances the index to the size of the collection - 1 and returns this Movie, and has a sort method that sorts the collection. You can even have add(Movie) and a remove(Movie) methods here. By separating this functionality from the GUI, you are able to simplify your task by dividing and conquering.
    5) Finally you can display all this with your InventoryGUI class that uses the above class as its model, displaying the current Movie that is pointed to by the Inventory's index, that when the next() method is called gets the Movie returned by it and displays it.
    Note that if you go this route, you'll need to do some major re-writes of the GUI class, but it will improve your program greatly.
    HTH and good luck

  • Inventory Program Pt 2 - I have most of it, but I can't get it finished.

    Hello. I am currently stumped. I am already a day late with this assignment and I cannot figure out the logic to use to calculate the overall value of the entire inventory. I'm pasting my code here in the hopes that someone can tell me what it is I'm not thinking of. I also need to do a bubblesort to display the inventory sorted by name of the computer game listed; with several arrays, I don't know how I'm going to keep the related information together. Please help!
    /*                       Inventory Program Part 2
    Modify the Inventory Program so the application can handle multiple items. Use an
    array to store the items. The output should display the information one product
    at a time, including the item number, the name of the product, the number of units
    in stock, the price of each unit, and the value of the inventory of that product.
    In addition, the output should display the value of the entire inventory.
    Create a method to calculate the value of the entire inventory.
    Create another method to sort the array items by the name of the product.   */
    package InventoryPart2; // Comment out later
    import java.util.Scanner; // Program uses class Scanner to accept user input
    public class InventoryPt2 // Main method begins execution of Java application
         public static void main (String args [])
            // create Scanner to obtain input from command window
              Scanner input = new Scanner( System.in );
            computerGame gameInfo = new computerGame(); // Instantiates the computerGame object
            invValue inventoryValue = new invValue(); // Instantiates the invValue object
            // Initialize arrays for storage of inventory information
            // Need to perform bubble sort on each array in an index-controlled loop
            String gameNumber[] = new String[100];
            String gameName[] = new String[100];
            int gameStock[] = new int[100];
            double gamePrice[] = new double[100];
            double gameStockVal[] = new double[100];
            // Show Program Welcome Message
         System.out.println(); // White space
         System.out.println( "Welcome to the Computer Game Inventory Program!!!");
            System.out.println();
            System.out.println( "      Copyright 2009 by Some Guy");
            System.out.println(); // White space
         System.out.println(); // White space, again
              // Prompt for the number of games
              System.out.print( "How many different computer games are you entering? "); // Prompt for input
              int maxCount = input.nextInt(); // Read input
              input.nextLine(); // Clear-out
            int counter = 0;
            do // Begin a loop to collect information about each game entered
            System.out.println();
            System.out.print( "Please enter an item ID number: ");
            gameInfo.setNumber(input.next());
            gameNumber[counter] = gameInfo.getNumber();
            System.out.println();
            System.out.print( "Please enter a name for the game: ");
            gameInfo.setName(input.next());
            gameName[counter] = gameInfo.getName();
            System.out.println();
            System.out.print( "Please enter the number on-hand: ");
            gameInfo.setStock(input.nextInt());
            gameStock[counter] = gameInfo.getStock();
            System.out.println();
            System.out.print( "Please enter the price of this game: $");
            gameInfo.setPrice(input.nextDouble());
            gamePrice[counter] = gameInfo.getPrice();
            System.out.println();
            gameStockVal[counter] = gameInfo.thisItemVal();
            counter = counter + 1;
            while ( counter < maxCount ); // End loop
            counter = 0;
            //double totalValue = 0 + gameStockVal[counter];
            do
            System.out.println( "          Item number: " + gameNumber[counter] );
            System.out.println( "            Game name: " + gameName[counter] );
            System.out.println( "      Number in stock: " + gameStock[counter] );
            System.out.print  ( "           Price each: $" );
            System.out.printf( "%1.2f", gamePrice[counter] );
            System.out.println();
            System.out.print  ( "Total value this item: $" );
            System.out.printf( "%1.2f", gameStockVal[counter] );
            System.out.println();
            System.out.println();
            counter = counter + 1;
            while ( counter < maxCount );
            System.out.print( "The total value of all inventory is: $" );
            System.out.printf ( "%1.2f", ??? );
            System.out.println();
            System.out.println();
        } // End main method
    } // End class InventoryPt2
    class computerGame
        private String number; // Declaration of variables
        private String name;
        private int stock;
        private double price;
       public computerGame() // Default constructor
            number = "";
            name = "";
            stock = 0;
            price = 0.00;
        // Parameterized constructor
        public computerGame( String number, String name, int stock, double price )
            this.number = number;
            this.name = name;
            this.stock = stock;
            this.price = price;
        public void setNumber ( String number ) // Method to store and return the game's ID number
                this.number = number;
            String getNumber()
                return number;
        public void setName ( String name ) // Method to store and return the game's name
                this.name = name;
            String getName()
                return name;
        public void setStock ( int stock ) // Method to store and return how many of a game are in stock
                this.stock = stock;
            int getStock()
                return stock;
        public void setPrice ( double price ) // Method to store and return a game's price
                this.price = price;
            double getPrice()
                return price;
        public double thisItemVal()
                return ( stock * price );
    class invValue
        double totalValue;
        public invValue() // Default constructor
            totalValue = 0.00;
        public invValue( double totalValue ) // Parameterized constructor
            this.totalValue = totalValue;
        public void setValue ( double totalValue )
            this.totalValue = totalValue;
        public double getValue()
            return totalValue;
    }

    This is a place to ask questions, not a place for others to complete your homework. Accept the grade and learn from your mistake/s. Gl with the future.
    Mel

  • Need help with inventory program!!! someone please help me!!!

    Ok I have to write this inventory program for one of my classes.
    For part one i needed to Create a product class that holds the item number, the name of product, the number of units in stock, and the price of each unit.
    Then create a java application that displays all of the above info plus the total value of the inventory. I have done this so far with success.
    For part two i needed to modify the program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time including the item number, the name of the product, the number of units in stock, the price per unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
    so create a method to calculate the value of the entire inventory.(i did this)
    and create another method to sort the array items by the name of the product. ( i did this)
    The program compiles and runs fine except it is not doing anything from part two. It just does the same thing that it did when i wrote part one.
    Does anyone know why or what i need to do to my code.
    Here is my code.
    import java.util.Scanner; // program uses class Scanner
    import java.util.Arrays;
    class ProductList
      Product[] products = new Product[100]; // an array of 100 pruducts
      private void populate() {
        products[0] = new Product(0, "Good Luck Chuck"      , 25, 4.95);
        products[1] = new Product(1, "The Bourne Identity"  ,  3, 7.95);
        products[2] = new Product(2, "The Reaping"          ,  5, 8.99);
          products[3] = new Product(3, "Deja Vu"              ,  2,12.99);
          products[4] = new Product(4, "I Know Who Killed Me" ,  3,10.95);
      private void sortByTitle() {
      private void print() {
        for(int i=0; i<products.length; i++) {
          System.out.println(products);
    private void printTotalInventoryValue() {
    System.out.println("Total Inventory Value = "+calculateTotalInventoryValue());
    private double calculateTotalInventoryValue() {
    double total = 0D;
    for(int i=0; i<products.length; i++) {
    total += products[i].calculateInventoryValue();
    return total;
    public static void main( String args[] ) {
    ProductList list = new ProductList();
    list.populate();
    list.sortByTitle();
    list.print();
    list.printTotalInventoryValue();
    } class Product
    private int id;
    private String title;
    private int stock;
    private double price;
    public Product(int id, String title, int stock, double price) {
    setId(id);
    setTitle(title);
    setStock(stock);
    setPrice(price);
    public int getId() { return this.id; }
    public void setId(int id) { this.id = id; }
    public String getTitle() { return this.title; }
    public void setTitle(String title) { this.title = title; }
    public int getStock() { return this.stock; }
    public void setStock(int stock) { this.stock = stock; }
    public double getPrice() { return this.price; }
    public void setPrice(double price) { this.price = price; }
    public double calculateInventoryValue() {
    return getStock() * getPrice();
    public class Inventorypt2
    private String ProductInfo; // call class product info
    public static void main(String args[])
    //create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );
    int num; // product's item number
    int stock; // number of items in stock
    double price; // price each of item
    ProductInfo product; // product information instance
    System.out.println(); // blank line
    String name = "go";
    // loop until sentinel value read from user
    while ( !name.equalsIgnoreCase ("stop") )
    System.out.print( "Enter DVD title, or STOP to quit: "); // prompt
    name = input.nextLine(); // read item name from user or quit
    System.out.print( "Enter the item number: "); // prompt
    num = input.nextInt(); // read item number from user
    while ( num <=0 ) //loop until item number is positive
    System.out.println ("Item number must be positive. Please re-enter item number: ");//prompt user to re-enter item number
    num = input.nextInt(); // read item number
    } //end while
    System.out.print( "Enter the quantity in stock: "); // prompt
    stock = input.nextInt(); // read stock quantity from user
    while ( stock <0 ) //loop until stock is positive
    System.out.println ("Quantity in stock can not be less than zero. Please re-enter the quantity in stock: ");//prompt user to re-enter quantity in stock
    stock = input.nextInt(); // read stock quantity from user
    } //end while
    System.out.print( "Enter the price of DVD: "); // prompt
    price = input.nextDouble(); // read item price from user
    while ( price <=0 ) //loop until price is positive
    System.out.println ("Product price must be positive. Please re-enter the price of the product: ");//prompt user to re-enter product price
    price = input.nextDouble(); // read item price from user
    } //end while
    product = new ProductInfo( num, name, stock, price); // initialize ProductInfo variables
    System.out.println(); // blank line
    System.out.printf( "Item Name: %S\n", product.getName());
    System.out.printf( "Item Number: %s\n", product.getNum());
    System.out.printf( "Qty. in Stock: %s\n", product.getStock());
    System.out.printf( "Price Each: $%.2f\n", product.getPrice());
    System.out.printf( "Total Value in Stock: $%.2f\n", product.getInventoryTotal());
    System.out.println(); // blank line
    System.out.print( "Enter DVD title, or STOP to quit: "); // prompt
    name = "";
    while ( name.equals("") )
    name = input.nextLine(); // read new product name from user or quit
    } //end while
    System.out.println(); // blank line
    System.out.println("Good Bye!"); // exit message
    Edited by: jay1981 on Mar 16, 2008 2:07 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You will get more help if your code is formatted better:
    * Only post code that is already formatted correctly including indentations.
    * Get rid of all those comments cluttering up your code.
    * Make sure your posted code compiles without need for any changes. Yours doesn't at present. Where is the ProductInfo class?
    Again, you want it easy for a volunteer here to read your post, otherwise he/she simply won't do it. Good luck.

  • Can anyone help me solve my problem trying add GUI to Inventory program?

    Here is my code in which I am receiving a couple of errors.
    package inventory4;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Inventory4 extends JFrame implements ActionListener {
        private class MyPanel extends JPanel {
            ImageIcon image = new ImageIcon("Sample.jpg");
            int width = image.getIconWidth();
            int height = image.getIconHeight();
            long angle = 30;
            public MyPanel() {
                super();
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g;
                g2d.rotate(Math.toRadians(angle), 60 + width / 2, 60 + height / 2);
                g2d.drawImage(image.getImage(), 60, 60, this);
                g2d.dispose();
        }//end class MyPanel
        int currentIndex; //Currently displayed Item
        Product[] supplies = new Product[4];
        JLabel name;
        JLabel number;
        JLabel title;
        JLabel quantity;
        JLabel price;
        JLabel fee;
        JLabel totalValue;
        JTextField nameField = new JTextField(20);
        JTextField numberField = new JTextField(20);
        JTextField titleField = new JTextField(20);
        JTextField quantityField = new JTextField(20);
        JTextField priceField = new JTextField(20);
        JPanel display;
        JPanel displayHolder;
        JPanel panel;
        public Inventory4() {
            setSize(500, 500);
            setTitle("Bob's CD Inventory Program");
    //make the panels
            display = new JPanel();
            JPanel other = new JPanel();
            JPanel picture = new MyPanel();
            JPanel centerPanel = new JPanel();
            displayHolder = new JPanel();
            display.setLayout(new GridLayout(7, 1));
    //other.setLayout(new GridLayout(1, 1));
    //make the labels
            name = new JLabel("Name :");
            number = new JLabel("Number :");
            title = new JLabel("Title :");
            quantity = new JLabel("Quantity :");
            price = new JLabel("Price :");
            fee = new JLabel("Restocking Fee :");
            totalValue = new JLabel("Total Value :");
    //Add the labels to the display panel
            display.add(name);
            display.add(number);
            display.add(title);
            display.add(quantity);
            display.add(price);
            display.add(fee);
    //Add the panels to the frame
            getContentPane().add(centerPanel, "Center");
            getContentPane().add(other, "South");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
    class CD extends Product {
        String genre;
        double restockingFee;
        public CD(String genre, double restockingFee, int item, String title, double stockQuantity,
                double price) {
            //super(title,item, stockQuantity, price);
            this.genre = genre;
            this.restockingFee = restockingFee;
        // TODO Auto-generated constructor stub
        //returns the value of the inventory, plus the restocking fee
        public double getInventoryValue() {
            // TODO Auto-generated method stub
            return super.getItemPrice() + restockingFee;
        public String toString() {
            StringBuffer sb = new StringBuffer("Genre      \t").append(genre).append("\n");
            sb.append(super.toString());
            return sb.toString();
    //Inventory4.java
    class Product implements Comparable {
        private String title;   // class variable that stores the item name
        private int item;     // class variable that stores the item number
        private double stockQuantity;   // class variable that stores the quantity in stock
        private double price;     // class variable that stores the item price
        private String genre;
        public Product() {
            title = "";
            item = 0;
            stockQuantity = 0;
            price = 0.0;
            genre = "";
        public Product(String title, String genre, int item, double stockQuantity, double price) {
            this.title = title;
            this.item = item;
            this.stockQuantity = stockQuantity;
            this.price = price;
            this.genre = genre;
        public void setTitle(String title) {
            this.title = title;
        public String getTitle() {
            return title;
        public void setItem(int item) {
            this.item = item;
        public int getItem() {
            return item;
        public void setStockQuantity(double quantity) {
            stockQuantity = quantity;
        public double getStockQuantity() {
            return stockQuantity;
        public void setItemPrice(double price) {
            this.price = price;
        public double getItemPrice() {
            return price;
        public void setGenre(String genre) {
            this.genre = genre;
        public String getGenre() {
            return genre;
        public double calculateInventoryValue() {
            return price * stockQuantity;
        public int compareTo(Object o) {
            Product p = null;
            try {
                p = (Product) o;
            } catch (ClassCastException cE) {
                cE.printStackTrace();
            return title.compareTo(p.getTitle());
        public String toString() {
            return "CD Title: " + title + "\nGenre: " + genre + "\nItem #: " + item + "\nPrice: $" + price + "\nQuantity: " + stockQuantity + "\nValue with restocking fee: $" + (calculateInventoryValue() + (calculateInventoryValue() * .05));
    public class Inventory4 {
        Product[] supplies;
        public static void main(String[] args) {
            Inventory4 inventory = new Inventory4();
            inventory.addProduct(new Product("Mozart", "Classical", 1, 54, 11.50));
            inventory.addProduct(new Product("Beethoven", "Classical", 2, 65, 12.00));
            inventory.addProduct(new Product("Tiny Tim", "Classical", 3, 10, 1.00));
            System.out.println("Inventory of CD's:\n\n");
            System.out.println();
            inventory.showInventory();
            System.out.println();
            double total = inventory.calculateTotalInventory();
            System.out.println("Total Value is: $" + (total + (total * .05)));
        public void sortByName() {
            for (int i = 1; i < supplies.length; i++) {
                int j;
                Product val = supplies;
    for (j = i - 1; j > -1; j--) {
    Product temp = supplies[j];
    if (temp.compareTo(val) <= 0) {
    break;
    supplies[j + 1] = temp;
    supplies[j + 1] = val;
    //creates a String representation of the array of products
    public String toString() {
    String s = "";
    for (Product p : supplies) {
    s = s + p.toString();
    s = s + "\n\n";
    return s;
    //Using an array so adding an item requires us to increase the size of the array first
    public void addProduct(Product p1) {
    if (supplies == null) {
    supplies = new Product[0];
    Product[] p = supplies; //Copy all products into p first
    Product[] temp = new Product[p.length + 1]; //create bigger array
    for (int i = 0; i < p.length; i++) {
    temp[i] = p[i];
    temp[(temp.length - 1)] = p1; //add the new product at the last position
    supplies = temp;
    //sorting the array using Bubble Sort
    public double calculateTotalInventory() {
    double total = 0.0;
    for (int i = 0; i < supplies.length; i++) {
    total = total + supplies[i].calculateInventoryValue();
    return total;
    public void showInventory() {
    System.out.println(toString()); //call our toString method

    I re-entered the package and changed some of the code. I am building successfully, but getting a new msg: init:
    deps-jar:
    compile:
    run:
    java.lang.NoClassDefFoundError: Inventory5_5
    Caused by: java.lang.ClassNotFoundException: Inventory5_5
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    Exception in thread "main"
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds) I may have to go ahead and submit it as is to get it in on time. Thank you very much for your help and your patience. Here is my last effort.package inventory4;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class inventory4 extends JFrame  {
        private class MyPanel extends JPanel {
            ImageIcon image = new ImageIcon("Sample.jpg");
            int width = image.getIconWidth();
            int height = image.getIconHeight();
            long angle = 30;
            public MyPanel() {
                super();
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g;
                g2d.rotate(Math.toRadians(angle), 60 + width / 2, 60 + height / 2);
                g2d.drawImage(image.getImage(), 60, 60, this);
                g2d.dispose();
        }//end class MyPanel
        int currentIndex; //Currently displayed Item
        Product[] supplies = new Product[4];
        JLabel name;
        JLabel number;
        JLabel title;
        JLabel quantity;
        JLabel price;
        JLabel fee;
        JLabel totalValue;
        JTextField nameField = new JTextField(20);
        JTextField numberField = new JTextField(20);
        JTextField titleField = new JTextField(20);
        JTextField quantityField = new JTextField(20);
        JTextField priceField = new JTextField(20);
        JPanel display;
        JPanel displayHolder;
        JPanel panel;
        public inventory4() {
            setSize(500, 500);
            setTitle("Bob's CD Inventory Program");
    //make the panels
            display = new JPanel();
            JPanel other = new JPanel();
            JPanel picture = new MyPanel();
            JPanel centerPanel = new JPanel();
            displayHolder = new JPanel();
            display.setLayout(new GridLayout(7, 1));
    //other.setLayout(new GridLayout(1, 1));
    //make the labels
            name = new JLabel("Name :");
            number = new JLabel("Number :");
            title = new JLabel("Title :");
            quantity = new JLabel("Quantity :");
            price = new JLabel("Price :");
            fee = new JLabel("Restocking Fee :");
            totalValue = new JLabel("Total Value :");
    //Add the labels to the display panel
            display.add(name);
            display.add(number);
            display.add(title);
            display.add(quantity);
            display.add(price);
            display.add(fee);
    //Add the panels to the frame
            getContentPane().add(centerPanel, "Center");
            getContentPane().add(other, "South");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
    class CD extends Product {
        String genre;
        double restockingFee;
        public CD(String genre, double restockingFee, int item, String title, double stockQuantity,
                double price) {
            //super(title,item, stockQuantity, price);
            this.genre = genre;
            this.restockingFee = restockingFee;
        // TODO Auto-generated constructor stub
        //returns the value of the inventory, plus the restocking fee
        public double getInventoryValue() {
            // TODO Auto-generated method stub
            return super.getItemPrice() + restockingFee;
        public String toString() {
            StringBuffer sb = new StringBuffer("Genre      \t").append(genre).append("\n");
            sb.append(super.toString());
            return sb.toString();
    //Inventory4.java
    class Product implements Comparable {
        private String title;   // class variable that stores the item name
        private int item;     // class variable that stores the item number
        private double stockQuantity;   // class variable that stores the quantity in stock
        private double price;     // class variable that stores the item price
        private String genre;
        public Product() {
            title = "";
            item = 0;
            stockQuantity = 0;
            price = 0.0;
            genre = "";
        public Product(String title, String genre, int item, double stockQuantity, double price) {
            this.title = title;
            this.item = item;
            this.stockQuantity = stockQuantity;
            this.price = price;
            this.genre = genre;
        public void setTitle(String title) {
            this.title = title;
        public String getTitle() {
            return title;
        public void setItem(int item) {
            this.item = item;
        public int getItem() {
            return item;
        public void setStockQuantity(double quantity) {
            stockQuantity = quantity;
        public double getStockQuantity() {
            return stockQuantity;
        public void setItemPrice(double price) {
            this.price = price;
        public double getItemPrice() {
            return price;
        public void setGenre(String genre) {
            this.genre = genre;
        public String getGenre() {
            return genre;
        public double calculateInventoryValue() {
            return price * stockQuantity;
        public int compareTo(Object o) {
            Product p = null;
            try {
                p = (Product) o;
            } catch (ClassCastException cE) {
                cE.printStackTrace();
            return title.compareTo(p.getTitle());
        public String toString() {
            return "CD Title: " + title + "\nGenre: " + genre + "\nItem #: " + item + "\nPrice: $" + price + "\nQuantity: " + stockQuantity + "\nValue with restocking fee: $" + (calculateInventoryValue() + (calculateInventoryValue() * .05));
    public class Inventory4 {
        Product[] supplies;
        public static void main(String[] args) {
            Inventory4 inventory = new Inventory4();
            inventory.addProduct(new Product("Mozart", "Classical", 1, 54, 11.50));
            inventory.addProduct(new Product("Beethoven", "Classical", 2, 65, 12.00));
            inventory.addProduct(new Product("Tiny Tim", "Classical", 3, 10, 1.00));
            System.out.println("Inventory of CD's:\n\n");
            System.out.println();
            inventory.showInventory();
            System.out.println();
            double total = inventory.calculateTotalInventory();
            System.out.println("Total Value is: $" + (total + (total * .05)));
        public void sortByName() {
            for (int i = 1; i < supplies.length; i++) {
                int j;
                Product val = supplies;
    for (j = i - 1; j > -1; j--) {
    Product temp = supplies[j];
    if (temp.compareTo(val) <= 0) {
    break;
    supplies[j + 1] = temp;
    supplies[j + 1] = val;
    //creates a String representation of the array of products
    public String toString() {
    String s = "";
    for (Product p : supplies) {
    s = s + p.toString();
    s = s + "\n\n";
    return s;
    //Using an array so adding an item requires us to increase the size of the array first
    public void addProduct(Product p1) {
    if (supplies == null) {
    supplies = new Product[0];
    Product[] p = supplies; //Copy all products into p first
    Product[] temp = new Product[p.length + 1]; //create bigger array
    for (int i = 0; i < p.length; i++) {
    temp[i] = p[i];
    temp[(temp.length - 1)] = p1; //add the new product at the last position
    supplies = temp;
    //sorting the array using Bubble Sort
    public double calculateTotalInventory() {
    double total = 0.0;
    for (int i = 0; i < supplies.length; i++) {
    total = total + supplies[i].calculateInventoryValue();
    return total;
    public void showInventory() {
    System.out.println(toString()); //call our toString method

  • Help with Java Inventory Program - I almost got it

    Hello, I'm new to the forum so please don't hang me if I'm not posting this correctly or in the right place. I'm writing a Java Inventory Program for class and everything was great until we had to modify it to sort by product name (in my case dvd's). The problem is my arrays for inventory count and price are thrown off when I sort by dvd name because they are predefined. I could cheat and just rearrange the array in a logical order according to the dvd title but that isn't really the answer for me. Can someone help me do where my inventory count and price don't go out of wack when I sort by dvd name, I really don't want to start over.
    Here is my code:
    // Java InventoryProgram2
    // Purpose of application is to Display DVD Inventory
    import java.util.Arrays;
    public class InventoryProgram2 // declare public class
    { // Start of public class InventoryProgram1
         String dvdName[] = { "The Departed", "The Dark Knight","The Mummy", "Minority Report"};
         double itemNum;
         float stockCount[] = {3, 5, 8,2};
         float totalValue [] = new float [4];
         float price[] = { 19, 22, 17, 14};
         float totInvVal;
              // Method for printing dvdName the dvdName
              public void DvdName ()
              { // Start of print method
                   // For loop to calculate total value
                   Arrays.sort(dvdName);
                   for( int itemNum = 0; itemNum < dvdName.length; itemNum ++ )
                        totalValue[itemNum] = stockCount[itemNum] * price[itemNum];
                   System.out.printf( "%s %15s %12s %12s %12s\n", "Item Number", "Dvd Name", "Price", "Stock", "Total"); // Prints title of column
                   for ( int itemNum = 0; itemNum <dvdName.length; itemNum ++ )
                        System.out.printf("%-8d %20s %10.02f %12.02f %12.02f\n", itemNum, dvdName[itemNum], price [itemNum],stockCount[itemNum], totalValue[itemNum]); // Calls the value of each column
         } // end of method to print dvdName
         // Method for total value of the inventory
         public void totalInvValue()
         { //start of method to calc total inv value
         totInvVal = stockCount [0] * price [0] + stockCount [1] * price [1] + stockCount [2] * price [2] + stockCount [3] * price [3];
         System.out.printf("%s", "The Total Value of the Inventory is:","%10.02f");
         System.out.printf("$%.02f", totInvVal);
         } // end of method to calc total inv value
    } // End of public class InventoryProgram1
    // Java InventoryProgram2_Test
    // Purpose of application is to Display DVD Inventory
    public class InventoryProgram2_Test
    { // Start Bracket for InventoryProgram1
    public static void main ( String args[] )
    { // Start Bracket for Public Main
         InventoryProgram2 myInventoryProgram2 = new InventoryProgram2(); // invokes InventoryProgram1
    myInventoryProgram2.DvdName (); // calls DvdName Method
         myInventoryProgram2.totalInvValue(); // call method total inventory value
    } // End Bracket for Public Main
    } // End Bracket for InventoryProgram1
    Edited by: ozzie2132 on Aug 11, 2008 6:57 PM
    Edited by: ozzie2132 on Aug 11, 2008 6:57 PM

    a_turingmachine wrote:
    naive ex:
    class DVD {
    String dvdName;
    float stockCount;
    float price;
    }--turing machine:
    Suggestion 1: If you are going to give code for someone doing homework, try not to give exactly what the OP needs but rather something similar. They will learn a lot more if they have to process your recommendations and then create their own code.
    Suggestion 2: When posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]or
    {&#99;ode}
      // your code block goes here.
      // note here that the tags are the same.
    {&#99;ode}

  • Inventory Program 2

    I need some serious help and I'd appreciate anyone who knows Java. Here is the assignment:
    Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
    *?h Create a method to calculate the value of the entire inventory.*
    *?h Create another method to sort the array items by the name of the product.*
    *?h Post as an attachment in java forma*
    I have not completed the program so I am not sure what kind of errors I will get. For some reason I cannot get past the first part of code. The errors are in bold print. The error for "new DVD(....) reads "cannot find symbol". The System.out.println("...") error reads "cannot find symbol..symbol: method getDVDPrice()...location: class inventoryprogram1app.DVD[]...operator + cannot be applied to java.lang.String,Arrray.getDVDPrice. I think that most of the bottom half is ok because I have no errors here, it's just the top part that I cant get past. Any help would be appreciated. Thanks.
    public class InventoryProgram1App
    public static void main(String[] args)
    DVD[]dvd =new DVD[10];
    new *DVD*("We Were Soilders","5","19.99","278");
    new *DVD*("Why Did I Get Married","3","15.99","142");
    new *DVD*("I Am Legend","9","19.99","456");
    new *DVD*("Transformers","4","19.99","336");
    new *DVD*("No Country For Old Men","4","16.99","198");
    new *DVD*("The Kingdom","6","15.99","243");
    new *DVD*("Eagle Eye","2","16.99","681");
    new *DVD*("The Day After Tomorrow","4","19.99","713");
    new *DVD*("Dead Presidents","3","19.99","493");
    new *DVD*("Blood Diamond","7","19.99","356");
    *System.out.println("DVD Title:" +DVD.getdvdTitle());+*
    *+System.out.println("DVD Price:"+ dvd.getDVDPrice());*
    *System.out.println("DVD units in stock:" +dvd.getDVDStock());+*
    *+System.out.println("DVD item number:"+ dvd.getDVDitemNumber());*
    *for (int counter = 0; > DVD.length; counter++);*
    class DVD
    private int dvdTitle;
    private double dvdPrice;
    private double dvdStock;
    private double dvditemNumber;
    public DVD(int title, double price, double stock, double itemNumber)
    this.dvdTitle = title;
    this.dvdPrice = price;
    this.dvdStock = stock;
    this.dvditemNumber = itemNumber;
    public void setDVDTitle(int title)
    this.dvdTitle = title;
    public int getdvdDTitle()
    return dvdTitle;
    public void setDVDPrice(double price)
    this.dvdPrice = price;
    public double getDVDPrice()
    return dvdPrice;
    public void setDVDStock(double stock)
    this.dvdStock = stock;
    public double getDVDStock()
    return dvdStock;
    public void setDVDitemNumber(double itemNumber)
    this.dvditemNumber = itemNumber;
    public double getDVDitemNumber()
    return dvditemNumber;
    public double getValue()
    return this.dvdStock * this.dvdPrice;
    }

    I really appreciate you helping me out with this. I looked at all of the replies and went back and changed what was suggested. I have a load of errors...(*java.lang.ClassFormatError: Method "<error>" in class inventoryprogram2app/InventoryProgram2App has illegal signature "Ljava/lang/Object;"*
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: inventoryprogram2app.InventoryProgram2App.  Program will exit.
    Exception in thread "main"
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    I am still working on the program and trying to correct the errors, but when I correct 1 or 2 errors lines that were not errors at first became errors. I've been working on this since last night and can't for the life of me figure out what I am doing wrong. The code is not completed because I am trying to correct the current errors. I did run the program to get the error messages. I would appreciate any advice on what I am doing wrong. Thanks in advance.
    public class InventoryProgram2App
        public static void main(String[] args)
            private DVD[]dvd =new DVD[10];
                Scanner input = new Scanner(System.in);
                String dvdTitle;
                double dvdPrice = 0.0;
                double dvdStock = 0.0;
                double dvditemNumber = 0.0;
                *dvd = new DVD();*
                *System.out.println("DVD Title: " + dvd.getDVDTitle());*
                *System.out.println("DVD Price:" + dvd.getDVDPrice());*
                *System.out.println("DVD units in stock:" + dvd.getDVDStock());*
                *System.out.println("DVD item number:" + dvd.getDVDitemNumber());*
                *System.out.println("DVD inventory value:" + dvd.getValue());*
    class DVD
        private String dvdTitle;
        private double dvdPrice;
        private double dvdStock;
        private double dvditemNumber;
         public DVD(String title, double price, double stock, double itemNumber)
            this.dvdTitle = title;
            this.dvdPrice = price;
            this.dvdStock = stock;
            this.dvditemNumber = itemNumber;
         public void setdvdTitle(String dvdTitle)
             *dvdTitle = dvdTitle;*
                *dvd[0] = new DVD("We Were Soilders","5","19.99","278");*
                *dvd[1] = new DVD("Why Did I Get Married","3","15.99","142");*
                *dvd[2] = new DVD("I Am Legend","9","19.99","456");*
                *dvd[3] = new DVD("Transformers","4","19.99","336");*
                *dvd[4] = new DVD("No Country For Old Men","4","16.99","198");*
                *dvd[5] = new DVD("The Kingdom","6","15.99","243");*
                *dvd[6] = new DVD("Eagle Eye","2","16.99","681");*
                *dvd[7] = new DVD("The Day After Tomorrow","4","19.99","713");*
                *dvd[8] = new DVD("Dead Presidents","3","19.99","493");*
                *dvd[9] = new DVD("Blood Diamond","7","19.99","356");*            }
         public void setdvdStock(int dvdStock)
            int stock = 0;
            if(dvdStock >= 0)
                dvdStock = stock;
            *else(dvdStock = 0)*     }
         public void setdvdPrice(double dvdPrice)
            double price;
            *if(dvdPrice = 0.0)*
                 price = dvdPrice;
             *else(price = 0.0)*
        public void setDVDTitle(String title)
            this.dvdTitle = title;
        public String getDVDTitle()
            return dvdTitle;
        public void setDVDPrice(double price)
            this.dvdPrice = price;
        public double getDVDPrice()
            return dvdPrice;
        public void setDVDStock(double stock)
            this.dvdStock = stock;
        public double getDVDStock()
            return dvdStock;
        public void setDVDitemNumber(double itemNumber)
            this.dvditemNumber = itemNumber;
        public double getDVDitemNumber()
            return dvditemNumber;
        public double getValue()
            return this.dvdStock * this.dvdPrice;
    class inventoryDVD
        int[] dvdValue = new int[10];
        for (int dvdS = 0;counter < DVD.length(); counter++);
        *dvdPrice * dvdStock[counter];*
        public String toString;
    }

  • TS3989 Mssage when opening Photo Stream on-"This file does not have a program associated with it for performing this action. Please install a program or, if one is already installed, create an association in the Default Programs control panel" Help!!!

    Mssage when opening Photo Stream on-"This file does not have a program associated with it for performing this action. Please install a program or, if one is already installed, create an association in the Default Programs control panel" Help!!!

    You are posting in the "icloud on my mac" forum, but your profile mentions Windows.  If using a mac, you need to have iphoto or aperture installed in order to receive new photos via photo stream.  If using windows, try posting in the iCloud on a PC forum.  You'll get better help there.
    https://discussions.apple.com/community/icloud/icloud_on_my_pc

  • How to do program for search help

    Hi,
    Please tell me how to do the program for search help in Dialog programming.
    Thanks,
    Sriram.

    Step 1:
    Create a function module (ZZ_TEST_FUNCTION).
    Step 2:
    --> Create a search help(ZSEARCH)
    --> Enter the above function Module(ZZ_TEST_FUNCTION) in search help exit field.
    STEP 3:
    Attach the search help with any field of table.
    Function module Sample Code:
    FUNCTION ZZ_TEST_FUNCTION.               
    ""Local interface:                    
    *"       IMPORTING                 
    *"             VALUE(MCONAME) DEFAULT SPACE *"             VALUE(SELSTR) DEFAULT SPACE
    *"       TABLES                      
    *"              SHLP_TAB TYPE  SHLP_DESCR_TAB_T
    *"              RECORD_TAB STRUCTURE  SEAHLPRES
    *"       CHANGING                   
    *"             VALUE(SHLP) TYPE  SHLP_DESCR_T *"             VALUE(CALLCONTROL) LIKE  DDSHF4CTRL 
    *"                             STRUCTURE  DDSHF4CTRL
    CALL SCREEN 100.
    Return from application back to SAP                   
      CASE save_ok_0100.                                    
        WHEN 'RSTR'.                                        
          callcontrol-step = 'SELONE2'.                     
        WHEN 'CANCEL' OR 'BACK' OR 'EXIT'.                  
          callcontrol-step = 'EXIT'.                        
        WHEN 'SEL'.                                         
            READ TABLE itab.                 
            record_tab = itab-filed1.           
            APPEND record_tab.                              
            callcontrol-step     = 'RETURN'.                
           EXIT.                                           
          ENDIF.                                            
      ENDCASE.                                              
    ENDFUNCTION.

  • Where to find my Serial Number for Photoshop CS6 Extended? The program has been on my computer for at least a year now and for some reason it is now requiring my serial number to run the program. Please help!

    Where to find my Serial Number for Photoshop CS6 Extended? The program has been on my computer for at least a year now and for some reason it is now requiring my serial number to run the program. Please help!

    Log in into your Adobe account and go to "My Products".  You'll find a list of all the products you've ever registered with Adobe.

  • When I turn on my PC with Vista 64 bits it gives a message "ApplephotoStreams.exe has stopped working. Windows will close program.  Please help.

    When I turn on my PC with Vista 64 bits it gives me a message "ApplePhotoSream.exe" has stopped working correctly. Windows will close the program.
    Please help!!!

    Hi, I have the same problem. Has anyone come forward with any advice on fixing the problem?

  • All my programs are opening in adobe even the system restore and the regisrty - how do I reset all programs to their originall default programs. Please help

    all my programs are opening in adobe even the system restore and the regisrty -
    how do I reset all programs to their originall default programs.
    Please help.
    PS I have also tried starting in save mode and still have the same problem.

    Hi,
    As
    BurrWalnut mentioned, first please run a virus scan to eliminate virus infection (if AV program is not opened in adobe)
    The files association could be corrupted in your situation, apart from the solution posted in the first reply, I also suggest you check Control Panel\All Control Panel Items\Default Programs\Set your Default Programs or Associate a file type or protocol
    with a progra,, manually check the association and check if it can do some help.
    Add: another way to open restore point is launching it in recovery console, please refer to this guide
    http://windows.microsoft.com/en-hk/windows/what-are-system-recovery-options#what-are-system-recovery-options=windows-7
    Yolanda Zhu
    TechNet Community Support

Maybe you are looking for