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

Similar Messages

  • I recently downloaded Adobe Premiere Element after testing the trial version...now I am having difficulty registering the program...please help...

    I recently downloaded Adobe Premiere Element after testing the trial version...now I am having difficulty registering the program...please help...

    Premiere Elements is not part of the Cloud, I will move this to that forum
    Premiere Elements Forum http://forums.adobe.com/community/premiere_elements
    Select a topic, then click I STILL NEED HELP to start Premiere Elements Online chat
    -http://helpx.adobe.com/contact.html?step=PRE

  • 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

  • Photoshop Elements 8. "Could not use Clone Stamp Tool because of a program error."  Please help.

    Photoshop Elements 8.  "Could not use Clone Stamp Tool because of a program error."  Please help.

    Try this:
    Open your picture file
    Access the clone stamp tool
    Hold down the ALT key on the keyboard and left click on the area from which you wish to clone, then release the ALT key, and click to place the pixels at the destination
    TIPS:
    It is a good idea to open a blank layer at the top in the layers palette, and do the cloning on this layer. Be sure that "sample all layers" at the top is checked. You can change the layer opacity if necessary
    Use the bracket keys next to the letter p on the keyboard to increase & decrease the size of the cursor
    Let us know  how you make out with the error message now.

  • Hello Since yesterday evening. My itunse program does not work my mobile. Note  I update the program to ios7 Please help me Thank you

    hi
    Hello
    Since yesterday evening. My itunse program does not work my mobile.
    Note
    I update the program to ios7
    Please help me
    Thank you

    I found this strange glitch that wouldn't let me open my iTunes Store. I tried all the reset options and still iTunes would close a second after it opened. I fixed this. Instead of using the iTunes Store icon on your home page to open it. Go into music and click on store. It will say "Cannot Connect To Store". Just tap ok. Then tap on "featured" on the bottom of the screen. That will take you to the store front page. After that is loaded. Back out and the icon for iTunes Store on the home page should work just fine. Hope that helps.

  • Hi, I don't have sound on my MacBook Air and the Mail program never respond, please help me out!

    Hi, I don't have sound on my MacBook Air and the Mail program never respond, please help me out!

    Hi Mr. Shahid,
    Thanks for visiting Apple Support Communities.
    Start with the troubleshooting tips in this article if you don't hear sound from your MacBook Air:
    OS X Mavericks: If you can’t hear sound from your speakers
    http://support.apple.com/kb/PH13841
    Best,
    Jeremy

  • 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.

  • 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() );
    }

  • Error while loading program...Please help.. :)

    Hello All,
    Have written a HTMLB program (DBConnect.java) which takes data from database and retrieves it in TableView.
    But it does not work.
    Get this error:
    Caused by: java.lang.NoClassDefFoundError: com/sapportals/portal/htmlb/page/PageProcessorComponent
    Loader Info -
    ClassLoader name: [com.sapportals.portal.prt.util.ApplicationClassLoader@1e72d6]
    Parent loader name: [com.sapportals.portal.prt.util.ApplicationClassLoader@9cf322]
    References:
       not registered!
    No resources !
    The error occurred while trying to load "com.sap.sample.database.DBConnect".
         at com.sap.engine.frame.core.load.ReferencedLoader.loadClass(ReferencedLoader.java:389)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:219)
         at com.sapportals.portal.prt.core.broker.PortalComponentItemFacade.getInstanceInternal(PortalComponentItemFacade.java:228)
         ... 30 more
    I have also included the PageProcessorComponent class file in my project properties.
    Please help....Whatz wrong.
    Awaiting Reply.
    Thanks and Warm Regards,
    Ritu R Hunjan

    Hi Ritu,
    Change the PrivateSharingReference to SharingReference in the xml
    <application-config>
        <property name="SharingReference" value="com.sap.portal.htmlb"/>
      </application-config>
    ==========
    Change your xml to
    <?xml version="1.0" encoding="utf-8"?>
    <application>
    <application-config>
    <property name="SharingReference" value="com.sap.portal.htmlb"/>
    </application-config>
    <components>
    <component name="DBConnect">
    <component-config>
    <property name="ClassName" value="com.sap.sample.database.DBConnect"/>
    </component-config>
    <component-profile>
    <property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld" />
    </component-profile>
    </component>
    </components>
    <services/>
    </application>

  • I can not update my iphoto program... please help

    when I download the latest version (604), I get a message that tell me
    "iPhoto Updater cannot be installed on this computer. An eligible iPhoto application could not be found in /Applications. Well there is an iPhoto 2.0 program there. Do I have to buy the latest version???
    Please help..
    Elizabeth
    G5, G4   Mac OS X (10.4.6)  

    Yes, in order to do the free up update, you must first purchase the upgrade. Buy iLife 06, and you'll get iPhoto 6, which you then want to update to 6.0.4. You'll also get the latest versions of iMovie, iDVD, iTunes, iWeb, and GarageBand. the iLife Suite is great fun. Check out the iLife suite at http://www.apple.com/ilife/
    And be sure to check the system requirements for RAM, etc.

  • Application server error (Part 2) - Please Help!

    Hi there
    Yesterday I made this thread, [Click Here|Application server error - Please Help!;
    We installed a application server and it could not locate that host which was fixed by adding the app server name in the host file on the production box. We now have another issue.
    I we remove/disable the app server the messages still fail, cause it's looking for the app server host. I checked in ZR10 but nothing there is pointing to the app server.
    Is there some other parameter we can check to change the system not to point to the app server but the original production server?
    Thanks,
    Jan
    Edited by: Jan de Lange on Feb 11, 2010 9:49 AM

    Hi Jan
    Check the How to guide below. This documents the necessry configurations etc.
    How Tou2026Scale Up SAP Exchange Infrastructure 3.0
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c3d9d710-0d01-0010-7486-9a51ab92b927?quicklink=index&overridelayout=true
    Regards
    Mark

  • Java program in XP - Please Help

    Hi, I am not sure if I am in the right fourm. I am not a developer, but a network engineer trying to help out my wife. My wife uses a java program to monitor the company she works for web site, which is not linked to a web browser. When she received the java program, it came with Java 1.2.2. Our PC had Windows 98 installed. I purchased a new machine, with Windows XP on it, and installed the java program and JRE on to it. The program does not work. The programmer who wrote the program was fired a few months ago, so I started looking through the internet, and the Sun fourms for a solution. First, the XP machine does not have Microsoft VM on it. Second, I upgraded the java to 1.4.1_02, following the instructions, still with no success. There was a suggestion to dual boot with Windows 98, but I really do not want to do that. What happens is - when you log in to the program, it just freezes. It does not go into the server. Any help is greatly appreciated.

    Possible reasons for the program hanging up
    1) The version of the VM on the machine is not correct.
    2) Even if the version is correct and correctly installed, can you please check whether the PATH and CLASSPATH variables are set correctly on the machine where you are running the program.
    3) I use WINXP as well with the latest version of VM downloaded from Sun and NOT Microsoft.
    Hopefully this might solve the issue.

  • Virtual Preload agreement/ Third parting applications Please help!

    Hi I am new to blackberry and smart phones. I have a Blackberry Curve and when I try to play games or other thing it is asking me this....
     If you agree to the conditions set out below by clicking “I Agree”, you will be linked to a third party site (“Linked Site”) not under the control of Research In Motion Limited or its affiliates (“RIM”).  RIM is offering this link to the Linked Site solely as a convenience to you, on the understanding that providing such link does not imply any endorsement by RIM of the Linked Site or its information or contents, nor does it imply any association between RIM and the Linked Site’s operator.  Also, any dealings with third parties conducted through the Linked Site are solely between you and such third party.  Any software application that you may download or otherwise acquire from the Linked Site for use on this handheld device is not licensed by RIM and is “Third Party Software” under the license agreement under which you, or the entity who authorized your use of this handheld device, originally licensed RIM’s proprietary software for this handheld device (“License Agreement”), and as such its use may be subject to certain terms and conditions established by a third party.  Please carefully review your License Agreement to understand your rights and obligations.  If you do not agree to the conditions set out here or do not wish to be linked to the Linked Site for any reason, do not click “I agree” below and please return to the home screen.
    I have read this about a million times and I have no idea what it is telling me. I need help understanding this more and I am also wondering is this going to cost money to agree to it and what it is linking me too 

    Hi and Welcome to the Community!
    The lawyers sure got ahold of that one, didn't they?!?!? All it is really saying is that, if you go to that linked site/3rd party app, RIM has no liability for whatever that linked site/3rd party app may do. When you agree, you absolve RIM of liability and agree that, no matter what, you will not seek any recourse from RIM. RIM has zero control over what that other site/app may do...anything they do is 100% between you and them, and RIM has no involvement (nor liability).
    Good luck!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Audio skipping and programs quitting unexpectedly, please help

    Hi all, I have a Power PC G5 running on OSX 10.3.9. I came into my room this morning to my fan running at an absurd speed and the computer was frozen. I restarted the computer, but the rest of the day, my audio has been skipping constantly (on itunes and also when played through Firefox) regardless of how many programs I have open. I have never had any issues with this before. I'm also having problems with programs freezing today and with programs quitting unexpectedly.
    What caused my fan to go nuts? The tower is sitting in a pretty dusty area, so it is possible that there is dust around the tower. I have no experience opening or cleaning a computer, so if that is what I should do, could you please instruct me on the best way to do that.
    I have about 40gb free with 110gb utilized on my Macintosh HD. The activity monitor shows that I only have 130mb Free of system memory (when I'm only running itunes, activity monitor, and firefox). The activity monitor also jumps from having abou 85% of the CPU idle when it is working fine down to below %40 percent when the audio is skipping. What is causing these jumps?
    Thank you for your help.
    Max

    Let's start with the basics.
    Try using Disk Utility to do a Disk Repair, as shown in this link, while booted up on your install disk.
    You could have some directory corruption. Let us know what errors Disk Utility reports and if DU was able to repair them.
     Cheers! DALE

Maybe you are looking for

  • Ipod shuffle will NOT keep music - only one CD downloaded - HELP!?

    WELL, it lets me add songs (supposedly) to the ipod. ONE of the cd's I purchased actually copied to the ipod. It says it's syncing, and it adds the other cd's to the library. But every time i eject the ipod and listen to it - only that one cd is ther

  • How to populate Java Beans List from the DB ?

    Hi, I have three tables called State,District and College. Assume, State table has fields statid,statename,statedescr District table has fields districtId,districtname,districtdescr and stateid College table has fields collegeid,collegename,collegede

  • How to use dbms_shared_pool ?

    Hi, When I tried to execute this package under SQL prompt using the following statement: execute sys.DBMS_SHARED_POOL.SIZES (1) ; An error 'PLS-00201: identifier 'SYS.DBMS_SHARED_POOL' must be declared' was prompted out. What should I do ? Thanks

  • How could I set the proxy settings for just some URLs and not for all?

    Hello, I am using HttpURLConnection to establish a HTTP connection . The connection pass through a proxy, and it requires security. I know that I can set the proxy settings in the system properties, and this works perfect. But I don't want to set the

  • Disk space required for Grid Control

    Just getting started with the Grid Control. Anyone know roughly how much disk space is required for a basic installation?