My assignment requires that I use exception handling to create a directory and file if necessary.

I was able to create a C:data\inventory.dat file, provided that there's an existing Data folder (directory) in my C: drive; however, I have a feeling that the assignment wants me to create an actual Data folder if one is not available. When I remove the Data folder from my C: drive, I get "C:\data\inventory.dat (The system cannot find the path specified)".

How am I to create able a folder that currently does not exist? I'm reading the java.sun website on the File class, the mkdirs methods, and the FileSystemView class; however, I'm having trouble implementing the requirements in my code (I wish API documentation was more understandable to me.). Can an example be provided? Thank you everyone; below is my code.

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;


public class InventoryGUI extends JFrame implements ActionListener,Serializable 
{
   private JTextArea textArea;
   
   private JButton first,
                   next,
                   previous,
                   last,
                   add,
                   modify,
                   delete,
                   save,
                   search,
                   exit;
   
   JLabel imageLabel;
   
   private static Inventory inv = new Inventory();

   /**
	 * @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( "logo.gif" );
	  imageLabel = new JLabel( 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 );
      this.textArea.setText(inv.getFirst());
      this.setSize(400, 400);
	  this.pack();
	  this.setVisible( true );
   }

   @Override
   public void actionPerformed( ActionEvent e ) 
   {
      // TODO Auto-generated method stub
      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( inv.index );
	  }
      
   }
   
   public void save()
   {            
      File f = new File( "C:\\data\\inventory.dat" );
      
      try 
      {  
	     FileOutputStream out = new FileOutputStream( f );
		 
		 try 
		 {
		    ObjectOutputStream objectOut = new ObjectOutputStream( out );
			   objectOut.writeObject( inv );
		 } 
		 
		 catch (IOException e) 
		 {
		    // TODO Auto-generated catch block
			JOptionPane.showMessageDialog( null, e.getMessage() );
			   e.printStackTrace();
		 }
      } 
      
      catch ( FileNotFoundException e ) 
      {
	     // TODO Auto-generated catch block
	     JOptionPane.showMessageDialog( null, e.getMessage() );
		    e.printStackTrace();
	  }

   }  

   public static Inventory getInv() 
   {
      return inv;
   }

   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.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class InventoryDialogue extends JFrame implements ActionListener
{
   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 );
   }

   @Override
   public void actionPerformed( ActionEvent arg0 ) 
   {
      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 ) 
         {
	        // TODO Auto-generated catch block
	        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 ) 
         {
            // TODO Auto-generated catch block
		    JOptionPane.showMessageDialog( null,"Please Enter Valid Price" );

		    //e.printStackTrace();
		    return;
         }
			
         InventoryGUI.getInv().getproducts().set( InventoryGUI.getInv().index, 
            new ProductModified( name, InventoryGUI.getInv().index, units, price ) );
			
	     this.dispose();
      }

   }
   
   public static void main( String args[] )
   {
      InventoryDialogue idf = new InventoryDialogue( true,"cc" );
   }
}
import java.text.Collator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.io.Serializable;

public class Inventory implements Serializable
{
   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;
import java.io.Serializable;

//class declaration for TransformersProduct
public class Product implements Serializable
{
   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"; 
   }
}
import java.io.Serializable;

public class ProductModified extends Product implements Serializable
{
   public ProductModified( String autobotName, int productNumber, int unit,
			               double price ) 
   {
      super( autobotName, productNumber, unit, price );
	  this.inventoryValue = this.inventoryValue();
	  // TODO Auto-generated constructor stub
   }
	
   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(); 
   }
}

Maybe something like this:

public class DirTest
{
    public static final String PATH = "c:/DELETE_THIS";

    public static final String NAME = "inventory.dat";

    public static void main(String[] args)
    {
        try
        {
            File base = new File(PATH);
            if (!(base.exists() && base.isDirectory()))
                if (!base.mkdir())
                    throw new IOException("Directory creation failed");
            File file = new File(base, NAME);
            BufferedWriter buf = new BufferedWriter(new FileWriter(file));
            try
            {
                buf.write("Hello world");
            }
            finally
            {
                if (buf != null)
                    buf.close();
            }
        }
        catch (IOException e)
        {
            System.out.println(e);
            System.exit(1);
        }
    }
}

File.mkdir() or File.mkdirs() is what you need to use.

edit: s.o.s. beat me to the post :) The only issue there is that it is not using exception handling to create the directory. Personally, I think that is the better way to do it, but his assignment requires it to be done by handling the exception.

Just catch the exception from the FileOutputStream, create the directory, and then try to create the stream again. Outside of that assignment though, I'd say use the way that s.o.s. posted above. It's much cleaner to check for the existence of the directory prior to trying to use it. The catch block approach breaks the flow of your code because its not reentrant from where the exception occurred.

Thanks for all of your help and examples. I managed to get that working. I do have one last problem. My sorter is not working. I managed to sort by product name in my previous assignment; however, I can't get it to work on this one. I changed things around so much in the program that I'm lost on how to get it going again. I also blocked that part of the code off with delimiters; I didn't want it to interfere with program

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;


public class TransformersGUIMainExecution extends JFrame implements ActionListener,Serializable 
{
   private JTextArea textArea;
   
   private JButton first,
                   next,
                   previous,
                   last,
                   add,
                   modify,
                   delete,
                   save,
                   search,
                   exit;
   
   JLabel imageLabel;
   
   private static TransformersInventoryInfo inv = new TransformersInventoryInfo();

   /**
	 * @param arg0
	 * @throws HeadlessException
	 */
   public TransformersGUIMainExecution( 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( "AutobotCompanyLogo.jpg" );
	  imageLabel = new JLabel( 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 );
      this.textArea.setText(inv.getFirst());
      this.setSize(400, 400);
	  this.pack();
	  this.setVisible( true );
   }

