inventory program part 6

Syntax error on token(s), misplaced construct(s)

Page 1 of 1

8 Replies - 5351 Views - Last Post: 12 March 2008 - 06:07 PM Rate Topic: -----

#1 idgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-February 08

inventory program part 6

Post icon  Posted 11 March 2008 - 01:58 PM

This is what I need to do for this assignment:

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 have the following errors that I do not know how to fix:

Severity and Description Path Resource Location Creation Time Id
Syntax error on token(s), misplaced construct(s) Movies/src/Inventory6a InventoryGUI.java line 29 1205268460031 28509

Severity and Description Path Resource Location Creation Time Id
Syntax error on token(s), misplaced construct(s) Movies/src/Inventory6a InventoryGUI.java line 263 1205268460031 28510

Severity and Description Path Resource Location Creation Time Id
Syntax error on token(s), misplaced construct(s) Movies/src/Inventory6a InventoryGUI.java line 263 1205268460031 28510

Severity and Description Path Resource Location Creation Time Id
The public type ProductModified must be defined in its own file Movies/src/Inventory6a InventoryGUI.java line 726 1205268460031 28512

Could anyone please help me???
Here is my code:
package Inventory6a ;

	import java.awt.BorderLayout;
	import java.awt.Dimension;
	import java.awt.FlowLayout;
	import java.awt.HeadlessException;
	import java.awt.Image;

	import java.awt.event.ActionEvent;
	import java.awt.event.ActionListener;

	import java.io.File;
	import java.io.FileNotFoundException;
	import java.io.FileOutputStream;
	import java.io.IOException;
	import java.io.ObjectOutputStream;
	import java.io.Serializable;

	import javax.swing.ImageIcon;
	import javax.swing.JButton;
	import javax.swing.JFrame;
	import javax.swing.JLabel;
	import javax.swing.JOptionPane;
	import javax.swing.JPanel;
	import javax.swing.JScrollPane;
	import javax.swing.JTextArea;


class InventoryGUI extends JFrame implements ActionListener,Serializable
{ 

	   /**
		 * 
		 */
		private static final long serialVersionUID = 1L;

	private JTextArea textArea;
	   
	   private JButton first,
	                   next,
	                   previous,
	                   last,
	                   add,
	                   modify,
	                   delete,
	                   save,
	                   search,
	                   exit;
	   JLabel imageLabel;
	   
	   private static Inventory Inventory = new Inventory();

	private static Inventory inv;

	   /**
	     * @param arg0
	     * @throws HeadlessException
	     */
	   public InventoryGUI( String arg0 ) throws HeadlessException 
	   {
	      super( "Inventory GUI" );
	      
	      textArea = new JTextArea( 250,30 );

	      JScrollPane scrollPane = new JScrollPane( textArea ); 

	      textArea.setEditable( false );

	      scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );

	      scrollPane.setPreferredSize( new Dimension( 250, 250 ) );

	      JPanel cp = new JPanel();

	      cp.setSize( 250, 40 );

	      cp.setLayout( new BorderLayout() );

	      cp.add( scrollPane,BorderLayout.CENTER );
	      
	      JPanel buttonPaenl = new JPanel();
	      
	      JPanel buttonPaenl1 = new JPanel();

	      first = new JButton( "First" );
	      first.addActionListener( this );
	      
	      search = new JButton( "Search" );
	      search.addActionListener( this );
	      
	      next = new JButton( "Next" );
	      next.addActionListener( this );

	      previous = new JButton( "Previous" );
	      previous.addActionListener( this );

	      last = new JButton( "Last" );
	      last.addActionListener( this );

	      add = new JButton( "Add" );
	      add.addActionListener( this );

	      modify = new JButton( "Modify" );
	      modify.addActionListener( this );
	        
	      delete = new JButton( "Delete" );
	      delete.addActionListener( this );

	      save = new JButton( "Save" );
	      save.addActionListener( this );

	      exit = new JButton( "Exit" );
	      exit.addActionListener( this );
	        
	      buttonPaenl.setLayout( new FlowLayout() );
	      buttonPaenl1.setLayout( new FlowLayout() );
	      buttonPaenl.add( first );
	      buttonPaenl.add( previous );
	      buttonPaenl.add( next );
	      buttonPaenl.add( last );
	      buttonPaenl1.add( add );
	      buttonPaenl1.add( modify );
	      buttonPaenl1.add( delete );
	      buttonPaenl1.add( save );
	      buttonPaenl1.add( search );
	      buttonPaenl1.add( exit );

