Tutorial: Linked List IV

by
Ronald S. Holland
Total Application Works
RonHolland@sumtotalz.com





To visit my site

HOME] Consulting Design Maintenance Project Testing Training Turnkey Java C++ SQL HTML JavaScript ]


To contact us

2002 - 2011 All Rights Reserved Total Application Works


  • If you like this tutorial, tell a friend about it (copy and paste the following URL or send this page to a friend.)
    <html>
    <title>Example of a link </title>
    <body>
    <table border>
    <a href="http://sumtotalz.com/TotalAppsWorks/Linkedlist/LL_Tutorial_4.html"> Tutorial: Linked List IV </a>
    </table>
    </body>
    </html>
    Download the source
    Screen shot
  1. Java Table of contents
  2. 2nd Java Cup
  3. Pie Chart I
  4. Pie/Bar Chart IB
  5. Pie/Bar Chart II
  6. Pie/Bar Chart III
  7. A Basic Calculator
  8. Linked list Introduction
  9. Linked Lists I
  10. Linked List II
  11. Linked List III
  12. Linked List IV
  13. Hardware Store I
  14. Hardware Store II
  15. Hardware Store III
  16. Client/Server
  17. Client/Server II
  18. Client/Server III
  19. Client/Server IV
  20. Multithreaded Client/Server
  21. Multithreaded Client/Server II
  22. Multithreaded Client/Server III
  23. Basic Calculator II
  24. Basic Calculator III

Introduction

The purpose of this tutorial is to show how to modify two applications to come up with a third application. What is the significance of this? We wouldn't want to have to reinvent the square root subroutine every time we needed it. This is an example of how to modify existing classes/algorithms to solve a problem. In this tutorial, we will continue to develop our Linked List application by adding the capability for persistent data to the back end of our application. Again, we will be modifying only our Linked List class in this tutorial. This tutorial assumes that you have already mastered the preceding tutorials on this topic:

  1. Linked Lists I
  2. Linked List II
  3. Linked List III
  4. Hardware Store I
You may be wondering why you must master the Hardware Store application. In the Hardware Store application, the basic structure looks like:

 

GUI Front End              Persistent Data Back End
+-----------------+        +----------------+
| Hardware Store  |<------>|     Record     |
+-----------------+        +----------------+
 
Figure 1: Hardware Store Data


In the above example, the user was able to add, update, and delete persistent data. In the preceding the Linked List III tutorial, we added a GUI front end to our Linked List application. In this tutorial, we are basically going to take the Hardware Store application and add the Linked List class in the middle, so that it looks like:

 
GUI Front End            Ordering Algorithm        Persistent Data Back End
+----------------+        +----------------+        +----------------+
| Hardware Store |<------>|  Linked List   |<------>|     Record     |
+----------------+        +----------------+        +----------------+
 
Figure 2: Hardware Store using a Linked List


Of course, in this tutorial, the Hardware Store application will be modified so that it becomes the Car Store application. In effect, the Hardware Store application/class is an algorithm. As such, it is reusable. After we reuse it and modify it, the depiction looks like:

 
  GUI Front End            Ordering Algorithm        Persistent Data Back End
+-----------------+        +----------------+        +----------------+
| Car Parts Store |<------>|  Linked List   |<------>|     Record     |
+-----------------+        +----------------+        +----------------+
 
Figure 3: Car Parts Store using a Linked List


To reiterate, we will modify the Hardware Store application in the following areas:
  • The titles of the GUI.
  • The Linked List class will be modified so that it goes from handling integers to handling Strings.
  • The data will now reflect automobile parts, instead of hardware items.
As a review, we will redefine a Linked List, which is a main topic in our tutorial, in the next section.

What is a Linked List?

What is a Linked List? It is a self-referential class that contains a reference member and that member contains the address to a class object of the same class type. In real life, there are many instances where we use addresses. For example, we use addresses

  • To designate where we live.
  • To designate where mail is to be sent.
  • To designate our email address.
A Linked List is like a chain where each link in the chain contains the address to the next link in the chain. A class of this type might look like:

  
class node {
   private int data;
   private next refA;

   public node() {}
   void setData( int ) {}
   int getData(  int ) {}
   void setNextRef( node ref ) {}
   node getNextRef( ) {} 
   void init(  ) {}
   void AddLastNode( int ) {}
   void AddNode( int ) {}
   void DeleteNode( int ) {}
   void DisplayList( int ) {}
}
Figure 4: Linked List Class


After the above class is run and data is inserted into the linked list, the chain might look something like the following:

  
    HEAD
+-----------+
| reference | <-- contains the address to the start
+-----+-----+     of the linked list
      | 
      V   
+-----+-----+      +-----------+      +-----------+
|   data    |  +-->|   data    |  +-->|   data    |
+-----------+  |   +-----------+  |   +-----------+
| reference |--+   | reference |  |   | reference |
+-----------+      +-----+-----+  |   +-----+-----+
                         |        |
      +------------------+        |
      |                           |
      V                           |
+-----+-----+      +-----------+  |
|   data    |  +-->|   data    |  |
+-----------+  |   +-----------+  | 
| reference |--+   | reference |--+
+-----------+      +-----------+
Figure 5: Linked List Chain


In an array, data is stored in contiguous memory and can be accessed by using a reference and an index. For example,

  
int ar[] = new int[ 12] ;
 
for ( int i = 0 ; i < ar.length ; i++ )
   ar[ i ] = i ;
Figure 6: Initializing an array


The above code segment loads the value of i in each succeeding location of the array named ar.

An array is different than a linked list in many ways. In an array,

  • The data is stored in contiguous physical memory.
  • The contiguous memory is addressed using a reference to the first location.
  • By using the name of the array and an index, the data is accessed. For example,
      
    ar[ 1 ] = 5 ;
    
  • The location of the array is resolved at compile time.
  • In addition, the size of an array cannot be changed at run time.

The organization of data in an array is physical. A linked list

  • Stores data based on the logical order of the data and not the physical order.
    • In other words, a linked list gives the appearance that the data in the list is stored in contiguous memory.
  • Instead of an index, all stored data records are assigned a physical address in memory that the link list algorithm/logic uses to locate the information.
  • A linked list logically organizes the data, rather than by physical address.
  • The memory for each node in the linked list is dynamically allocated at run time.

Requirements for a Linked List

