View Single Post
Old 07-08-2009, 01:43 PM   #1 (permalink)
ladymoe
Recruit
 
Join Date: Jul 2009
Posts: 6
ladymoe is on a distinguished road
Need help with part six of inventory program

I am very confused and need help. My assignment for this part is due this Sunday night at midnight. Thank you to anyone who can help me understand where I have gone wrong and where to go from here.

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.
I am not sure where to go. Below is my code and the response from the instructor when I turned it in last week for part 4.

You program did not compile due to some class definition issues. The first error stems from the fact you are defining multiple classes within the source code and the classes are not being correctly defined/ delimited. The following line:

public static void inventory (String args[])

wraps the entire program and causes it to fail as inventory has to be defined as a class at this point. The lines you mentioned in your post do not show up as errors, but there are some syntax errors such as spaces between assignment operators and your declaration of your import declaratives is not valid, based upon the situation mentioned above. You seem to have a good grasp on the GUI development, but you need to address the overall program construction.
Code:
package inventory;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
import java.lang.Object;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public static void inventory (String args[]){

class DVD {

private String dvdTitle;
private int stockQuantity;
private double Price;
private double itemNumber;
public DVD()
{
}
public DVD(String title, int stock, double price, double item) {
//call to Object constructor
dvdTitle = title;
stockQuantity = stock;
Price = price;
itemNumber = item;
} //end constructor

//set DVD title
public void setdvdTitle(String title) {
        setdvdTitle(title);
} //end method

//return dvd Title
public String getdvdTitle() {
return dvdTitle;
} //end method 

//set Dvd quantity
public void stockQuantity(int stock) {
stockQuantity = (stock < 0) ? 0 : stock;
} //end method

//return quantity
public double getstockQuantity() {
return stockQuantity;
} //end method

public void setPrice(double price) {
Price = (price < 0.0) ? 0.0 : price;
} //end method S

//return dvd price
public double getPrice() {
return Price;
} //end method

public void setitemNumber(double item) {
itemNumber = (item < 0.0) ? 0.0 : item;
} //end method

//return itemNumber
public double getitemNumber() {
return itemNumber;
} //end method


// calculate inventory value
public double getValue() {
return  getPrice() * stockQuantity;

} //end method


    double getInventoryValue() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    Object[] getitemPrice() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    Object[] value() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
 // end class Dvd

class dvdExt extends DVD{
    private String runningLength;
    private String Genre;
    double rate = 0.05;
    private double  restockingfee;
    public dvdExt(String title, int stock, double price, double item,String runningLength,String Genre)
    {
        super(title, stock, price, item);
        this.runningLength=runningLength;
        this.Genre=Genre;

    }

    public String getRunningLength() {
        return runningLength;
    }

    public String getGenre() {
        return Genre;
    }

    public void setRunningLength(String runningLength) {
        this.runningLength = runningLength;
    }

    public void setGenre(String Genre) {
        this.Genre = Genre;
    }

    public double getRestockingfee() {

        return super.getValue()*rate;
    }

}
public class Inventory3 {
        private Object[] products;
        private int numCDs;

        // Dvd = new Dvd ("Rocky", 20, 10.00, 100);
public void main(String args[]) {
int maxItems = 10;
long totalInventoryValue=0,totalRestockingFee=0;
dvdExt dvdcollection[] = new dvdExt[maxItems];
    try {
        String dvdtitle;
        double price;
        int stock;
        String runLength,Genre;
        Scanner scanner = new Scanner(System.in);
for (int k = 0; k < dvdcollection.length; k++) {
System.out.println("Input DVD Title " + String.valueOf(k + 1) +
        " of " + String.valueOf(maxItems));
dvdtitle = scanner.nextLine();

System.out.println("Input DVD price " + String.valueOf(k + 1) + " of " +
        String.valueOf(maxItems));
price = Double.parseDouble(  scanner.nextLine());
System.out.println("Input DVD Quantity " + String.valueOf(k + 1) + " of " +
        String.valueOf(maxItems));
stock = Integer.parseInt(scanner.nextLine());
System.out.println("Input DVD Running Time " + String.valueOf(k + 1) + " of " +
        String.valueOf(maxItems));
runLength = scanner.nextLine();
System.out.println("Input DVD Genre " + String.valueOf(k + 1) + " of " +
        String.valueOf(maxItems));
Genre = scanner.nextLine();
dvdcollection[k] = new dvdExt (dvdtitle, stock, price, k + 1,runLength,Genre);
}
} catch (Exception ec) {
System.out.println(ec.getMessage());
System.exit(-1);
}


for (int k = 0; k < maxItems; k++) {
// calculate the total inventory value
totalInventoryValue + = dvdcollection[k].getValue();
totalRestockingFee + = dvdcollection[k].getRestockingfee();

}
System.out.println("Display Inventory");
System.out.println(" ");
for (int k = 0; k < maxItems; k++) {
System.out.println("DVD Title " + dvdcollection[k].getdvdTitle());
System.out.println("DVD Quantity " + String.valueOf
        (dvdcollection[k].getstockQuantity()));
System.out.println("DVD Price " + String.valueOf
        
        (dvdcollection[k].getPrice()));
System.out.println("DVD Item Number " + String.valueOf
        (dvdcollection[k].getitemNumber()));
System.out.println("DVD Running Time " + dvdcollection[k].getRunningLength());
System.out.println("DVD Genre " + dvdcollection[k].getGenre());
System.out.println("DVD's Total Value " + String.valueOf

        (dvdcollection[k].getValue()));
System.out.println("DVD's Restocking Fee " + String.valueOf
        
        (dvdcollection[k].getRestockingfee()));
System.out.println(" ");
}
System.out.println("Inventory Total Value " +String.valueOf(totalInventoryValue));
System.out.println("Inventory Total Value " +String.valueOf(totalRestockingFee));
            }
}
 //end main

// sort by name

private void sort(DVD[] products) {
    //bubble sort
            String n=dvdTitle;
    for (int search = 1; search < n; search++) {
        for (int i = 0; i < n-search; i++) {
            if
        (products[i].getdvdTitle().compareToIgnoreCase(products[i+1].getdvdTitle()) > 0)
            {// swap
                DVD temp = (DVD) products[i];
                products[i] = products[i+1];
                products[i+1] = temp;

            }
        }
    }
}
public int size (int numCDs) {
    return numCDs;
}
    }
// end


//inventory GUI part 4
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JLabel;



           

public void static

 class Inventory4 JFrame {
//access to inventory
        private Inventory theInventory;

//currently displayed product
//index begins at 0, continues to number of product in inventory -1

        private int index = 0;

//GUI to display currently selected product

        private final JLabel itemNoLabel = new JLabel
                ("  Item Number");
        private JTextField itemNoText;

        private final JLabel dvdTitleLabel = new JLabel
                ("  DVD Title");
        private JTextField dvdTitleText;


        private final JLabel itemPriceLabel = new JLabel
                  ("    Item Price");
        private JTextField itemPriceText;



        private final JLabel noinstockLabel = new JLabel
                ("  No. In Stock");
        private JTextField noinstockText;



        private final JLabel valueLabel = new JLabel
                ("  Product Value");
        private JTextField valueText;



        private final JLabel restockingFeeLabel = new JLabel
                ("  Restocking Fee");
        private JTextField restockingFeeText;



        private final JLabel totalValueLabel = new JLabel
                ("  totalvalueLabel");
        private JTextField totalValueText;



            private JPanel centerPanel;
            private JPanel buttonPanel;
            private Object nextbutton;
    private Object itemnoText;
    private Object itempriceText;

   //GUI constructor that creates all GUI elements

            InventoryGUI (Inventory inventory,Inventory theIventory,JButton New) {
            super ("MaDonna's Inventory");
            final Dimension dim = new Dimension (160, 40);
            final FlowLayout flo = new FlowLayout (FlowLayout.LEFT);
            JPanel jp;
 // create object that will store info
    theIventory = inventory;

// create GUI for entering product info and setup panel

    centerPanel = new JPanel ();
    centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
    buttonPanel = new JPanel();

    JButton firstButton = new JButton("First");
    firstButton.addActionListener(new FirstButtonHandler());
    buttonPanel.add(firstButton);

    JButton previousButton = new JButton ("Previous");
    previousButton.addActionListener(new PreviousButtonHandler());
    buttonPanel.add(previousButton);

    JButton nextButton = new JButton("Next");
    nextbutton.addActionListener(new NextButtonHandler());
    buttonPanel.add(nextButton);

    JButton lastButton = new JButton("Add");
    lastButton.addActionListener(new LastButtonHandler());
    buttonPanel.add(lastButton);

    JButton addButton = new JButton("Add");
    addButton.addActionListener(new AddButtonHandler());
    buttonPanel.add(addButton);

    JButton deleteButton = new JButton("Delete");
    deleteButton.addActionListener(new DeleteButtonHandler());
    buttonPanel.add(deleteButton);

    JButton modifyButton = new JButton("Modify");
    modifyButton.addActionListener(new ModifyButtonHandler());
    buttonPanel.add(modifyButton);

    JButton saveButton = new JButton("Save");
    saveButton.addActionListener(new SaveButtonHandler());
    buttonPanel.add(saveButton);

    centerPanel.add(buttonPanel);

    jp = new JPanel (flo);
    itemNoLabel.setPreferredSize(dim);
    jp.add(itemNoLabel);
    itemNoText = new JTextField(3);
    itemNoText.setEditable(false);
    jp.add(itemNoText);
    centerPanel.add(jp);


    jp = new JPanel (flo);
    dvdTitleLabel.setPreferredSize(dim);
    jp.add(dvdTitleLabel);
    dvdTitleLabel = new JTextField(20);
    dvdTitleLabel.setEditable(false);
    jp.add(dvdTitleText);

    centerPanel.add (jp);

    jp = new JPanel(flo);
    itemPriceLabel.setPreferredSize(dim);
    jp.add(itemPriceLabel);
    itemPriceText = new JTextField(20);
    itemPriceText.setEditable(false);
    jp.add(itemPriceText);

    centerPanel.add(jp);

    jp = new JPanel (flo);
    noinstockLabel.setPreferredSize(dim);
    jp.add(noinstockLabel);
    noinstockText = new JTextField (4);
    noinstockText.setEditable(false);
    jp.add(noinstockText);

    centerPanel.add(jp);

    jp = new JPanel (flo);
    restockingFeeLabel.setPreferredSize(dim);
    jp.add(restockingFeeLabel);
    restockingFeeText = new JTextField (20);
    restockingFeeText.setEditable(false);
    jp.add(restockingFeeText);

    centerPanel.add(jp);

    jp = new JPanel(flo);
    valueLabel.setPreferredSize(dim);
    jp.add(valueLabel);
    valueText = new JTextField(20);
    valueText.setEditable(false);
    jp.add(valueText);

    centerPanel.add(jp);

    //add inventory total
    jp = new JPanel (flo);
    totalValueLabel.setPreferredSize(dim);
    jp.add(totalValueLabel);
    totalValueText = new JTextField (20);
    totalValueText.setEditable(false);
    jp.add(totalValueText);

    centerPanel.add(jp);

    //add panel to display

    setContentPane(centerPanel);

    repaintGUI();

    setSize(440, 500);
    setResizable(false);
    setVisible(true);

            }
  //change display to show current product info
   public void repaintGUI() {
       DVD temp = (DVD) theInventory.getDVD(index);
       if (temp !=null) {
           itemnoText.setText("" + temp.getitemNumber());
           dvdTitleText.setText(temp.getdvdTitle());
           itempriceText.setText(String.format("$%.2f",
                        temp.getitemPrice()));
           restockingFeeText.setText(String.format("$%.2f",
                        temp.restockingFee()));
           noinstockText.setText("" + temp.getnoinstock());
           valueText.setText(String.format("$%.2f", temp.value()));
       }
       totalValueText.setText(String.format("$%.2f",
                    theInventory.value()));

   }

    private void setContentPane(JPanel centerPanel) {
        setContentPanel();
    }

    private void setContentPanel() throws UnsupportedOperationException {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void setResizable() throws UnsupportedOperationException {
        throw new UnsupportedOperationException("Not yet implemented");
    }



    private void setResizable(boolean b) {
        setResizable();
    }

    private void setSize() throws UnsupportedOperationException {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void setSize(int i, int i0) {
        throw new UnsupportedOperationException("Not yet implemented");
    }


    }
    private void setSize(int i, int i0) {
        setSize();
    }

    private void setVisible(boolean b) {
        throw new UnsupportedOperationException("Not yet implemented");
    }


   class FirstButtonHandler implements ActionListener {
       public void actionPerformed(ActionEvent a){
           repaintGUI();
       }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
   }

   class PreviousButtonHandler implements ActionListener {
       public void actionPerformed(ActionEvent a) {
           repaintGUI();
       }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
   }
 class NextButtonHandler implements ActionListener {
    private Object theInventory;
    private int index;
     public void actionPerformed(ActionEvent a,int numItems) {
        int numitems = theInventory.getnumItems();
        index = (++index) % numItems;
        repaintGUI();

     }

        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
 }
 class LastButtonHandler implements ActionListener {
    private Object theInventory;
    private int index;
     public void actionPerformed(ActionEvent a){
         int numItems = theInventory.getNumItems();
         index = (numItems -1) % numItems;
         repaintGUI();
     }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
 }
 class AddButtonHandler implements ActionListener {
     public void actionPerformed(ActionEvent a){
         repaintGUI();
     }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
 }
 class ModifyButtonHandler implements ActionListener {
     public void actionPerformed(ActionEvent a) {
         repaintGUI();
     }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
 }
 class SaveButtonHandler implements ActionListener {
     public void actionPerformed(ActionEvent a) {
     repaintGUI();

     }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
 }
class DeleteButtonHandler implements ActionListener {
    public void actinPerformed(ActionEvent a){
        repaintGUI();
    }

        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

    private void repaintGUI() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    }
}

       

    
   
    private void setDefaultCloseOperation(int EXIT_ON_CLOSE) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

 
//End Inventory4 class

(THIS IS IN A SEPERATE FILE CALLED INVENTORY)
class Inventory {

    int getNumItems() {
        int numItems = this.getNumItems();
    }

    int getnumItems() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    Object[] value() {
        value();
    }

    private void value() throws UnsupportedOperationException {
        throw new UnsupportedOperationException("Not yet implemented");

(THIS IS IN A SEPERATE FILE CALLED - REPAINT)

package inventory;

/**
 *
 * @author MaDonna
 */
class repaint {

}

Last edited by Belisarius; 07-08-2009 at 02:35 PM. Reason: Added code tags
ladymoe is offline   Reply With Quote