	      cp.add( buttonPaenl,BorderLayout.SOUTH );
	      cp.add( buttonPaenl1,BorderLayout.NORTH );

	      ImageIcon icon = new ImageIcon( "C:\\data\\logo.gif","a pretty but meaningless splat" );
	      imageLabel = new JLabel( "Xavier", icon, JLabel.CENTER );
	      cp.add( imageLabel,BorderLayout.EAST );
	      this.setContentPane( cp );

	      this.setTitle( " Week Nine Final Project: Inventory Program Part Six - Transformers Autobot Inventory ( More Than Meets the Eye o_0/>?! ) " );

	      this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	      Inventory inv;
		this.textArea.setText(inv.getFirst());
	      this.setSize(400, 400);
	      this.pack();
	      this.setVisible( true );
	   }

	   @Override
	   public void actionPerformed( ActionEvent e ) 
	   {
	      Inventory inv;
		if( e.getActionCommand().equals( "First" ) )
	      {
	         textArea.setText( inv.getFirst() );
	      }
	      
	      if( e.getActionCommand().equals( "Next" ) )
	      {
	         textArea.setText(inv.getNext());
	      }
	        
	      if( e.getActionCommand().equals( "Previous" ) )
	      {
	         textArea.setText( inv.getPrevious() );
	      }
	      
	      if( e.getActionCommand().equals( "Last" ) )
	      {
	         textArea.setText(inv.getLast());
	      }
	      
	      if( e.getActionCommand().equals( "Save" ) )
	      {
	         save();
	      }
	        
	      if( e.getActionCommand().equals( "Exit" ) )
	      {
	         System.exit(0);
	      }
	        
	      if( e.getActionCommand().equals( "Add" ) ) 
	      {
	         InventoryDialogue id = new InventoryDialogue( true," Add a new Inventory " );
	      }
	      
	      if( e.getActionCommand().equals( "Modify" ) )
	      {
	         InventoryDialogue id = new InventoryDialogue( false," Modify Inventory " );
	      }
	      
	      if( e.getActionCommand().equals( "Search" ) )
	      {
	         String s = JOptionPane.showInputDialog( null, " Enter Product Name ",null, 1 );
	         
	         s = inv.Search(s);
	         
	         if( s == null )
	         {
	            JOptionPane.showMessageDialog( this, " No Results Found " );
	         } 
	            
	         else textArea.setText( s );
	            
	         if( e.getActionCommand().equals( "Delete" ) )
	         {
	            inv.getproducts().remove( Inventory6a.Inventory.index );
	            }
	      }
	   }
	   
	   public void save()
	   {
	      File f = new File( "C:\\data\\inventory.dat" );
	      
	      try 
	      {
	         FileOutputStream out = new FileOutputStream( f );
	         
	         try 
	         {
	            ObjectOutputStream objectOut = new ObjectOutputStream( out );
	               Object inv;
				objectOut.writeObject( inv );
	         } 
	         
	         catch (IOException e) 
	         {
	            JOptionPane.showMessageDialog( null, e.getMessage() );
	               e.printStackTrace();
	         }
	      } 
	      
	      catch ( FileNotFoundException e ) 
	      {
	         JOptionPane.showMessageDialog( null, e.getMessage() );
	            e.printStackTrace();
	      }

	   }  

	   public static Inventory getInv() 
	   {
	      return getInv();
	   }

	   public static void setInv( Inventory inv ) 
	   {
	      InventoryGUI.inv = inv;
	   }

	   /**
	    * @param args
	    */
	   public static void main( String[] args ) 
	   {
	      InventoryGUI inventory = new InventoryGUI( "Inventory" );
	   }
	}

	import java.awt.LayoutManager;
	import javax.swing.BoxLayout;
	import javax.swing.JTextField;