This program is intended to be an introduction to linked lists. As such, the requirements are:

  1. Requirements for Linked List tutorial I
    1. Write this program as an application.
    2. The linked list node should be added to the linked list in a LIFO manner
      • All new nodes should be added at the head of the linked list
    3. Create an Add method to add new nodes to the linked list
    4. Create a Remove method to delete/remove nodes from the linked list
    5. Create a DisplayLL method to show the contents of the nodes
  2. Requirements for Linked List tutorial II
    1. Modify the add method so that elements are added in ascending sorted order.
    2. Create an addLast method to add new elements to the tail/end of the list.
    3. Create an addFirst method to add new elements to the head of the list.
    4. Create a Remove method to delete an element from the Linked List.
    5. Create an isEmpty method to determine if the Linked List has any entries.
    6. Create a contains method that finds out if a particular value is in the Linked List.
    7. Create a toArray method that retrieves the elements in the Linked List and stores them in an array.
    8. Create a getLast method that returns the last element in the Linked List.
    9. Create a size method that discovers the number of elements in the Linked List.
  3. Requirements for Linked List tutorial III
    1. Write the code so that it can be run as either an applet or an application.
      • Use the JApplet class to run the code as an applet.
      • Use the JFrame class to run the code as an application.
    2. Remove the main() method from the Linked List application.
    3. Add a test application that creates a Linked List object.
    4. Add a GUI front end to the test application.
      • The test application should be a subclass of JFrame i.e., extends JFrame
      • Use the JTable class to display the entries in the list.
      • Use the JButton class to allow the user to access various Linked List functions.
  4. Requirements for Hardware Store tutorial I
    1. Write this program as an application.
    2. The application should use a menu bar and menu items to show the various options.
    3. Initialize the hardware.dat file to 250 empty records;
      • Changed for the 10/07/2005 update
        • Initialize the following files to 250 empty records;
          • lawnmower.dat
          • lawnTractor.dat
          • handDrill.dat
          • drillPress.dat
          • circularSaw.dat
          • hammer.dat
          • tableSaw.dat
          • bandSaw.dat
          • sanders.dat
          • stapler.dat
        • Each type of tool should be stored in a separate file.
    4. Input the data concerning each tool;
    5. Delete a tool that you no longer carry;
    6. Update information on any tool that you carry;
    7. List all of the tools in your inventory;
    8. Present views for the various categories (e.g. lawn mowers) of tools that you carry.
    9. javadoc.
      • javadoc style comments begin with /** and end with */.
      • For example,
          
        /** This is what a javadoc style comment looks like. */
          
  5. Requirements for Linked List tutorial IV
    1. Add the Linked List application to the hardware Store application in the following fashion.

       
        GUI Front End            Ordering Algorithm         Persistent Data 
                                                               Back End
      +-----------------+        +----------------+        +----------------+
      | Car Parts Store |<------>|  Linked List   |<------>|     Record     |
      +-----------------+        +----------------+        +----------------+
       
      Figure 8: Car Parts Store High Level View
    2. Since the Hardware Store program runs as an application, the Car Parts Store program will run as an application.
    3. Modify the hardware Store application so that it becomes the Car Parts Store inventory program.
    4. Write the application so that it maintains a Car Store inventory.
    5. The application should use a menu bar and menu items to show the various options.
    6. The CarStore class should extend the JFrame class.
    7. The application should have a menu bar.
    8. Use two-dimensional String arrays to initialize file with car store items.
    9. Write an InitRecord() method to initialize data files.
    10. The InitRecord() method will initialize but is not limited to just the following data files:
      1. gas.dat - contains gas/fuel filter data
      2. headGas.dat - points to the first entry in the gas.dat file
      3. air.dat - contains air filter data
      4. headAir.dat - points to the first entry in the air.dat file
      5. battery.dat - contains data on batteries
      6. headBattery.dat - points to the first entry in the battery.dat file
      7. oil.dat - contains oil filter data
      8. headOil.dat - points to the first entry in the oil.dat file
      9. tires.dat - contains data on tires
      10. headTires.dat - points to the first entry in the tires.dat file
    11. Write a display() method that will display the contentsof a data file.
    12. Write a Redisplay() method that can be used to refresh the contents on the main frame.
    13. In this application, the JButton class will be used to exit only.

A Look at the Current Hardware Store Program Construction

In the following figure, the NewRec, UpdateRec, and the DeleteRec all read and write using the Record class.

  
GUI Front End          Persistent Data Back End
+----------------+        +----------------+
| Hardware Store |<------>|     Record     |
| +-----------+  |        | +-----------+  | 
| |  NewRec   |<------+   |                |               
| +-----------+  |    |   |                |
| |  UpdateRec|<------+   | +-----------+  |
| +-----------+  |    +---->|   Write   |  |
| |  DeleteRec|<------+   | +-----------+  |
| +-----------+  |    |   | |           |  |     
| |           |  |    |   | |           |  |   
| |           |  |    |   | |           |  |   
| +-----------+  |    |   | +-----------+  |   
| |  toArray  |<------+-----|   Read    |  |
| +-----------+  |        | +-----------+  |
| |           |  |        |                |
+----------------+        +----------------+
  
Figure 9: Current Hardware Store Program Construction


In the Car Parts Store program, the Linkedlist class will make the calls to the Record class for the read/writes. consider the following figure:

  
GUI Front End             Ordering Algorithm         Persistent Data 
                    +-------------------------+         Back End
+----------------+  |     +----------------+  |     +----------------+
| Hardware Store |  |     | Linked List    |  |     |     Record     |
| +-----------+  |  |     | +-----------+  |  |     | +-----------+  |
| |  NewRec   |<----------->|    Add    |<----+-+   | |           |  |              
| +-----------+  |  |     | +-----------+  |    |   | |           |  |   
| |  UpdateRec|<----+     | |           |  |    |   | +-----------+  |
| +-----------+  |        | +-----------+  |    +---->|   Write   |  |
| |  DeleteRec|<----------->| Remove    |  |        | +-----------+  |
| +-----------+  |        | +-----------+  |        | |           |  |     
| |           |  |        | |           |  |        | |           |  |   
| |           |  |        | |           |  |        | |           |  |   
| +-----------+  |        | +-----------+  |        | +-----------+  |   
| | Redisplay |<----------->| toArray   |<----------->|   Read    |  |
| +-----------+  |        | +-----------+  |        | +-----------+  |
|                |        |                |        |                |
+----------------+        +----------------+        +----------------+
  
Figure 10: Car Parts Store program


Logic for CarStore() constructor Method

The CarStore() constructor is used primarily to initialize the application. In our example, we will use the following methods.

  1. SetUpMenu() - is used to set up the menu bar and menu items.
    • You add JMenu objects to the menu bar to construct a menu. When the user selects a JMenu object, its associated JPopupMenu is displayed, allowing the user to select one of the JMenuItems on it.
  2. SetUpButtons() - is used to set up any buttons on the application. An implementation of a push button.
  3. InitRecord() - is used to initialize the following .dat files.
    • tire.dat
    • battery.dat
    • oil.dat
    • air.dat
    • gas.dat
  4. cs = this - stores a reference to this CartStore object.
  5. display() - is used to populate the JTable.
  6. setSize() - resizes this object so that it has width and height.
  7. setVisible() - Shows or hides this component.