   @Override
   public void actionPerformed( ActionEvent e ) 
   {
      // TODO Auto-generated method stub
      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" ) ) 
	  {
	     TransformersInventoryDialogue id = new TransformersInventoryDialogue( true," Add a new Inventory " );
	  }
	  
	  if( e.getActionCommand().equals( "Modify" ) )
	  {
	     TransformersInventoryDialogue id = new TransformersInventoryDialogue( 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( inv.index );
	  }
      
   }
   
   public void save()
   {            
      // Initialize object
      String filepath = "C:/data";
      
      File myDir = new File( filepath );

      // Check if directory exists
      if( !myDir.exists( ) )
      {
         try
         {
            if( !myDir.mkdirs( ) )
            {
               // Could not create folder(s), so end execution here
            }
         }
         catch( SecurityException e )
         {
            // Error handling here
         }
      }      
      
      
      File f = new File( "C:\\data\\inventory.dat" );
      
      try 
      {  
	     FileOutputStream out = new FileOutputStream( f );
		 
		 try 
		 {
		    ObjectOutputStream objectOut = new ObjectOutputStream( out );
			   objectOut.writeObject( inv );
		 } 
		 
		 catch (IOException e) 
		 {
		    // TODO Auto-generated catch block
			JOptionPane.showMessageDialog( null, e.getMessage() );
			   e.printStackTrace();
		 }
      } 
      
      catch ( FileNotFoundException e ) 
      {
	     // TODO Auto-generated catch block
	     JOptionPane.showMessageDialog( null, e.getMessage() );
		    e.printStackTrace();
	  }

   }  

   public static TransformersInventoryInfo getInv() 
   {
      return inv;
   }

   public static void setInv( TransformersInventoryInfo inv ) 
   {
      TransformersGUIMainExecution.inv = inv;
   }

   /**
	* @param args
	*/
   public static void main( String[] args ) 
   {
      TransformersGUIMainExecution TransformersInventoryInfo = new TransformersGUIMainExecution( "Inventory" );
   }
}
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class TransformersInventoryDialogue extends JFrame implements ActionListener
{
   private boolean status = false; //false is for modify
   
   JTextField nameTextField,
              unitTextField,
              priceTextField;
   
   JLabel nameLabel,
          unitLabel,
          priceLabel;
	
   JPanel TextFields,
          buttons;
   
   JButton modify, 
           add;
	
   public TransformersInventoryDialogue( 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 );
   }