class InventoryDialogue extends JFrame implements ActionListener
	{
	   /**
		 * 
		 */
		private static final long serialVersionUID = 1L;

	private boolean status = false; //false is for modify
	   
	   JTextField nameTextField,
	              unitTextField,
	              priceTextField;
	   
	   JLabel nameLabel,
	          unitLabel,
	          priceLabel;
	    
	   JPanel TextFields,
	          buttons;
	   
	   JButton modify, 
	           add;
	    
	   public InventoryDialogue( Boolean stat, String title )
	   {
	      super( title );
	      status = stat;
	      JPanel but = new JPanel();
	      modify = new JButton( "Modify" );
	      modify.addActionListener( this );
	      add = new JButton( "Add" );
	      add.addActionListener( this );
	      but.add( add );
	      but.add( modify );
	      
	      if( status == false )
	      {
	         add.setVisible( false );
	      }
	      
	      else
	      {
	         modify.setVisible( false );
	      }
	      
	      nameTextField = new JTextField( "", 20 );
	      unitTextField = new JTextField( "", 5 );
	      priceTextField = new JTextField( "" , 5 );
	      nameLabel = new JLabel( "Name" );
	      unitLabel = new JLabel( "Units" );
	      priceLabel = new JLabel( "Price per Unit" );
	      JPanel p = new JPanel();

	      p.setLayout( new FlowLayout() );
	      p.add( nameLabel );
	      p.add( nameTextField );
	      p.add( unitLabel );
	      p.add( unitTextField );
	      p.add( priceLabel );
	      p.add( priceTextField );
	      JPanel cp = new JPanel();
	      cp.setLayout( new BorderLayout() );
	      cp.add( p, BorderLayout.CENTER );
	      cp.add( but, BorderLayout.EAST );
	      this.setContentPane( cp );
	      this.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
	      this.pack();
	      this.setVisible( true );
	   }

	   public void actionPerformed( ActionEvent arg0, Object nventory ) 
	   {
	      if( arg0.getActionCommand().equals( "Add" ) )
	      {
	         String name;
	         int units;
	         Double price;
	         name = nameTextField.getText();
	      
	         try 
	         {
	            units = Integer.parseInt( unitTextField.getText() );
	         } 
	      
	         catch ( NumberFormatException e ) 
	         {
	            JOptionPane.showMessageDialog( null, e.getMessage() );
	         
	            e.printStackTrace();
	         
	            return;
	         }
	      
	         try 
	         {
	            price = Double.parseDouble( priceTextField.getText() );
	         } 
	      
	         catch ( NumberFormatException e ) 
	         {
	            JOptionPane.showMessageDialog( null, e.getMessage() );

	            e.printStackTrace();
	         
	            return;
	         }
	            
	         InventoryGUI.getInv().getproducts().add( new ProductModified( name, InventoryGUI.getInv().products.size(), 
	                                                                       units,price ) );
	      
	         this.dispose();
	      }

	      if( arg0.getActionCommand().equals( "Modify" ) )
	      {
	         String name;
	         int units;
	         Double price;
	         name = nameTextField.getText();
	      
	         try 
	         {
	            units = Integer.parseInt( unitTextField.getText() );
	         } 
	      
	         catch ( NumberFormatException e ) 
	         {
	            JOptionPane.showMessageDialog( null,"Please Enter Valid Integers" );
	         
	            e.printStackTrace();
	         
	            return;
	         }
	            
	         try 
	         {
	            price = Double.parseDouble( priceTextField.getText() );
	         } 
	      
	         catch ( NumberFormatException e ) 
	         {
	            JOptionPane.showMessageDialog( null,"Please Enter Valid Price" );

	            //e.printStackTrace();
	            return;
	         }
	           
	         ProductModified set = InventoryGUI.getInv().getproducts().get( Inventory.index );
	            
	         this.dispose();
	      }
	   }
	   
	   public static void main( String args[] )
	   {
	      InventoryDialogue idf = new InventoryDialogue( true,"cc" );
	   }

	@Override
	public void actionPerformed(ActionEvent e) {
		
	}
	}
	

	import java.text.Collator;
	import java.util.ArrayList;
	import java.util.Iterator;
	import java.util.Locale;
class Inventory 
{
	   private String inventoryName; // name of inventory
	   
	   public String restockRate; // restock rate percentage
	   
	   public double totalRestock;

	   public static int index;

	   public ArrayList < ProductModified > products = new ArrayList < ProductModified > ();

	   public Inventory()
	   {
	      products.add( new ProductModified( "No Sale Bot", 0, 1, 0.00 ) );
	      products.add( new ProductModified( "Optimus Prime", 7, 52, 160.00 ) );
	      products.add( new ProductModified( "BumbleeBee", 16, 61, 97.00 ) );
	      products.add( new ProductModified( "Ironhide", 25, 106, 88.00 ) );
	      products.add( new ProductModified( "Ratchet", 34, 125, 79.00 ) );
	      products.add( new ProductModified( "Jazz", 0, 124, 70.00 ) );
	      
	      index = 0;
	   }
	    