An example looks like:

  
    public CarStore() {
      super ("Car Parts Store") ;

      c = getContentPane() ;

      SetUpMenu() ;

      SetUpButtons() ;

      InitRecord( "tire.dat" , "headTires.dat" , tireRecord , 21 ) ;

      InitRecord( "battery.dat" , "headBattery.dat" , batteryRecord , 15 ) ;

      InitRecord( "oil.dat" , "headOil.dat" , oilFilterRecord , 21 ) ;

      InitRecord( "air.dat" , "headAir.dat" , airFilterRecord , 15 ) ;

      InitRecord( "gas.dat" , "headGas.dat" , fuelFilterRecord , 15 ) ;

      cs = this ;

      display( "Tires" ) ;

      setSize( 700, 400 );
      setVisible( true );
   }
  
Figure 11: Car Parts Store Constructor


Logic for SetUpMenu() Method

To create our menu bar and menu items for our application/applet, we do the following:

  1. Create the menubar
  2. Add the menubar to the frame
  3. Create the File menu and add it to the menubar
  4. Add the Exit menu items
  5. Create the View menu and add it to the menubar
  6. Add the Views' menu items
  7. Create the Option menu and add it to the menubar
  8. Add the Add menuitems
  9. Add the Update menuitems
  10. Add the Delete menuitems
  11. Create the Tools menu and add it to the menubar
  12. Add the Tools menu items

Logic for setupButtons() Method

The logic for the setupButtons() Method is as follows:

  1. Add a JPanel
  2. Create the JButton Exit
  3. Add the JButton to the JPanel
  4. Add the JButton and JPanel to the bottom of the frame
Putting it together and the code looks like:

  
buttonPanel = new JPanel() ;
exit = new JButton( "Exit" ) ;
buttonPanel.add( exit ) ;
c.add( buttonPanel , BorderLayout.SOUTH) ;
exit.addActionListener( menuHandler );
  
Figure 12: Logic for setupButtons() Method


Logic for the Redisplay() Method

The Redisplay() method is called to redisplay the JTable when the value(s) have changed. The logic looks like:

  1. Create a LinkedList object
  2. Call the Linked List toArray() method to get the updated entries
  3. Delete the old table
  4. Create a new table
  5. Add the new table to the frame context
  6. Add a scroll pane to this context
  7. Cause the updated table to show on the screen
Putting it together and the code looks like:

  
LinkedList ll = new LinkedList() ;
ll.toArray( lFile , hFile , pData ) ;
c.remove( table ) ;
table = new JTable( pData, columnNames ) ;
table.setEnabled( true );
c.add( table , BorderLayout.CENTER) ;
c.add( new JScrollPane ( table ) );
c.validate();
  
Figure 13: Redisplay() Method


Logic for the Display() Method

The Display() Method is used to display the contents of a data file using a JTable. The logic looks like:

  1. Create a LinkedList object
  2. Use a nested if contruct to determine which data file is to be populated in the JTable
  3. Open the data file that contains the head pointer
  4. Open the data file that contains the LinkedList data
  5. Call the toArray method to populate an array with the contents of the data file
  6. store the number of data file entries in a variable
  7. Populate a JTable object with the contents of the array

Logic for checkpData() Method

The checkpData() method is called to ensure that the recordID entered is an existing number in the pData array. The actionPerformed() method of the UpdateRec class calls the checkpData() method.

Logic for InitRecord() Method

The InitRecord() method is used to initialize a data file. The logic is:

  1. Create a try-catch block.
  2. Determine if the .dat file containing the head pointer exists. If the file doesn't exist, create it.
  3. If the .dat file containing the Linked List does not exist, create it and initialize it with initial values.

Logic for actionPerformed() Method

The actionPerformed() Method is the method that is called when a GUI event, such as a button being pressed, occurs. The vents that this method responds to are:

  1. The Exit menu Item being selected.
  2. The user requesting that debug be toggled on or off.
  3. A request to view all tires.
  4. A request to view all batteries.
  5. A request to view all oil Filters.
  6. A request to view all air Filters.
  7. A request to view all gas Filters.
  8. A request for the delete dialog to delete an item.
  9. A request for the add dialog to add an item.
  10. A request for the update dialog to update an item.

Logic for sysPrint() Method

The sysPrint() Method is used for debugging.

  • set myDebug = true to turn on debugging

Logic for checkDigit() Method

The checkDigit() Method is used to make sure that the data entered is a digit.

Logic for checkFields() Method

The purpose of the checkFields() Method is to ensure that the text entry field is not null.

  1. It issues an error message if the text entry field is null.
  2. It then checks to ensure that the data entered was a digit.
  3. If the data entered was a digit, this code ensures that a button was pressed.

Putting It All Together