   @Override
   public void actionPerformed( ActionEvent arg0 ) 
   {
      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, "Please Enter Valid Integers" );
		 
		    e.printStackTrace();
	     
	        return;
         }
	  
	     try 
	     {
            price = Double.parseDouble( priceTextField.getText() );
         } 
      
         catch ( NumberFormatException e ) 
         {
	        // TODO Auto-generated catch block
	        JOptionPane.showMessageDialog( null, "Please Enter Valid Price" );

            e.printStackTrace();
         
            return;
         }
			
         TransformersGUIMainExecution.getInv().getproducts().add( new TransformersSubProduct( name, TransformersGUIMainExecution.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 ) 
         {
            // TODO Auto-generated catch block
		    JOptionPane.showMessageDialog( null,"Please Enter Valid Price" );

		    //e.printStackTrace();
		    return;
         }
			
         TransformersGUIMainExecution.getInv().getproducts().set( TransformersGUIMainExecution.getInv().index, 
            new TransformersSubProduct( name, TransformersGUIMainExecution.getInv().index, units, price ) );
			
	     this.dispose();
      }

   }
   
   public static void main( String args[] )
   {
      TransformersInventoryDialogue idf = new TransformersInventoryDialogue( true,"cc" );
   }
}
import java.text.Collator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.io.Serializable;

public class TransformersInventoryInfo implements Serializable
{
   //private String inventoryName; // name of inventory
   
   //public String restockRate; // restock rate percentage
   
   //public double totalRestock;

   public static int index;

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