	   public void sort()
	   {
	      Locale loc = Locale.ENGLISH;
	       
	      ProductModified Temp;
	       
	      Collator col = Collator.getInstance( loc );
	       
	      for ( int i = 0; i < products.size(); i++ ) 
	      {
	         for ( int j = i + 1; j < products.size(); j++ )
	         {
	            if( col.compare( products.get( i ).getAutobotName(), products.get( j ).getAutobotName() ) > 0 )
	            {
	               Temp = products.get( i );
	                
	               products.set( i, products.get( j ) );
	               products.set( j, Temp );
	            }
	         }
	      }
	   }
	    
	   public String getInventoryName() 
	   {
	      return inventoryName;
	   }
	    
	    public void setInventoryName( String inventoryName ) 
	    {
	       this.inventoryName = inventoryName;
	    }
	    
	    public String getRestockRate() 
	    {
	       return restockRate;
	    }
	    
	    public void setRestockRate( String restockRate ) 
	    {
	       this.restockRate = restockRate;
	    }
	    
	    public double getTotalRestock() 
	    {
	       return totalRestock;
	    }
	    
	    public void setTotalRestock( double totalRestock ) 
	    {
	       this.totalRestock = totalRestock;
	    }
	    
	    public ArrayList < ProductModified > getproducts() 
	    {
	       return products;
	    }
	    
	    public void seproducts( ArrayList < ProductModified > products) 
	    {
	       this.products = products;
	    }
	    
	    public String toString()
	    {
	       String transformersSub = new String(" ");

	       transformersSub = "Welcome to the\n" + getInventoryName() + "!\n\n";

	       transformersSub = transformersSub + "Below is the available inventory:\n\n";

	       transformersSub = transformersSub + "The restock interest rate is at " + getRestockRate() + ".\n\n";

	       transformersSub = transformersSub + "Index\tProductModified #\t\t\tName\t\tUnits\t\tPrice\t\t";

	       transformersSub = transformersSub + "Unit Restock Value\t";    

	       transformersSub = transformersSub + "Stock Value\t\t";

	       transformersSub = transformersSub + "Total ProductModified Restock\n";
	       
	       Iterator < ProductModified > i = this.getproducts().iterator();
	       
	       while(i.hasNext())
	       {
	          transformersSub = transformersSub + i.next();
	       }
	       
	      return transformersSub;
	   }
	   
	   public Double getTotal()
	   {
	      Double Total = 0.0;
	      
	      ProductModified p;
	      
	      Iterator < ProductModified > i = products.iterator();
	      
	      while( i.hasNext() )
	      {
	            p = i.next();
	            
	            Total = Total + p.getPrice() * p.getUnit();
	      }
	      
	      return Total;
	   }

	   public String processOutPut( ProductModified p )
	   {
	      String out = "Welcome to the Transformers Autobot Toy Inventory\n\nTotal Inventory = " 
	      + this.getTotal() + "\nRestocking Fee = 5%" 
	      + "\n\nItem #\tName\tUnit\tPrice\tUnit Restock Value" 
	      + p;
	      
	      return out;
	   }
	   
	   public String getFirst()
	   {
	      index = 0;
	      
	      return processOutPut( products.get(0) );
	    
	   }
	   
	   public String getLast()
	   {
	      index = products.size() - 1;
	      
	      return processOutPut( products.get( products.size() - 1 ) );
	   }
	    
	   public String getNext()
	   {
	      if( index == products.size() - 1 ) 
	      {
	         getFirst();
	          
	         return getFirst();
	      } 
	      
	      else
	      {
	         index++;
	         
	         return processOutPut( products.get( index ) );
	      }
	   }
	   
	   public String getPrevious()
	   {
	      if( index == 0 )
	      {
	         return getLast();
	      } 
	      
	      else
	            
	      return processOutPut(products.get(--index));
	   }
	   
	   public String Search( String Search )
	   {
	      Iterator < ProductModified > i = products.iterator();
	   
	      String te = null;
	   
	      ProductModified p;
	      
	      while( i.hasNext() )
	      {
	         p = i.next();
	      
	         if( p.getAutobotName().equals( Search ) )
	         {
	            te = processOutPut( p );
	         }
	      }
	      
	      return te;
	   }
	}