When we put it all together we get code that looks like:

  
   public CarStore() {
      super ("Car Parts Store") ;

      c = getContentPane() ;

      SetUpMenu() ;

      SetUpButtons() ;

      InitRecord( "tire.dat" , "headTires.dat" , tireRecord , 21 ) ;

      InitRecord( "battery.dat" , "headBattery.dat" , batteryRecord , 15 ) ;

      InitRecord( "oil.dat" , "headOil.dat" , oilFilterRecord , 21 ) ;

      InitRecord( "air.dat" , "headAir.dat" , airFilterRecord , 15 ) ;

      InitRecord( "gas.dat" , "headGas.dat" , fuelFilterRecord , 15 ) ;

      cs = this ;

      display( "Tires" ) ;

      setSize( 700, 400 );
      setVisible( true );
   }

   /** **********************************************************
    *  SetUpMenu() - is used to declare any menus/items
    *                and is called from the CarStore()
    *                constructor.
    *
    *                The SetUpMenu() method is called from the
    *                CarStore constructor.
    ************************************************************ */
   public void SetUpMenu()   {
      /** Create the menubar */
      menuBar = new JMenuBar();

      /** Add the menubar to the frame */
      setJMenuBar(menuBar);

      /** Create the File menu and add it to the menubar  */
      fileMenu = new JMenu("File");

      menuBar.add(fileMenu);
      /** Add the Exit menu items */
      eMI = new JMenuItem("Exit") ;
      fileMenu.add( eMI );
      eMI.addActionListener( menuHandler );

      /** Create the View menu and add it to the menubar  */
      viewMenu = new JMenu("Views");

      menuBar.add(viewMenu);
      /** Add the Views' menu items */
      viewTiresMI = new JMenuItem("Tires") ;

      viewMenu.add( viewTiresMI ) ;
      viewTiresMI.addActionListener( menuHandler ) ;

      viewBatteriesMI = new JMenuItem("Batteries") ;
      viewMenu.add( viewBatteriesMI ) ;
      viewBatteriesMI.addActionListener( menuHandler ) ;

      filtersMenu  = new JMenu("Filters") ;
      oilFiltersMI = new JMenuItem("Oil Filters") ;
      airFiltersMI = new JMenuItem("Air Filters") ;
      gasFiltersMI = new JMenuItem("Gas Filters") ;
      filtersMenu.add( oilFiltersMI ) ;
      filtersMenu.add( airFiltersMI ) ;
      filtersMenu.add( gasFiltersMI ) ;
      oilFiltersMI.addActionListener( menuHandler ) ;
      airFiltersMI.addActionListener( menuHandler ) ;
      gasFiltersMI.addActionListener( menuHandler ) ;
      viewMenu.add( filtersMenu ) ;


      /** Create the Option menu and add it to the menubar  */
      optionsMenu = new JMenu( "Options" ) ;
      menuBar.add( optionsMenu );

      /** Add the Add menuitems */
      addMI = new JMenuItem("Add") ;
      optionsMenu.add( addMI );
      addMI.addActionListener( menuHandler );

      /** Add the Update menuitems */
      updateMI = new JMenuItem("Update") ;
      optionsMenu.add( updateMI );
      updateMI.addActionListener( menuHandler );
      optionsMenu.addSeparator();

      /** Add the Delete menuitems */
      deleteMI = new JMenuItem("Delete") ;
      optionsMenu.add( deleteMI );
      deleteMI.addActionListener( menuHandler );

      /** Create the Tools menu and add it to the menubar  */
      toolsMenu = new JMenu("Tools") ;
      menuBar.add(toolsMenu);
      /** Add the Tools menu items */
      debugON = new JMenuItem("Debug On") ;
      debugOFF = new JMenuItem("Debug Off") ;
      toolsMenu.add( debugON );
      toolsMenu.add( debugOFF );
      debugON.addActionListener( menuHandler );
      debugOFF.addActionListener( menuHandler );

      /** Create the Help menu and add it to the menubar  */
      helpMenu = new JMenu("Help") ;

      /** Add the Help HW Store menuitems */
      helpHWMI = new JMenuItem("Help on Car Store") ;
      helpMenu.add( helpHWMI );
      helpHWMI.addActionListener( menuHandler );

      menuBar.add(helpMenu);

      /** Create the About menu and add it to the menubar  */
      aboutMenu = new JMenu("About") ;

      /** Add the About Store menuitems */
      aboutHWMI = new JMenuItem("About Car Store") ;
      aboutMenu.add( aboutHWMI );
      aboutHWMI.addActionListener( menuHandler );

      menuBar.add(aboutMenu);


   }

   /** *************************************************************
    *  SetUpButtons() - is used to declare any buttons. The only
    *                   button declared in this application is the
    *                   exit button.
    *
    *                   The SetUpButtons() method is called from the
    *                   CarStore constructor.
    **************************************************************** */
   public void SetUpButtons()   {
      buttonPanel = new JPanel() ;
      exit = new JButton( "Exit" ) ;
      buttonPanel.add( exit ) ;
      c.add( buttonPanel , BorderLayout.SOUTH) ;
      exit.addActionListener( menuHandler );
   }


   /** ************************************************************
    *  Redisplay() - is used to refresh the contents of the JTable
    *                on the main frame window.
    *
    *                The Redisplay() method is called from the
    *                CarStore constructor.
    ************************************************************ */
   public void Redisplay( RandomAccessFile lFile, RandomAccessFile hFile,
                         String a[][] ) {
      LinkedList ll = new LinkedList() ;
      ll.toArray( lFile , hFile , pData ) ;
      c.remove( table ) ;
      table = new JTable( pData, columnNames ) ;
      table.setEnabled( true );
      c.add( table , BorderLayout.CENTER) ;
      c.add( new JScrollPane ( table ) );
      c.validate();
   }

   /** *************************************************
    *  display() - is used to display the contents of
    *              data file using a JTable.
    *
    *              The display() method is called from the
    *              1- CarStore constructor
    *              2- MenuHandler class
    ************************************************ */
   public void display( String str ) {
      pp = new LinkedList();
      String hf = null , df = null ,  title = null ;

      if ( str.equals( "Tires" ) ) {
         hf = new String("headTires.dat" ) ;
         df = new String("tire.dat"  ) ;
         linkFile = new File( "tire.dat" ) ;
         headFile = new File( "headTires.dat" ) ;
         title = new String( "Car Parts Store: Tires" ) ;
      }
      else if ( str.equals( "Batteries" )  ) {
         hf = new String("headBattery.dat" ) ;
         df = new String("battery.dat"  ) ;
         linkFile = new File( "battery.dat" ) ;
         headFile = new File( "headBattery.dat" ) ;
         title = new String( "Car Parts Store: Batteries" ) ;
      }
      else if ( str.equals( "Oil Filters" )  ) {
         hf = new String("headOil.dat" ) ;
         df = new String("oil.dat"  ) ;
         linkFile = new File( "oil.dat" ) ;
         headFile = new File( "headOil.dat" ) ;
         title = new String( "Car Parts Store: Oil Filters" ) ;
      }
      else if ( str.equals( "Air Filters" )  ) {
         hf = new String("headAir.dat" ) ;
         df = new String("air.dat"  ) ;
         linkFile = new File( "air.dat" ) ;
         headFile = new File( "headAir.dat" ) ;
         title = new String( "Car Parts Store: Air Filters" ) ;
      }
      else if ( str.equals( "Gas Filters" )  ) {
         hf = new String("headGas.dat" ) ;
         df = new String("gas.dat"  ) ;
         linkFile = new File( "gas.dat" ) ;
         headFile = new File( "headGas.dat" ) ;
         title = new String( "Car Parts Store: Fuel Filters" ) ;
      }

      try {
         /** Open the headFile in RW mode.
          *  If the file does not exist, create it
          *  and initialize it to 250 empty records.
          */

         if ( !headFile.exists() ) {
         }
         else {
            hFile = new RandomAccessFile( hf , "rw" );
         }
      }
      catch ( IOException e ) {
            System.err.println( e.toString() );
            System.err.println( "Failed in opening " + hf );
            System.exit( 1 );
      }

      try {
         /** Open the .dat file in RW mode.
          *  If the file does not exist, create it
          *  and initialize it to 250 empty records.
          */

         sysPrint("display(): 1a - checking to see if " + df + " exists." );
         if ( !linkFile.exists() ) {

            sysPrint("display(): 1b - " + df + " does not exist." );

         }
         else {
            lFile = new RandomAccessFile( df , "rw" );
            int entries = pp.toArray( lFile , hFile , pData );
            setEntries( entries ) ;

            this.setTitle( title );

            table = new JTable( pData, columnNames ) ;
            table.setEnabled( true );
            c.add( table , BorderLayout.CENTER) ;
            c.add( new JScrollPane ( table ) );
            c.validate();
         }

         lFile.close();
         hFile.close();
      }
      catch ( IOException e ) {
            System.err.println( e.toString() );
            System.err.println( "Failed in opening " + hf );
            System.exit( 1 );
      }

   }

   /** *****************************************************
    *  checkpData() - is used to ensure that the recordID
    *  entered is a number that exists inthe array.
    *
    *  checkpData() is called from the UpdateRec class.
    ******************************************************* */
   public boolean  checkpData( int recID , String pData[][] ) {

      int pDataLength = getEntries() , aa = 0 ;
      boolean valIndex = false;

      sysPrint("checkpData(): 1a - The value of pDataLength is " + pDataLength );
      for (int ii = 0 ; ii < pDataLength; ii++) {
         sysPrint("index is " + ii + " checkpData(): 1b - The value of 
             Integer.parseInt(pData[ ii ] [ 0 ] is " + 
                  Integer.parseInt(pData[ ii ] [ 0 ] ) ) ;
         sysPrint("checkpData(): 1c - The value of ii is " + ii ) ;
         aa = Integer.parseInt(pData[ ii ] [ 0 ]) ;
         if ( aa == recID ) {
            valIndex = true ;

            break;
         }
      }

      return valIndex ;
   }

   /** *****************************************************************
    *  setEntries() - is called to to set the number of
    *                 entries in the current data file.
    *
    *                 The setEntries() method is called from
    *                 1- display() method
    *                 2- actionPerformed() method of the NewRec class
    *                 3- actionPerformed() method of the DeleteRec class
    ******************************************************************* */
   public void setEntries( int ent )   {
      numEntries = ent ;
   }

   /** ******************************************************************
    *  getEntries() - is used to obtain the number of entries in the
    *                 current data file. The getEntries() method is called
    *                 from
    *                 1- checkpData( method
    *                 2- actionPerformed() method UpdateRec class
    *                 3- actionPerformed() method NewRec class
    ***************************************************************** */
   public int getEntries()   {
      return numEntries  ;
   }

   /** ****************************************************
    * Method: IsInPData() is used to ensure  that the data
    * entered is in the pData array
    *****************************************************/
   public boolean  IsInPData( String strVal ) {

      int strLength = 0 , loopCTL = getEntries() ;
      boolean ret = false;

      for ( int ii = 0 ; ii < loopCTL ; ii++ ) {
         if ( (pData[ ii ] [ 0 ]).equals( strVal ) ) {
            ret = true ;
            break ;
         }
      }

      return ret ;
   }

   /** ****************************************************
    * Method: checkDigit() is used to ensure  that the data
    * entered is a digit
    *****************************************************/
   public boolean  checkDigit(String strVal) {

      int strLength = 0;
      boolean notDig = true;

      strLength = strVal.length();

      for (int ii = 0; ii < strLength; ii++) {
         if (!Character.isDigit(strVal.charAt(ii)) ) {
            notDig = false;
            break;
         }
      }

      sysPrint( "The data is a digit " + notDig ) ;
      return notDig ;
   }
   /** *************************************************
    *  InitRecord() - is used to initialze a data file.
    *                 The InitRecord() method is called
    *                 from the CarStore constructor.
    ************************************************ */
   public void InitRecord( String linkDat , String headDat ,
            String tireRecord[][] , int loopCTL  ) {


      pp = new LinkedList();
      linkFile = new File( linkDat ) ;
      headFile = new File( headDat ) ;

         sysPrint("initRecord(): 1a - the value of linkDat is " + linkDat + 
               " \nand the value of headDat is " + headDat);
      try {
         /** Open the headFile in RW mode.
          *  If the file does not exist, create it
          *  and initialize it to 250 empty records.
          */

         if ( !headFile.exists() ) {

            hFile = new RandomAccessFile( headDat , "rw" );

            data.setRecID( -1 ) ;
            data.setQuantity( -1 ) ;
            data.setNext( 0 ) ;
            data.setToolType( " " ) ;
            data.setBrandName( "zzzzzzzzzzzzzzzzzz" ) ;
            data.setToolDesc( " " ) ;
            data.setPartNumber( " " ) ;
            data.setCost( " " ) ;

            hFile.seek( 0 * data.getSize() );
            data.write( hFile ) ;
         }
         else {
            hFile = new RandomAccessFile( headDat , "rw" );
         }
      }
      catch ( IOException e ) {
            System.err.println( e.toString() );
            System.err.println( "Failed in opening headTires.dat."  );
            System.exit( 1 );
      }

      try {
         /** Open the tire.dat file in RW mode.
          *  If the file does not exist, create it
          *  and initialize it to 250 empty records.
          */

         sysPrint("initTire(): 1ab - checking to see if " + linkDat + " exist." );
         if ( !linkFile.exists() ) {

            sysPrint("initTire(): 1b - " + linkDat + " does not exist." );

            lFile = new RandomAccessFile( linkDat , "rw" );
            data = new Record() ;

            for ( int ii = 0 ; ii < loopCTL ; ii++ ) {
               data.setRecID( Integer.parseInt( tireRecord[ ii ][ 0 ] ) ) ;
               sysPrint("initTire(): 1c - The value of record ID is " + 
                     data.getRecID() ) ;
               data.setQuantity( Integer.parseInt( tireRecord[ ii ][ 2 ] ) ) ;
               data.setToolType( tireRecord[ ii ][ 3 ] ) ;
               data.setBrandName( tireRecord[ ii ][ 4 ] ) ;
               data.setToolDesc( tireRecord[ ii ][ 5 ] ) ;
               data.setPartNumber( tireRecord[ ii ][ 6 ] ) ;
               data.setCost( tireRecord[ ii ][ 7 ] ) ;


               sysPrint("Calling Linklist method add() during initialization. " 
                     + ii );
               pp.add( lFile, hFile, data );

            }
         }
         else {
            lFile = new RandomAccessFile( linkDat , "rw" );
         }

         lFile.close();
         hFile.close();

      }
      catch ( IOException e ) {
            System.err.println( e.toString() );
            System.exit( 1 );
      }
   }

   /** ****************************************************************
    *  close() - is used to exit the application. It is called by:
    *            1- WindowAdapter's windowClosing() method
    *            2- MenuHandler class' actionPerformed() method
    ******************************************************************** */
   public void close()   {
      System.exit( 0 ) ;
   }

   /** *************************************************
    *  sysPrint() - is used for debugging
    *               - set myDebug = true to turn on debugging
    *
    ************************************************ */
   public void sysPrint( String str  )   {
      if ( myDebug ) {
         System.out.println( str );
      }
   }

   /** ************************************************************
    *  main() - This is the main entry poing point that is called
    *           by Java on application startup.
    ************************************************************** */
   public static void main(String args[]) {
      final CarStore cs = new CarStore() ;
      //cs.s

      cs.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )  {
               cs.close() ;
            }
         }
      );
   }

  