   public TransformersInventoryInfo()
   {
      products.add( new TransformersSubProduct( "No Sale Bot",    0,   1,   0.00 ) );
      products.add( new TransformersSubProduct( "Optimus Prime",  7,  52, 160.00 ) );
      products.add( new TransformersSubProduct( "BumbleeBee",    16,  61,  97.00 ) );
      products.add( new TransformersSubProduct( "Ironhide",      25, 106,  88.00 ) );
      products.add( new TransformersSubProduct( "Ratchet",       34, 115,  79.00 ) );
	  products.add( new TransformersSubProduct( "Jazz",          43, 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 < TransformersSubProduct > getproducts() 
	{
	   return products;
	}
	
	public void seproducts( ArrayList < TransformersSubProduct > 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.00;
	  
	  TransformersSubProduct p;
	  
	  Iterator < TransformersSubProduct > i = products.iterator();
	  
	  while( i.hasNext() )
	  {
			p = i.next();
			
			Total = Total + p.getPrice() * p.getUnit();
	  }
	  
	  return Total;
   }

   public Double getTotalRestock()
   {
      Double TotalRestock = 0.00;
	  
	  TransformersSubProduct p;
	  
	  Iterator < TransformersSubProduct > i = products.iterator();
	  
	  while( i.hasNext() )
	  {
			p = i.next();
			
			TotalRestock = TotalRestock + ( 0.05 * p.getPrice() * p.getUnit() ) 
			                            + ( p.getPrice() * p.getUnit() );
	  }
	  
	  return TotalRestock;
   }

   public String processOutPut( TransformersSubProduct p )
   {
      String out = "Welcome to the Transformers Autobot Toy Inventory!" + "\n\nBelow is the available Inventory:"
      + "\n\nThe restock interest rate is at 5%"   
      + "\n\nItem #\tName\t\tUnits\tPrice\tUnit Restock\tStock Value\tTotal Product Restock" 
      + p + "\n\nThe value of the entire inventory is $" + this.getTotal()
      + "\n\nThe 5% restocking cost for the entire inventory is $" + this.getTotalRestock();
	  
	  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 < TransformersSubProduct > i = products.iterator();
   
      String te = null;
   
      TransformersSubProduct p;
      
      while( i.hasNext() )
      {
	     p = i.next();
      
         if( p.getAutobotName().equals( Search ) )
         {
	        te = processOutPut( p );
         }
      }
      
      return te;
   }
}
import static java.lang.System.out;
import java.io.Serializable;

//class declaration for TransformersProduct
public class TransformersProduct implements Serializable
{
   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 restock;
   public double stock;
   public double totalRestock;
	
   /**
	* @param autobotName
	* @param productNumber
	* @param unit           
	* @param price
	*/
   
   public TransformersProduct( 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 getRestock() 
   {
      return restock;
   }
	
   public Double restock()
   {
      return 0.05 * this.getPrice() + this.getPrice();
   }
   
   public double getStock() 
   {
      return stock;
   }
	
   public Double stock()
   {
      return this.getPrice() * this.getUnit();
   } 
	
   public double getTotalRestock() 
   {
      return totalRestock;
   }
	
   public Double totalRestock()
   {
      return 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"; 
   }
}
import java.io.Serializable;

public class TransformersSubProduct extends TransformersProduct implements Serializable
{
   public TransformersSubProduct( String autobotName, int productNumber, int unit,
			               double price ) 
   {
      super( autobotName, productNumber, unit, price );
	  
	  this.restock = this.restock();
	  
	  this.stock = this.stock();
	  
	  this.totalRestock = this.totalRestock();
	  // TODO Auto-generated constructor stub
   }
	
   public Double restock()
   {
      return this.getPrice() + this.getPrice() * 0.05;
   }                         
   
   public Double stock()
   {
      return this.getUnit() * this.getPrice();
   }                            
   
   public Double totalRestock()
   {
      return this.getUnit() * this.getPrice() + this.getUnit() * this.getPrice() * 0.05;
   }
   
   public String toString()
   {
      return "\n\n" + this.productNumber + "\t" + this.autobotName 
                    + "\t\t" + this.unit   + "\t$ " + this.price 
                    + "\t$ " + this.getRestock() 
                    + "\t$ " + this.getStock() 
                    + "\t$ " + this.getTotalRestock()
                    + "\n"; 
   }
}

Here's my previous assignment, with the sorter working.

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.TextArea;
import java.awt.Container;

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

import java.text.Collator;

import java.util.Locale;

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


import javax.swing.border.Border;

// class declaration for TransformersInventory5
public class TransformersInventory5 extends JFrame implements ActionListener
{
   private static TransformersProductSubClass myTransformers;
   public static int currentRecordShown = 0;
   private JTextArea textArea;
   private JButton first,next,previous,last;
      
   // declare array name autobotNameArray
   static String autobotNameArray[] = { "No Sale bot", "Optimus Prime", "BumbleBee", 
                                        "Ironhide", "Ratchet", "Jazz" };
                                                    
   static int autobotProductArray[] = { 0, 7, 16, 25, 34, 43 }; // product # array
   static int autobotUnitArray[] = { 1, 52, 61, 106, 115, 124 }; // array of autobot toy units
      
   static double autobotPriceArray[] = { 0.00, 160.00, 97.00, 88.00, 79.00,70.00 }; // array of autobot toy prices

   static double autobotRestockArray[] = { 0.05 * autobotPriceArray[ 0 ] + autobotPriceArray[ 0 ], 
                                           0.05 * autobotPriceArray[ 1 ] + autobotPriceArray[ 1 ], 
                                           0.05 * autobotPriceArray[ 2 ] + autobotPriceArray[ 2 ], 
                                           0.05 * autobotPriceArray[ 3 ] + autobotPriceArray[ 3 ], 
                                           0.05 * autobotPriceArray[ 4 ] + autobotPriceArray[ 4 ], 
                                           0.05 * autobotPriceArray[ 5 ] + autobotPriceArray[ 5 ] }; // array of autobot stock values

   static double autobotStockArray[] = { autobotUnitArray[ 0 ] * autobotPriceArray[ 0 ], 
                                         autobotUnitArray[ 1 ] * autobotPriceArray[ 1 ], 
                                         autobotUnitArray[ 2 ] * autobotPriceArray[ 2 ], 
                                         autobotUnitArray[ 3 ] * autobotPriceArray[ 3 ], 
                                         autobotUnitArray[ 4 ] * autobotPriceArray[ 4 ], 
                                         autobotUnitArray[ 5 ] * autobotPriceArray[ 5 ] }; // array of autobot stock values
                                         
   static double autobotTotalRestockArray[] = { 0.05 * autobotStockArray[ 0 ] + autobotStockArray[ 0 ], 
                                                0.05 * autobotStockArray[ 1 ] + autobotStockArray[ 1 ], 
                                                0.05 * autobotStockArray[ 2 ] + autobotStockArray[ 2 ], 
                                                0.05 * autobotStockArray[ 3 ] + autobotStockArray[ 3 ], 
                                                0.05 * autobotStockArray[ 4 ] + autobotStockArray[ 4 ], 
                                                0.05 * autobotStockArray[ 5 ] + autobotStockArray[ 5 ] }; // array of autobot stock values

   public TransformersInventory5()
   {
      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();
	  
	  first = new JButton( "First" );
	  first.addActionListener(this);

	  next = new JButton( "Next" );
	  next.addActionListener( this );

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

	  last = new JButton( "Last" );
	  last.addActionListener( this );
	  
	  buttonPaenl.setLayout( new FlowLayout() );
      buttonPaenl.add( first );
	  buttonPaenl.add( previous );
	  buttonPaenl.add( next );
	  buttonPaenl.add( last );
	  cp.add( buttonPaenl, 
	          BorderLayout.SOUTH );	  
	  
	  this.setContentPane( cp );
	  
	  this.setTitle( "Week Eight CheckPoint: Inventory Program Part 5 ( Oooey GUI Phooey -- o_0?! )" );
	  
	  this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	  
	  this.pack();
      
      inventorySorter();
      
      myTransformers = new TransformersProductSubClass( "Transformers Autobot Toy Inventory", 
                                                        "5%",  
                                                        autobotNameArray, 
                                                        autobotProductArray, 
                                                        autobotUnitArray, 
                                                        autobotPriceArray,
                                                        autobotRestockArray, 
                                                        autobotStockArray,
                                                        autobotTotalRestockArray );
      textArea.setText( myTransformers.outputInventory() );
		
	  this.setVisible( true );
   } // end
                                      
   // main method begins program execution
   public static void main( String args[] ) 
   {                                         
      
      JFrame frame = new JFrame();
      ImageIcon icon = new ImageIcon("AutobotCompanyLogo.jpg");
      JLabel label = new JLabel(icon);
      Container contentPane = frame.getContentPane();
        
      contentPane.add(label);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setVisible(true);      
      
      TransformersInventory5 tfI2 = new TransformersInventory5();		
   } // end main
   
   // inventorySorter method
   public static void inventorySorter()
   {
      String sorter;
		
      int sorterAutobotProductArray,
          sorterAutobotUnitArray;
		
      double sorterAutobotPriceArray,
             sorterAutobotRestockArray,
             sorterAutobotStockArray,
             sorterAutobotTotalRestockArray;
	
	  Locale loc = Locale.ENGLISH;
		
      Collator col = Collator.getInstance( loc );
		
      for ( int i = 0; i < autobotNameArray.length; i++ ) 
      {
         for ( int j = i + 1; j < autobotNameArray.length; j++ ) 
         {
            if( col.compare(autobotNameArray[i], autobotNameArray[j] ) > 0 ) 
            {
               sorter = autobotNameArray[ i ];
		       sorterAutobotProductArray = autobotProductArray[ i ];
		       sorterAutobotUnitArray = autobotUnitArray[ i ];
		       sorterAutobotPriceArray = autobotPriceArray[ i ];
		       sorterAutobotRestockArray = autobotRestockArray[  i ];
		       sorterAutobotStockArray = autobotStockArray[ i ];
		       sorterAutobotTotalRestockArray = autobotTotalRestockArray[ i ];
		        
		       autobotNameArray[ i ] = autobotNameArray[ j ];
		       autobotProductArray[ i ] = autobotProductArray[ j ];
		       autobotUnitArray[ i ] = autobotUnitArray[ j ];
		       autobotPriceArray[ i ] = autobotPriceArray[ j ];
		       autobotRestockArray[ i ] = autobotRestockArray[ j ];
		       autobotStockArray[ i ] = autobotStockArray[ j ];
		       autobotTotalRestockArray[ i ] = autobotTotalRestockArray[ j ];
		        
		       autobotNameArray[ j ] = sorter;
		       autobotProductArray[ j ] = sorterAutobotProductArray;
		       autobotUnitArray[ j ] = sorterAutobotUnitArray;
		       autobotPriceArray[ j ] = sorterAutobotPriceArray;
		       autobotRestockArray[ j ] = sorterAutobotRestockArray;
		       autobotStockArray[ j ] = sorterAutobotStockArray;
		 	   autobotTotalRestockArray[ j ]  = sorterAutobotTotalRestockArray;		        
            } // end 2nd inner if
		 } // end 1st inner if
	  } // end for
   } // end inventorySorter
   
   public void actionPerformed( ActionEvent e ) 
   {
      if( e.getActionCommand().equals( "First" ) )
      {
	     textArea.setText( getFirst() );
	  }
	  
	  if( e.getActionCommand().equals( "Next" ) )
	  {
	     textArea.setText( getNext() );
	  }
		
	  if( e.getActionCommand().equals( "Previous" ) )
	  {
	     textArea.setText( getPrevious() );
	  }
		
	  if( e.getActionCommand().equals( "Last" ) )
	  {
	     textArea.setText( getLast() );
	  }

   }
   public String getFirst()
   {
      String firstRecord = getTitleForPrinting();
	  
	  firstRecord = firstRecord + "\n" + 1 + "\t" + myTransformers.product[ 1 ] + "\t\t\t" 
	                + myTransformers.autobotName[ 1 ] + "\t\t" + myTransformers.unit[ 1 ] 
	                + "\t\t$ " + myTransformers.price[ 1 ] + "\t\t$ " + myTransformers.restock[ 1 ] 
	                + "\t\t$ " + myTransformers.stock[ 1 ] + "\t\t$ " + myTransformers.totalRestock[ 1 ] 
	                + "\n";
	  
	  currentRecordShown=1;
	  
	  return firstRecord;
   }
	
   public String getLast()
   {
      int lastindex;
	   
	  lastindex = myTransformers.product.length-1;
		
	  String lastRecord = getTitleForPrinting();
	   
	  lastRecord = lastRecord + "\n" + lastindex + "\t" + myTransformers.product[ lastindex ] + "\t\t\t" 
	  + myTransformers.autobotName[ lastindex ] + "\t\t" + myTransformers.unit[ lastindex ] + "\t\t$ " 
	  + myTransformers.price[ lastindex ] + "\t\t$ " + myTransformers.restock[ lastindex ] + "\t\t$ " 
	  + myTransformers.stock[ lastindex] + "\t\t$ "+ myTransformers.totalRestock[ lastindex ] + "\n";
	   
	  currentRecordShown = lastindex + 1;
	   
	  return lastRecord;
   }
	
   public String getNext()
   {
      if( currentRecordShown == myTransformers.product.length )
	     return getFirst();
	   
	  else
	  {
	     currentRecordShown++;
		
		 String nextRecord = getTitleForPrinting();
		  
		 int index = currentRecordShown - 1;
		
		 nextRecord = nextRecord + "\n" + index + "\t" + myTransformers.product[ index ] + "\t\t\t" 
		 + myTransformers.autobotName[ index ] + "\t\t" + myTransformers.unit[ index ] + "\t\t$ " 
		 + myTransformers.price[ index ] + "\t\t$ " + myTransformers.restock[ index ] + "\t\t$ " 
		 + myTransformers.stock[ index ] + "\t\t$ " + myTransformers.totalRestock[ index ] + "\n";
		  
		 return nextRecord;
      }
   }
   public String getPrevious()
   {
      if( currentRecordShown == 1 )
         return getLast();
	  
	  else
	  {
	     currentRecordShown--;
		 
		 String previousRecord=getTitleForPrinting();
		 
		 int index = currentRecordShown - 1;
		 
		 previousRecord = previousRecord + "\n" + index + "\t" + myTransformers.product[ index ] + "\t\t\t" 
		 + myTransformers.autobotName[ index ] + "\t\t" + myTransformers.unit[ index ] + "\t\t$ "
		 + myTransformers.price[ index ] + "\t\t$ " + myTransformers.restock[ index ] + "\t\t$ " 
		 + myTransformers.stock[ index ] + "\t\t$ " + myTransformers.totalRestock[ index ] 
		 + "\n";
		 
		 return previousRecord;
      }
   }
   
   public String getTitleForPrinting()
   {
      String transformersSub = new String(" ");

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

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

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

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

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

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

	  transformersSub = transformersSub + "Total Product Restock\n";
		
	  return transformersSub;
   }      
}
import static java.lang.System.out;
 

// class declaration for TransformersProduct
public class TransformersProduct
{
   private String inventoryName; // name of inventory
   
   public String restockRate; // restock rate percentage
      
   public String autobotName[]; // array of autobot toy names
   
   public int product[]; // product # array
   public int unit[]; // array of autobot toy units
   
   public double price[]; // array of autobot prices
   public double restock[];
   public double stock[]; // array of autobot stock values
   public double totalRestock[];
   
   /* nine-argument constructor initializes inventoryName, restockRate, 
    *autobotName, product, unit, price, restock, stock, and totalRestock arrays. */
   public TransformersProduct( String name, String rate, String autobotNameArray[],
                               int autobotProductArray[], int autobotUnitArray[], 
                               double autobotPriceArray[], double autobotRestockArray[],
                               double autobotStockArray[], double autobotTotalRestockArray[] )   
   {
   	inventoryName = name; // initialize inventoryName
   	restockRate = rate; // initialize restock rate
   	autobotName = autobotNameArray; // initialize autobotName
   	product = autobotProductArray; // initialize product
   	unit = autobotUnitArray; // initialize unit
   	price = autobotPriceArray; // initialize price
   	restock = autobotRestockArray;
   	stock = autobotStockArray;
   	totalRestock = autobotTotalRestockArray; // initialize stock
   } // end eight-argument TransformersProduct constructor

   // method to set the inventory name
   public void setInventoryName ( String name ) 
   {
      inventoryName = name; // store inventory name
   } // end method setInventoryName
   
   // method to retrieve the inventory name
   public String getInventoryName()
   {
   	   return inventoryName; // 
   } // end method getInventoryName
   
   // method to set the inventory name
   public void setRestockRate ( String rate ) 
   {
      restockRate = rate; // store restock rate
   } // end method setInventoryName
   
   // method to retrieve the restock rate
   public String getRestockRate()
   {
   	   return restockRate; //
   } // end method getInventoryName

   // display a welcome message to the TransformersInventory5 user
   public void displayMessage()
   {
      // getInventoryName gets the name of the inventory
      out.printf( "Welcome to the\n%s!\n\n", 
                  getInventoryName() );
   } // end method displayMessage
   
   // display a welcome message to the TransformersInventory5 user
   public void displayMessage2()
   {
      // getInventoryName gets the name of the inventory
      out.printf( "The restock interest rate is at %s.\n\n",
                  getRestockRate() );
   } // end method displayMessage2    
   
   //method to display the invertory arrays output
   public void processInventory()
   {
      // output inventory arrays
      outputInventory();
   } // end method processInventory
   
   // output inventory arrays
   public String outputInventory()
   {
      // displays available inventory message
      out.println( "Below is the available inventory:\n" ); 
                                                             
      // create column headings
      out.print( "Index\tProduct #\t\tName\t\tUnits\t\t\tPrice\t\t" );

      out.print( " Unit Restock Value\t" ); // create Stock Value column
      
      out.print( "Stock Value\t" ); // create Stock Value column
      
      out.print( "Total Product Restock\n" ); // create Stock Value column
       
      // output each arrays' elements' value
      for ( int toyCounter = 0; toyCounter < autobotName.length; toyCounter++)
            out.printf( "\n%5d%12d%19s%17d             $%10.2f                   $%10.2f     $%10.2f               $%10.2f\n", 
                        toyCounter, product[ toyCounter ], autobotName[ toyCounter ], 
                        unit[ toyCounter ], price[ toyCounter ], restock[ toyCounter ],
                        stock[ toyCounter ], totalRestock[ toyCounter ] );
     
      // calculate entire inventory value 
      double totalStockValue = stock[ 0 ] + stock[ 1 ] + stock[ 2 ] + stock[ 3 ] + stock[ 4 ] + stock[ 5 ];
      
      // calculate the restocking cose
      double totalRestockValue = 0.05 * totalStockValue + totalStockValue;
      
      out.printf( "\nThe value of the entire inventory is $ %.2f\n", totalStockValue );
      out.printf( "\nThe restocking cost for the entire inventory is $ %.2f\n", totalRestockValue );
     
      return "Please Call the subClass function";
                 
   }  // end outputInventory
}
import static java.lang.System.out;

public class TransformersProductSubClass extends TransformersProduct
{
   public TransformersProductSubClass( String name, String rate, String autobotNameArray[],
                                       int autobotProductArray[], int autobotUnitArray[], 
                                       double autobotPriceArray[], double autobotRestockArray[],
                                       double autobotStockArray[], double autobotTotalRestockArray[] ) 
   {
      super( name, rate, autobotNameArray, autobotProductArray, autobotUnitArray,
		     autobotPriceArray, autobotRestockArray, autobotStockArray, autobotTotalRestockArray );
   }
   
   public String outputInventory()
   {
      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\tProduct #\t\t\tName\t\tUnits\t\tPrice\t\t";
	
	  transformersSub = transformersSub + "Unit Restock Value\t";	

	  transformersSub = transformersSub + "Stock Value\t\t";
      
      transformersSub = transformersSub + "Total Product Restock\n";

	  for ( int toyCounter = 0; toyCounter < autobotName.length; toyCounter++)
	  {
	     transformersSub = transformersSub + "\n" +	toyCounter + "\t" + product[ toyCounter ] 
	     + "\t\t\t" + autobotName[ toyCounter ] + "\t\t" + unit[ toyCounter ] + "\t\t$ "+ price[ toyCounter ] 
	     + "\t\t$ "+ restock[ toyCounter ] + "\t\t$ "+ stock[ toyCounter ] + "\t\t$ "+ totalRestock[ toyCounter ] 
	     + "\n";
	  }

	  double totalStockValue = stock[ 0 ] + stock[ 1 ] + stock[ 2 ] + stock[ 3 ] + stock[ 4 ] + stock[ 5 ];
	  double totalRestockValue = 0.05 * totalStockValue + totalStockValue;
	
	  transformersSub = transformersSub + "\nThe value of the entire inventory with additional 5% is $ " 
	  + totalStockValue + "\n";
		
	  transformersSub = transformersSub + "\nThe restocking cost for the entire inventory is $ " 
	  + totalRestockValue;
		
	  return transformersSub;
		
   }
}

1) keep backups...
2) keep organised...
3) don't hope we're going to read thousands of lines of code to find the one that's wrong.

Sorry, I was off in a rush to work, I forgot to explain where is the error. It's in the third part of the code (TransformersInventoryInfo class). The sort is located near the beginning of the class at /* public void sort().

Well, if it starts with "/*" then either that is the problem, or that code is not the problem, as it is commented out.

This article has been dead for over six months. Start a new discussion instead.