import static java.lang.System.out;


	//class declaration for TransformersProduct
	 class Product
	{
	   public String autobotName; // array of autobot toy names
	   public int productNumber; // product # array ID for product
	   public int unit; // array of autobot toy units
	   public double price; // array of autobot prices
	   public double inventoryValue;
	    
	   /**
	    * @param autobotName
	    * @param productNumber
	    * @param unit           
	    * @param price
	    */
	   
	   public Product( String autobotName, int productNumber, int unit,
	                   double price ) 
	   {
	      super();
	      this.autobotName = autobotName;
	      this.productNumber = productNumber;
	      this.unit = unit;
	      this.price = price;
	   }

	   public String getAutobotName() 
	   {
	      return autobotName;
	   }
	   
	   public void setAutobotName( String autobotName ) 
	   {
	      this.autobotName = autobotName;
	   }

	   public int getProductNumber() 
	   {
	      return productNumber;
	   }
	    
	   public void setProductNumber( int productNumber ) 
	   {
	      this.productNumber = productNumber;
	   }
	   
	   public int getUnit() 
	   {
	      return unit;
	   }
	   
	   public void setUnit( int unit ) 
	   {
	      this.unit = unit;
	   }
	   
	   public double getPrice() 
	   {
	      return price;
	   }
	   
	   public void setPrice( double price ) 
	   {
	      this.price = price;
	   }
	    
	   public double getInventoryValue() 
	   {
	      return inventoryValue;
	   }
	    
	   public Double inventoryValue()
	   {
	      return this.getPrice() * this.getUnit();
	   }
	   
	   public String toString()
	   {
	      return "\n"+this.productNumber+"\t"+this.autobotName+"\t"+this.unit +"\t"+this.price+ "\t"; 
	   }
	}

	    public class ProductModified extends Product 
	{
	   public ProductModified( String autobotName, int productNumber, int unit,
	                           double price ) 
	   {
	      super( autobotName, productNumber, unit, price );
	      this.inventoryValue = this.inventoryValue();   

	   }
	    
	   public Double inventoryValue()
	   {
	      return this.getUnit() * this.getPrice() + this.getUnit() * this.getPrice() * 0.05;
	   }
	   
	   public String toString()
	   {
	      return "\n" + this.productNumber + "\t" + this.autobotName 
	                  + "\t" + this.unit + "\t" + this.price + "\t" 
	                  + this.getInventoryValue(); 
	   }
	}


*1lacca: added code tags

Is This A Good Question/Topic? 0
  • +

Replies To: inventory program part 6

#2 idgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-February 08

Re: inventory program part 6

Posted 12 March 2008 - 12:24 PM

Syntax error on token(s), misplaced construct(s)

This is my major problem in my code. Like 3 of them. I still cannot fix it, I do not understand what I am doing wrong.
Was This Post Helpful? 0
  • +
  • -

#3 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: inventory program part 6

Posted 12 March 2008 - 12:45 PM

If I place all the classes in separate files, I receive the following errors:

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#4 idgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-February 08

Re: inventory program part 6

Posted 12 March 2008 - 01:48 PM

View Postletthecolorsrumble, on 12 Mar, 2008 - 12:45 PM, said:

If I place all the classes in separate files, I receive the following errors:



ok, so what does that mean... should I go back and redo all my code or what I really am at a loss here! Thank you for helping me!
Was This Post Helpful? 0
  • +
  • -

#5 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: inventory program part 6

Posted 12 March 2008 - 01:50 PM

You do not need to do it all over again, just need to get rid of the errors one-by-one and then perhaps the program will just do what you want it to do. :)
Was This Post Helpful? 0
  • +
  • -

#6 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: inventory program part 6

Posted 12 March 2008 - 02:27 PM

Well Well, what do you know ? :) I made some changes and it worked, not all of it but most of it seems to work...

Happy further Coding :)

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#7 idgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-February 08

Re: inventory program part 6

Posted 12 March 2008 - 04:30 PM

View Postletthecolorsrumble, on 12 Mar, 2008 - 02:27 PM, said:

Well Well, what do you know ? :) I made some changes and it worked, not all of it but most of it seems to work...

Happy further Coding :)



thank you I have it really messed up now! I cannot get it to open from the zip file. I unzipped it but Eclipse did not pick it up!
Was This Post Helpful? 0
  • +
  • -

#8 idgirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-February 08

Re: inventory program part 6

Posted 12 March 2008 - 05:45 PM

thank you I have it really messed up now! I cannot get it to open from the zip file. I unzipped it but Eclipse did not pick it up!
[/quote]


ok I think I have it done to this error on line 400:

Severity and Description Path Resource Location Creation Time Id
Implicit super constructor Product() is undefined. Must explicitly invoke another constructor Movies/src/Inventory6a inventory6.java line 400 1205368170218 39181

package Inventory6a;

	import java.util.*;

	import javax.swing.*;

import Inventory.Product1;

	import java.awt.*;
	import java.awt.event.*;