Figure 14: Car Parts Store Code


Car Store API

Method Summary
Method Description
checkDigit(String strVal) is used to ensure that the data entered is a digit
checkpData(String[][] pData) is used to ensure that the recordID entered is a number that exists inthe array.
close() is used to exit the application.
display(String str) is used to display the contents of data file using a JTable.
getEntries() is used to obtain the number of entries in the current data file.
InitRecord(String linkDat,
String headDat,
String[][] tireRecord,
int loopCTL)
is used to initialze a data file.
IsInPData(String strVal) is used to ensure that the data entered is in the pData array
main(String[] args) This is the main entry poing point that is called by Java on application startup.
Redisplay(RandomAccessFile lFile,
RandomAccessFile hFile,
String[][] a)
is used to refresh the contents of the JTable on the main frame window.
setEntries(int ent) is called to to set the number of entries in the current data file.
SetUpButtons() is used to declare any buttons.
SetUpMenu() is used to declare any menus/items and is called from the CarStore() constructor.
sysPrint(String str) is used for debugging - set myDebug = true to turn on debugging

NewRec Class API



  

   /** *************************************************************
    * NewRec class - is used to create the NewRec Dialog, which is
    *                used to gather user input for a new record.
    *************************************************************** */
   class NewRec extends Dialog
        implements ActionListener {
       

     /** ****************************************************************
      *  NewRec() - the NewRec constructor is used to create the NewRec
      *             dialog. This dialog is used to gather user data
      *             for a new record.
      ******************************************************************* */
      public NewRec( CarStore car_store, RandomAccessFile l_File,
              RandomAccessFile hFile, JTable tab,  String p_Data[] []  )
      {
          
      }

      public void NewSetup() { 

      }

     /** ******************************************************************
      *  actionPerformed() - is used to respond to NewRec dialog
      *                      GUI events. These events are:
      *                      1- Enter key pressed with cursor in the recordID
      *                         text field.
      *                      2- Save button being pressed
      *                      3- Cancel button being pressed
      ******************************************************************** */
      public void actionPerformed( ActionEvent e )   {
         
      }

     /** *************************************************
      *  NewClear() - is used to
      ************************************************ */
      private void NewClear()   {

      }
   }

  