import java.text.NumberFormat;

	// GUI for the Inventory
	// Contains an inventory of DVDs that lets the user step through them one by one
	class InventoryGUI extends JFrame 
	{
		
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		// create inventory for the DVD
		private Inventory theInventory;
		
		// index in the inventory of the currently displayed DVD.
		// the index starts at 0, goes to the number of DVD in the inventory minus 1
		private int index = 0;
		
		// GUI elements to display currently selected DVD's information
		private JLabel itemNumberLabel = new JLabel("Product Number: ");
		private JTextField itemNumberText;
		
		private JLabel produdctNameLabel = new JLabel("Title: ");
		private JTextField prodnameText;
		
		private JLabel genreLabel = new JLabel("Genre: ");
		private JTextField genreText;
		
		private JLabel numinstockLabel = new JLabel("Number in Stock: ");
		private JTextField numinstockText;
		
		private JLabel productPriceLabel = new JLabel("Product Price: ");
		private JTextField productPriceText;
		
		private JLabel restockingFeeLabel = new JLabel("Restocking Fee: ");
		private JTextField restockingFeeText;
		
		private JLabel valueLabel = new JLabel("Inventory Value: ");
		private JTextField valueText;
		
		private JLabel totalValueLabel = new JLabel("Total Inventory Value: ");
		private JLabel totalValueText;
		
		// load up the logo into a component for the GUI
		private JLabel logoLabel = new JLabel();
		
		// setup the buttons in the GUI
		// go to the previous product in the list
		private Action previousAction  = new AbstractAction("Previous") 
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				// if we're at the front of the list, then go to the last element
				if ( index == 0 ) {
					lastAction.actionPerformed(null);
				} else {
					// otherwise, just go backward one product
					index--;
				}
				
				repaint();
			}
		};
		private JButton previousButton = new JButton(previousAction);
		
		// go to the next product in the list
		private Action nextAction  = new AbstractAction("Next") 
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				// if we're at the end of the list, then go to the first element
				if ( index == theInventory.getSize() - 1 ) {
					firstAction.actionPerformed(null);
				} else {
					// otherwise, just go forward one product
					index++;
				}
				
				repaint();
			}
		};
		private JButton nextButton = new JButton(nextAction);

		// go to the first product in the list
		private Action firstAction  = new AbstractAction("First") 
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				index = 0;

				repaint();
			}
		};
		private JButton firstButton = new JButton(firstAction);

		// go to the last product in the list
		private Action lastAction  = new AbstractAction("Last") 
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent evt) {
				index = theInventory.getSize() - 1;
				repaint();
			}
		};
		private JButton lastButton = new JButton(lastAction);
		
		
		// Add the product to the underlying inventory object
		public void addDVDToInventory(DVD temp)
		{
			theInventory.addDVD(temp);
			sortInventory();
			repaint();
		} 
		
		// sort the items in the underlying inventory object
		public void sortInventory()
		{
			theInventory.sortInventory();
			repaint();
		}
		
		// constructor for the GUI, in charge of creating all GUI elements
		public InventoryGUI()
		{
			// create the inventory object that will hold the product information
			theInventory = new Inventory();
			
			// setup the GUI
			// add the next button to the top of the GUI
			// setup a panel to collect all the buttons in a FlowLayout
			JPanel buttonPanel = new JPanel();
			buttonPanel.add(nextButton);
			buttonPanel.add(previousButton);
			buttonPanel.add(firstButton);
			buttonPanel.add(lastButton);
			getContentPane().add(buttonPanel, BorderLayout.NORTH);
			
			// product information
			// setup a panel to collect all the components.
			JPanel centerPanel = new JPanel(new GridLayout(8, 2, 0, 4));
			
			centerPanel.add(itemNumberLabel);
			itemNumberText = new JTextField("");
			itemNumberText.setEditable(false);
			centerPanel.add(itemNumberText);
			
			centerPanel.add(produdctNameLabel);
			prodnameText = new JTextField("");
			prodnameText.setEditable(false);
			centerPanel.add(prodnameText);
			
			centerPanel.add(genreLabel);
			genreText = new JTextField("");
			genreText.setEditable(false);
			centerPanel.add(genreText);
			
			centerPanel.add(numinstockLabel);
			numinstockText = new JTextField("");
			numinstockText.setEditable(false);
			centerPanel.add(numinstockText);
			
			centerPanel.add(productPriceLabel);
			productPriceText = new JTextField("");
			productPriceText.setEditable(false);
			centerPanel.add(productPriceText);
			
			centerPanel.add(restockingFeeLabel);
			restockingFeeText = new JTextField("");
			restockingFeeText.setEditable(false);
			centerPanel.add(restockingFeeText);
			
			centerPanel.add(valueLabel);
			valueText = new JTextField("");
			valueText.setEditable(false);
			centerPanel.add(valueText);
			
			// add the overall inventory information to the panel
			centerPanel.add(totalValueLabel);
			totalValueText = new JLabel("");
			centerPanel.add(totalValueText);
			
			// add the panel to the center of the GUI's window
			getContentPane().add(centerPanel, BorderLayout.CENTER);
			

			getContentPane().add(logoLabel, BorderLayout.WEST);
			
		}

		// Get the GUI to show up on the screen
		public void showGUI() {
			this.setDefaultCloseOperation( EXIT_ON_CLOSE );
			this.pack();
			this.setResizable(true);
			this.setLocationRelativeTo( null );
			this.setVisible(true);

			repaint();
		}
		
		// repaint the GUI with current product's information
		public void repaint() {
			
			DVD temp = theInventory.getDVD(index);
			
			if (temp != null) {

				itemNumberText.setText( ""+temp.getItemNumber() );
				
				prodnameText.setText( temp.getItemNumber() );
				genreText.setText( temp.getGenre() );
				productPriceText.setText( String.format("$%.2f", temp.getItemPrice()) );
				restockingFeeText.setText( String.format("$%.2f", temp.getRestockingFee()) );
				numinstockText.setText( ""+temp.getItemsInStock() );
				
				valueText.setText( String.format("$%.2f", temp.getInventoryValue() ) );
				
			}
			
			totalValueText.setText( String.format("$%.2f", theInventory.getTotalValueOfAllInventory() ) );
			
		}
		
	}  // End InventoryGUI class

	/*
	 * class which reprsents a collection of DVDs in an inventory.
	 */
	class Inventory
	{
		public static Component index;
		// place to store all the DVDs in the inventory
		DVD[] inventory;
		
		// create an inventory capable of holding different DVDs
		public Inventory( )
		{
			inventory = new DVD[0];
		}

		// add the DVDs to the end of the inventory
		public void addDVD(DVD new_DVD)
		{
			// create a new array of DVDs that can hold one more than the current array of DVDs
			DVD[] new_inventory = new DVD[this.getSize() + 1];

			//copy all the old ones to the front of the new array
			for (int i = 0; i < this.getSize(); i++) {
				new_inventory[i] = inventory[i];
			}
			
			// add the new DVD to the end of the new array
			new_inventory[this.getSize()] = new_DVD;
			
			// replace the old inventory with the new one
			inventory = new_inventory;
			
		}
		// return the DVDs at the location index in the inventory 
		public DVD getDVD(int index)
		{
			return inventory[index];
		}
		
		// return the number of DVDs in the inventory
		public int getSize()
		{
			return inventory.length;
		}
			
		// run through all the DVDs in the inventory, and add up their value.
		// this includes the restocking fee
		public double getTotalValueOfAllInventory()
		{
			double tot = 0.00;
			
			for(int i = 0; i < getSize(); i++)
			{
				tot += inventory[i].getInventoryValue();
			}
			return tot;
		}

		// sort the DVDs in the inventory by movie title 
		public void sortInventory() 
		{
			Arrays.sort(inventory, 0, getSize()); 
		}
	

	//Class Product

	
		String itemNumber; //stores item number
		String name; //stores the CD's name
		int stockQuantity; //stores number of units in stock
		double priceperunit; //stores the price of each unit
		
		//Constructor method
		public void Product(String Item_Number, String Item_Name, int Items_in_Stock, double Item_Price){
			itemNumber = Item_Number;
			name = Item_Name;
			stockQuantity = Items_in_Stock;
			priceperunit = Item_Price;
		}
		
		public void setItemName(String Item_Name) //Method to set and get the item name
		{
			name = Item_Name;
		}
		
		public String getItemName() {
			return name;
		}
		
		public void setItemNumber(String Item_Number) //Method to set and get the item number
		{
			itemNumber = Item_Number;
		}
		
		public String getItemNumber(){
			return itemNumber;
		}
		
		public void setItemsInStock(int Items_in_Stock) //Method to set and get the quantity in stock
		{
			stockQuantity = Items_in_Stock;
		}
		
		public int getItemsInStock(){
			return stockQuantity;
		}
		
		public void setItemPrice(double Item_Price) //Method to set and get the item price
		{
			priceperunit = Item_Price;
		}
		
		public double getItemPrice(){
			return priceperunit;
		}
		
		public double getInventoryValue() //Method to calculate the value of the in stock inventory
		{
			return priceperunit * stockQuantity;
		}
		
		// returns -1, 0, or 1 depending on if the compared to object should appear before, the same, or after the current item
		public int compareTo (Product1 p) 
		{
			return name.compareTo(p.getItemNumber()); 
		}
		
		public String toString() {
			//Return the product details as a string
			return "Product Number: "+this.getItemNumber() + "\n" +
			"Product Name: "+this.getItemName() + "\n" + 
			"Number of Product items in stock: "+this.getItemsInStock() + "\n" + 
			"Product price: "+NumberFormat.getCurrencyInstance(Locale.US).format(this.getItemPrice()) + "\n" + 
			"Inventory Value: "+NumberFormat.getCurrencyInstance(Locale.US).format(this.getInventoryValue()) + "\n";
		}
	} // end Product Class


	class DVD extends Product {
		// Genre of the DVD being added
		private String DVDGenre;
		// Re-stock fee to add to inventory value
		private double restockingFee;
		
		// initialize Product constructor
		public DVD(String DVDTitle, String DVDGenre, String i,int Items_in_Stock, double Item_Price) {

			

			this.DVDGenre = DVDGenre;
			
			// the default restocking fee is 5%
			this.restockingFee = 0.05;
		}
	

		public String getItemsInStock() {
			return null;
		}


		public Object getItemPrice() {
			return null;
		}


		public String getItemNumber() {
			return null;
		}


		// getter and setter for the DVD's genre
		public void setGenre(String DVDGenre)
		{
			this.DVDGenre = DVDGenre;
		}
		public String getGenre()
		{
			return DVDGenre;
		}
		

		// calculates the re-stocking fee of the DVDs based on a percentage of the value
		public double getRestockingFee() // Figures restocking fee of inventory
		{
			return super.getInventoryValue() * restockingFee;
		}
		
		// include a restocking fee in the inventory's value
		public double getInventoryValue() // Figures total inventory value including restocking fee
		{
			return  super.getInventoryValue() + getRestockingFee();
		}

		// returns a string representation of the item
		public String toString() {
			//Return the product details as a string
			return "Product Number: "+this.getItemNumber() + "\n" +
			"Product Name: "+this.getItemNumber() + "\n" + 
			"Product Genre			: "  + DVDGenre			+ "\n" + 
			"Number of Product items in stock: "+this.getItemsInStock() + "\n" + 
			"Product price: "+NumberFormat.getCurrencyInstance(Locale.US).format(this.getItemPrice()) + "\n" + 
			"Restocking Fee   : "  + NumberFormat.getCurrencyInstance(Locale.US).format(getRestockingFee()) + "\n" + 
			"Inventory Value: "+NumberFormat.getCurrencyInstance(Locale.US).format(this.getInventoryValue()) + "\n";
		}

		public Object getTitle() {
			return null;
		}

		public String getTitle11() {
			return null;
		}

		public long getUnits() {
			return 0;
		}

		

		public String getTitle1() {
			return null;
		}

		public double getSum() {
			return 0;
		}

		public double totalAllInventory(DVD[] productDVD) {
			return 0;
		}

		public String getCode() {
			return null;
		}

	}// end DVD

	class Inventory6 {
		
		public static void main(String [] args) //main() method
		{
			
			//Instantiate a GUI Inventory object
			InventoryGUI theInventoryGUI = new InventoryGUI();
			
			//Create new DVD objects and add them to the inventory
			DVD theDVD = new DVD("Grumpy Old Men", "Comedy", "1", 1, 17.00);
			theInventoryGUI.addDVDToInventory(theDVD);

			theDVD = new DVD("Grumpier Old Men", "Comedy", "2", 1, 17.00);
			theInventoryGUI.addDVDToInventory(theDVD);

			theDVD = new DVD("Pretty Woman", "Comedy", "3", 1, 19.95);
			theInventoryGUI.addDVDToInventory(theDVD);

			theDVD = new DVD("Goast", "Drama", "4", 1, 19.95);
			theInventoryGUI.addDVDToInventory(theDVD);
							
			// sort the DVDs by name
			theInventoryGUI.sortInventory();
			
			// Display the inventory of DVD on the screen, one DVD at a time
			theInventoryGUI.showGUI();
			
		}//end of main() method
		
	}//end of Inventory5 class


any ideas?
Was This Post Helpful? 0
  • +
  • -

#9 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: inventory program part 6

Posted 12 March 2008 - 06:07 PM

Check your Product Class... You haven't mentioned the header of the class and the constructor of any class does not have a return type not even void. You have mentioned void for the Product constructor
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1