Figure 15: NewRec Class API




NewRec Class Method Summary
Method Description
NewRec() is used to create the NewRec dialog. This dialog is used to gather user data for a new record.
NewRec( CarStore car_store,
RandomAccessFile l_File,
RandomAccessFile hFile,
JTable tab,
String p_Data[] [] )
is used to create the NewRec dialog. This dialog is used to gather user data for a new record.
NewSetup() is used to create the GUI used on the NewRec dialog.
actionPerformed() is used to respond to NewRec dialog GUI events. These events are:
  1. Enter key pressed with cursor in the recordID text field.
  2. Save button being pressed
  3. Cancel button being pressed
NewClear() is used to exit the NewRec dialog when the user exits, saves or cancels.


A description of the UpdateRec Class API follows.

UpdateRec Class API

The UpdateRec class creates the Update dialog, which is used to gather user input to udate a record.

  

   /** **************************************************************
    * UpdateRec class - is used to create the Update dialog, which 
    *                   is used to gather user input to udate a record.
    ****************************************************************** */
   class UpdateRec extends Dialog
         implements ActionListener {
       

   /** ***********************************************************
    *  UpdateRec() - this constructor is used to initialize the
    *                UpdateRec object.
    ************************************************************* */
      public UpdateRec( CarStore car_store, RandomAccessFile l_File ,
             RandomAccessFile h_File, String p_Data [] [], int iiPassed)
      {
          
      }

   /** *************************************************
    *  checkDigit() - is used to ensure that the data
    *  entered is a digit
    ************************************************ */
      public boolean  checkDigit(String strVal) {
          
      }

   /** *********************************************************************
    *  actionPerformed() - is used to respond to UpdateRec dialog
    *                      GUI events. These events are:
    *                      1- Enter key pressed with cursor in the recordID
    *                         text field.
    *                      2- Save button being pressed
    *                      3- Cancel button being pressed
    *********************************************************************** */
      public void actionPerformed( ActionEvent e )   {
          
      }

   /** ***********************************************************
    *  UpClear() - is called to close the UpdateRec dialog.
    *************************************************************** */
      private void UpClear()   {
          
      }
   }
  
Figure 16: UpdateRec Class API




UpdateRec Class Method Summary
Method Description
UpdateRec() this constructor is used to initialize the UpdateRec object.
checkDigit() is used to ensure that the data entered is a digit
actionPerformed() is used to respond to UpdateRec dialog GUI events. These events are:
  1. Enter key pressed with cursor in the recordID text field.
  2. Save button being pressed
  3. Cancel button being pressed
UpClear() is called to close the UpdateRec dialog.


A description of the DeleteRec Class API follows.

DeleteRec Class API

The DeleteRec Class is used to create the DeleteRec dialog. This dialog is used to gather the record ID for the record the user wants to delete.

  

   /** **************************************************************
    * DeleteRec class - is used to create the DeleteRec dialog.
    *                   This dialog is used to gather the record
    *                   ID for the record the user wants to delete.
    *
    *************************************************************** */
   class DeleteRec extends Dialog
          implements ActionListener {
     

     /** *******************************************************
      *  DeleteRec() - this constructor is used to create
      *                the GUI on the DeleteRec dialog. It
      *                1- Processes the input parameters
      *                2- Creates the labels and text fields
      *                3- Attaches event handlers to the buttons
      *                   and the record if textfield.
      ************************************************************ */
      public DeleteRec( CarStore car_store,  RandomAccessFile lF,
                    RandomAccessFile hF, JTable tab, String p_Data[] []  )
      {
        
      }

     /** ***********************************************************************
      *  actionPerformed() - is used to respond to DeleteRec dialog
      *                      GUI events. These events are:
      *                      1- Enter key pressed with cursor in the recordID
      *                         text field.
      *                      3- Delete button being pressed
      *                      3- Pressing the Cancel button.
      ********************************************************************* */
      public void actionPerformed( ActionEvent e )   {

         
      }

     /** *****************************************************
      *  DelClear() - is used to close the DeleteRec dialog.
      ******************************************************* */
       private void DelClear()   {
        
      }
   }
}
  
Figure 17: DeleteRec Class API




DeleteRec Class Method Summary
Method Description
DeleteRec() this constructor is used to create the GUI on the DeleteRec dialog. It
  1. Processes the input parameters
  2. Creates the labels and text fields
  3. Attaches event handlers to the buttons and the record if textfield.
actionPerformed() is used to respond to DeleteRec dialog GUI events. These events are:
  1. Enter key pressed with cursor in the recordID text field.
  2. Delete button being pressed
  3. Pressing the Cancel button.
DelClear() is used to close the DeleteRec dialog.


Linked List API

The Linked List class is depicted in the following outline and method summary.

  
/**************************************************************
 * File: LinkedList.java
 *
 * Methods:
 *    -  public LinkedList()
 *    -  public LinkedList(int n, LinkedList ln)
 *    -  public void add( int num )
 *    -  void addLast( int num)
 *    -  public void addFirst( int num )
 *    -  public void DisplayLL()
 *    -  void Remove(int num)
 *    -  public boolean isEmpty()
 *    -  public boolean contains( int num )
 *    -  public void toArray(int a[])
 *    -  public int getLast()
 *    -  public int size()
 *    -  public static void main(String args[])
 *
 ***********************************************************************/

public class LinkedList {


   /** **********************************************
    *  constructor
    *
    ************************************************ */
   public LinkedList() {
      
   }

   /** **********************************************
    *  constructor
    *
    ************************************************ */
   public LinkedList(int n, LinkedList ln) {
      
   }


   /** *************************************************
    *  sysPrint() - is used for debugging
    *               - set myDebug = true to turn on debugging
    *
    ************************************************ */
   public void sysPrint( String str  )   {
      
   }
   /** **********************************************
    *  Method: add( int num )
    *
    *  Purpose:  Adds a value to the list in sorted
    *  order.
    *
    ************************************************ */
   public void add( RandomAccessFile lFile, RandomAccessFile hFile,
                        Record NewNode ) {
      
   }

   /** **********************************************
    *  Method: addLast( int num )
    *
    *  Purpose:  Adds a node containing the value passed
    *  in num, to the end of the list.
    *
    ************************************************ */
   void addLast( RandomAccessFile lFile, RandomAccessFile hFile,
                        Record NewNode ) {
      
   }

   /** **********************************************
    *  Method: addFirst( int num )
    *
    *  Purpose:  Adds a value to the beginning of the
    *  list.
    *
    ************************************************ */
   public void addFirst( RandomAccessFile lFile, RandomAccessFile hFile,
                        Record NewNode ) {      

   }

   /** **********************************************
    * Method: DisplayLL()
    *
    * Purpose: Iterate through a non-empty linked list
    *          until all of the entries are displayed on
    *          the screen.
    *
    ************************************************ */
   public void DisplayLL( RandomAccessFile lFile, RandomAccessFile hFile ) {
      
   }

   /** **********************************************
    * Method: Remove(int num)
    *
    * The Remove function searches for a node
    * with Num as its value. The node, if found, is
    * deleted from the list and from memory.
    * 1. Check to see if the Linked list has entries.
    *    - If the Linked list is empty, then there is no
    *      further processing required.
    * 2. Check if the value we are seeking is in the first
    *    node in the Linked list.
    *    - Delete that node by making the value of next the
    *      new head.
    * 3. Start iterating through the Linked list until the
    *    value we are seeking is found.
    *    - Delete that node by removing its reference from
    *      the link.
    *
    ************************************************ */
   public void Remove( RandomAccessFile lFile, RandomAccessFile hFile,
                         int numID) {
      
   }

   /** **********************************************
    * Method: isEmpty()
    *
    * Purpose: Determine if the linked list is empty.
    *          Return:
    *              - true if linked list is not empty
    *              - false if linked list is empty
    *
    ************************************************ */
   public boolean isEmpty( RandomAccessFile hFile ) {
      
   }

   /** **********************************************
    * Method: contains( int num )
    *
    * Purpose: Determine if the linked list contains
    *          the passed parameter.
    *          Return:
    *              - true if linked list is not empty
    *              - false if linked list is empty
    *
    ************************************************ */
   public boolean contains( RandomAccessFile lFile, RandomAccessFile hFile,
                       int num ) {

      
   }

   /** **********************************************
    * Method: toArray(int a[])
    *
    * Purpose: Returns an array containing all of the
    *          elements in this list in the correct
    *          order.
    *
    ************************************************ */
   public int toArray( RandomAccessFile lFile, RandomAccessFile hFile,
                         String a[][] ) {

      
   }

   /** **********************************************
    * Method: getLast()
    *
    * Purpose: Return the last logical number in the linked
    *          list
    *
    ************************************************ */
   public Record getLast( RandomAccessFile lFile, RandomAccessFile hFile,
                            Record node ) {

      
   }

   /** **********************************************
    * Method: size()
    *
    * Purpose: Returns the size of the linked list.
    *          Return:
    *              - number in linked list if not empty
    *              - 0 if linked list is empty
    *
    ************************************************ */
   public int size( RandomAccessFile lFile, RandomAccessFile hFile ) {

   }  
}
  
Figure 18: Linked List API


Method Summary
Method Description
add(RandomAccessFile lFile,
RandomAccessFile hFile,
Record NewNode)
Adds a value to the Linked List in sorted order.
addFirst(RandomAccessFile lFile,
RandomAccessFile hFile,
Record NewNode)
Adds a value to the beginning of the list.
contains(RandomAccessFile lFile,
RandomAccessFile hFile,
int num)
Determines if the linked list contains the passed parameter.
DisplayLL(RandomAccessFile lFile,
RandomAccessFile hFile)
Iterate through a non-empty linked list until all of the entries are displayed on the screen.
getLast(RandomAccessFile lFile,
RandomAccessFile hFile,
Record node)
Return the last logical number in the linked list
isEmpty(java.io.RandomAccessFile hFile) Determine if the linked list is empty.
Remove(RandomAccessFile lFile,
RandomAccessFile hFile,
int numID)
The Remove function searches for a node with Num as its value.
size(RandomAccessFile lFile,
RandomAccessFile hFile)
Returns the size of the linked list.
sysPrint(String str) is used for debugging - set myDebug = true to turn on debugging
toArray(RandomAccessFile lFile,
RandomAccessFile hFile,
String[][] a)
Returns an array containing all of the elements in this list in the correct order.

Record API

In this section,the Record class will be presented in outline form and its methods summarized. The Record class outline follows below.
  
/** ***************************************************
 * File:  Record.java
 * 
 ***************************************************   */


/** *******************************************************************
 * class: The Record class' purpose is to read and write records to
 *        a randomaccess file.
 * *******************************************************************/
public class Record  {
   
   public Record() {
   }

   public Record( Record rec ) {
      
   }


   /** *******************************************************************
    *  Method: ReadRec() Reads a record from the specified RandomAccessFile.
    * 1- Read the first integer
    * 2- Read the second integer
    * 3- Read characters one at a time until we reach a string of
    *    ';;;'. This indicates that we have reached the end of the
    *    character string for this particular record.
    * 4- Load the resulting string into a StringTokenizer object.
    * 5- We are looking for 7 tokens, so if the token count is
    *    greater than 4, we will tokenize the string.
    * 6- The tokens are loaded into a string array and then into the
    *    class variables.
    ********************************************************** */
   public void ReadRec( RandomAccessFile file ) throws IOException
   {
      
   }

   /** ***************************************************************
    *  The fill() method is used to fill in the passed string with
    *  blanks.
    ***************************************************************** */
    public StringBuffer fill ( String str, StringBuffer buf ) {
       
   }


   /** ************************************************************
    *  write() Writes a record to the specified RandomAccessFile.
    *          1- First it writes a int (recid) to the output file
    *          2- Next it writes the quantity as an int.
    *          3- Then it writes the remaing record as a string.
    ************************************************************** */
   public void write( RandomAccessFile file ) throws IOException
   {      

   }

   /** ********************************************************
    * Method: getRecID() is used to obtain the record ID.
    ********************************************************/
   public int getRecID() { return recID; }

   /** ********************************************************
    * Method: getToolType() is used to obtain the tool type.
    ********************************************************/
   public String getToolType() { return toolType.trim(); }

   /** ********************************************************
    * Method: getToolDesc() is used to obtain the description of
    *         the tool.
    ********************************************************/
   public String getToolDesc() { return toolDesc.trim(); }

   /** ********************************************************
    * Method: getPartNumber() is used to obtain the Part Number
    *         value currently in the record.
    ********************************************************/
   public String getPartNumber() { return partNum.trim(); }

   /** ********************************************************
    * Method: getQuantity() is used to obtain the value of the
    *         quantity currently in the record.
    ********************************************************/
   public int getQuantity() { return quantity; }

   /** ********************************************************
    * Method: getBrandName() is used to obtain the value of the
    *         current value of Brand Name from the record.
    ********************************************************/
   public String getBrandName() { return brandName.trim(); }

   /** ********************************************************
    * Method: getCost() is used to obtain the the value of the
    *         current value of cost  from the record.
    ********************************************************/
   public String getCost() { return cost.trim(); }

   public int getNext() { return next ; }

   /** ********************************************************
    * Method: setToolType() is used to set the value of the
    *         current value of Tool Type from the record.
    ********************************************************/
   public void setToolType( String f ) { toolType = f; }

   /** ********************************************************
    * Method: setRecID() is used to set the value of the of the
    *         record ID in the record.
    ********************************************************/
   public void setRecID( int p ) { recID = p ; }

   public void setNext( int p ) { next = p ; }

   /** ********************************************************
    * Method: setCost() is used to set the value of the of the
    *         cost in the record.
    ********************************************************/
   public void setCost( String f ) { cost = f ; }

   /** ********************************************************
    * Method: setBrandName() is used to set the value of the
    *         brand name in the record.
    ********************************************************/
   public void setBrandName( String f ) { brandName = f; }

   /** *************************************************************
    * Method: setToolDesc() is used to set the value of the tool
    *         description in the record.
    ********************************************************/
   public void setToolDesc( String f ) { toolDesc = f; }

   /** ********************************************************
    * Method: setPartNumber() is used to set the part number
    *         in the record.
    ********************************************************/
   public void setPartNumber( String f ) { partNum = f; }

   /** ********************************************************
    * Method: setQuantity() is used to set the value of the
    *         quantity in the record.
    ********************************************************/
   public void setQuantity( int q ) { quantity = q; }

   /** NOTE: This method contains a hard coded value for the
    * size of a record of information. The value is arrived at
    * by adding up the size Java allocates to each data type
    * writeChars(String s)
    *   Writes every character in the string s, to the output stream, in
    *   order, two bytes per character.
    * The data Record is five strings of 45 characters each and two int
    * data types.
    *
    */
   public static int getSize() { return 462; }
}
Figure 19: Record class API


The method summary follows below.
Method Summary
Method Description
fill(String str, StringBuffer buf) The fill() method is used to fill in the passed string with blanks.
getBrandName() ) is used to obtain the value of the current value of Brand Name from the record.
getCost() is used to obtain the the value of the current value of cost from the record.
getNext()
getPartNumber() is used to obtain the Part Number value currently in the record
etPartNumber() is used to obtain the Part Number value currently in the record.
getQuantity() is used to obtain the value of the quantity currently in the record.
getRecID() is used to obtain the record ID.
getSize() NOTE: This method contains a hard coded value for the size of a record of information.
getToolDesc() is used to obtain the description of the tool.
getToolType() is used to obtain the tool type.
ReadRec(RandomAccessFile file) Reads a record from the specified RandomAccessFile.
setBrandName(String f) is used to set the value of the brand name in the record.
setCost(String f) is used to set the value of the of the cost in the record.
setNext(int p)
setPartNumber(java.lang.String f) is used to set the part number in the record.
setQuantity(int q) is used to set the value of the quantity in the record
setRecID(int p) is used to set the value of the of the record ID in the record.
setToolDesc(String f) is used to set the value of the tool description in the record.
setToolType(String f) setToolType() is used to set the value of the current value of Tool Type from the record.
write(RandomAccessFile file) Writes a record to the specified RandomAccessFile.

algorithm - a step-by-step procedure for solving a problem or accomplishing some end especially by a computer

DBMS - DataBase Management System.

inheritance - when a class is defined, any subclass that is defined can inherit the definitions (public and/or protected) of the parent/base classes.

Java API: Linked List - The following are the methods in the Java Linked List.

requirement - In this instance, a specification that documents the functions, performance, design constraints and attributes of a program to be delivered.

Template - is a unique class or pattern that can be used to build other software code.






[
HOME] Consulting Design Maintenance Project Testing Training Turnkey Java C++ SQL HTML JavaScript ]

2002 - 2011 All Rights Reserved Total Application Works