Tutorial: Java Hardware Store II







To contact us



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

2002 - 2012 All Rights Reserved Total Application Works


  • Tell a friend about this site (copy and paste the following HTML page into a file (e.g., using Notepad).)
  • <html>
    <head>
    <title>How To Build a Calendar II </title>
    </head>
    <body>
    <a href="http://sumtotalz.com/TotalAppsWorks/HardwareStore/HW_Tutorial_II.html">
    How To Build a Hardware Store Inventory II program </a>
    </table>
    </body>
    </html>

Java Table of Contents

  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 Lists
  9. Linked List II
  10. Linked List III
  11. Linked List IV
  12. Hardware Store I
  13. Hardware Store II
  14. Hardware Store III
  15. Client/Server
  16. Client/Server II
  17. Client/Server III
  18. Client/Server IV
  19. Multithreaded Client/Server
  20. Multithreaded Client/Server II
  21. Multithreaded Client/Server III
  22. Basic Calculator II
  23. Planet Source
  24. Java Applications/Servers
  25. Servlets and JSP
  26. Free Java Source Code on the Web

Introduction

This tutorial is intended for Java programmers with some experience coding in Java. My experience has been that those persons who have not taken at least one semester in Java really struggle with the concept presented in this tutorial. This version is the same as the previous tutorial version with the new requirements added.

This tutorial shows how to build a bricks and mortar Java Hardware Store application using random-access to process the data file. This exercise is similar to the one I teach to second semester college Java students. For Java programmers with one to two years of experience, this should an interesting exercise. I am a proponent of designing before coding, so you should expect to see quite a bit of pseudocode in this tutorial.

This tutorial will take you through the steps of building a bricks and mortar hardware store application. Much of the code and logic that we will develop is provided in today's database management systems. However, for those who are not familiar with some of the logic used in file I/O, this will provide some very basic insights relative to how a DBMS works. The primary difference between this project and the previous one is that we will be adding a shopping cart view and the capabilty to create and print an invoice.

When you look at the following program requirements, it is obvious that the program is all about the data, how it is viewed and how it is manipulated. So let's proceed with the requirements before I give up the ending. No mystery gives up the ending in the first paragraph. So get out your pipes, violins, and magnifying glasses, as we prepare to "sleuth out" the solution. The clues for this mystery are presented in the section titled, "Requirements for an Application." A famous "sleuther" used to say, "Dr. Watson, the game's afoot."

Requirements for a Hardware Store Application

You are the owner of a hardware store and you need to keep an up-to-date inventory of the tools in stock. Write a program that initializes a random-access file hardware.dat to two hundred and fifty empty records. The program should allow you to:

  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;
  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. Add a shopping cart.
  10. Get Customer information
  11. Print an invoice which shows the customer selected items and the price for these items.
  12. The comments should be written in the style expected by javadoc.
    • javadoc style comments begin with /** and end with */.
    • For example, /** This is what a javadoc style comment looks like. */

Possible Approaches to Building an Application

When we look at the requirements (clues), a few items jump out at us.

  1. application - a program with a main() method
  2. views - ways to present the data
  3. inventory - implies persistent data
    • Data that is stored (written) to a storage device
    • Data that is retrieved (read) from a storage device
    • Means to manipulate (create, update, delete) the data

Over the years, I have seen various approaches to building an application. I will use the following simple approach. It combines a top-down and a bottom-up approach for getting to the solution. Templates allow us to solve this problem from a top down view. We will use a template for the application and one for the data.

   
/** this is a template for an application */

public MyApp extends JFrame {
   class level variables

   public MyApp() {
      ...
   }
 
   public static void main( String args[] ) {
      ...
   }

   private MyInner Classes() {
      ...
   }
}


and

/** this is a template for a file I/O class */ public MyRecord { class level variables public NewRec() { ... } public UpDateRec() { ... } public DeleteRec() { ... } public ReadRec() { ... } public WriteRec() { ... } public getVar1() { ... } public getVar2() { ... } public getVar3() { ... } public getVar_n() { ... } public setVar1() { ... } public setVar2() { ... } public setVar3() { ... } public setVar_n() { ... } }
Figure 1: Templates for applications and I/O class


There are several ways to design an application and a file I/O class. We will not explore those approaches for this tutorial. Some approaches put much of the application code in the main method. I prefer to put the code in the classes and keep the main() methods as simple as possible. This approach allows us to test classes as stand-alone classes and integrate them more easily into more complex applications. For instance, I would never create a menu bar in the main method. I would create the menu bar in the class constructor or in a method called from within the class constructor. For enterprise level applications, I prefer to create a Menu class that contains minimal capability and then use inheritance and method overriding to tailor the subclass to fit our needs. I'll leave it to the reader to modify the code to change the affected method to a class and then use inheritance. Some of the more advanced readers may want to consider using an interface instead of a class, when doing the modification.

Before proceeding with the top-down approach, we will go to the bottom-up approach and design our data. Let's consider the following attributes to describe each tool:

  • record ID
  • tool type - e.g. hammer
  • brand name
  • description
  • part number
  • quantity
  • price


I cheated a little bit on the data requirements. In reality, the customer should be the one telling us what type of data he wants in to see in the hardware.dat file. So, let's assume that he did provide the requirements. If the customer does not know what he wants to see, you should propose a couple of layouts and let him choose. You may want to take him on the Internet, so he can see what layouts other hardware stores are using. This will give him something on which to base his decision. Assume that the customer has chosen a layout and the template for a file I/O class looks like this.
  
/** this is a template for a file I/O class */

public MyRecord  {
   private int recID;
   private String  toolType;
   private String  brandName;
   private String  toolDesc;
   private String  partNum;
   private int     quantity;
   private long    toolCost;
  
   public NewRec() {
      ...
   }

   public UpDateRec() {
      ...
   }

   public DeleteRec() {
      ...
   }

   public ReadRec() {
      ...
   }

   public WriteRec() {
      ...
   }

   public getVar1() {
      ...
   }


   public getVar2() {
      ...
   }

   public getVar_n() {
      ...
   }

   public setVar1() {
      ...
   }

   public setVar2() {
      ...
   }

   public setVar_n() {
      ...
   }


}
   
Figure 2: Templates I/O class


The access method will be random-access, so we will not be building a relational data base system, which would be beyond the scope of this tutorial. The design point becomes, "Do we put all of the tool types in one table or a table per tool type?" The next sections consider various design points.

Design Points

When we use the word template, we should think of a cookie cutter. Using a cookie cutter, I can repeatedly cut out cookies that all have the same attributes of size and shape. With a programming template, you can repeatedly cut out similar style programs, classes, methods and/or algorithms. The key is that these templates should be of high quality and have been successfully used in other projects.

When we use the word design, we should think of an outline or several possible outlines. And when we think of the word design point, we should think of a feature or a requirement. Therefore, for the purposes of this tutorial, each requirement is a design point. Based on the above listed requirements, the design points for the hardware store are:

  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;
  4. Input the data concerning each new 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. The comments should be written in the style expected by javadoc.

Each design point can have several viable implementations. The key is to design the best implementation that works for a particular design point.

As I look closer at the requirements, it is obvious that I cannot complete the task because the requirements are too vague. At this point, I go back to the customer for clarification. After one or more discussions, we come up with:

  1. Write this program as an application.
  2. The application should use a menu bar and menu items to show the various options.
    File View Options Help About
       Exit
    •    Bench Power Tools
    •    Portable Power Tools
    •    Power Tool Accessories
    •    Hand Tools, Carpentry
    •    Hand Tools, General Purpose
    •    Mechanics Tools
    •    Tool Sets
    •    Wet-Dry Vacs
    •    Storage, Chests & Cabinets
    • List All
    • --------
    • Add
    • Update
    • --------
    • Delete
    Index

  3. Input the data concerning each new tool;
  4. Delete a tool that you no longer carry;
  5. Update information on any tool that you carry;
  6. List all of the tools in your inventory;
  7. Present views for the various categories (e.g. lawn mowers) of tools that you carry.
  8. The comments should be written in the style expected by javadoc.

At this point, I would use the application template to prototype the GUI. Allowing the customer to see an example of what he is requesting will save time spent arguing over what he really wanted later on in the development cycle.

Design Point One: Scalability and Extensibility

In today's environment, many businesses start off as just a "brick-and-mortar" business (a business that has a physical location, as opposed to an virtual or online presence). The inference is that we may start off with a physical hardware store and later on, we may decide to create an online store to work in conjunction with the physical store. As we design this program, we should design a program that can "go from a scooter to a race car without growing warts." What this means is that if the design does not allow for the possibility of a greater workload and/or added functionality, we end up with a program that is usually error prone.

Our program design should allow for scalability, which means an increase in volume. If you visit a "Ma and Pop" store, there is probably just one cash register/program accessing the data file. However, if you visit a home improvement store, you will note that there may be ten to twenty cash registers and/or displays, which all are capable of accessing the data. A hardware store is a hardware store, so our design should allow for the growth from one to twenty.

Another point to consider: what happens when simultaneous accesses to the data are occurring? How does the programmer protect against data corruption? Data corruption occurs when the same data is being changed at the same time. The key, in this case, is the capability to read a file for read-and-update. The read-and-update function on a file is a lock that allows one requester at a time to access (write to) a file. Multiple simultaneous accesses implies multi-threading and perhaps a client-server application.

Our application design should allow for extensibility and scalability so we can modify our program at some future date to make it a multi-threaded client-server application. For this tutorial, our application will be single-threaded and it will only have to accommodate one file access at a time. However, proper use of classes and objects will allow for easier modifications to handle scalability issues in the future. Clue: Classes consist of attributes (data) and behaviors (methods). Don't try to embed multiple behaviors in a single method.

Design Point Two: Adding a Menu

Design Point: The application should use a menu bar and menu items to show the various options.

I like to add a call to a setupMenu() method from the MyApp() constructor and an inner class to handle the events resulting from the menu. The pseudocode for the setupMenu() method is as follows:



   
/** this is a template for an application */

public MyApp extends JFrame {
   class level variables

   public MyApp() {
      ...
     /** Call the setupMenu() method to create the menubar 
      *  Menu and menu items */

      setupMenu() ;
   }
 
   public setupMenu() {
       /** Create the menubar */
      

      /** Add the menubar to the frame */
      

      /** Create the File menu and add it to the menubar  */
      
      /** Create the Edit menu and add it to the menubar  */

      /** Create the View menu and add it to the menubar  */

      /** Create the Help menu and add it to the menubar  */

      /** Create the About menu and add it to the menubar  */
   }
 
   public static void main( String args[] ) {
      ...
   }

   private MyInner Classes() {
      ...
   }

   class MenuHandler implements ActionListener {
      public void actionPerformed( ActionEvent e )  {

         
      }
   }
}

   

Figure 3: Pseudocode for the setupMenu() method


Design Point Three: Views and a Shopping Cart

Views are ways to see or present data. We could use a listbox to present the data. Listbox's are useable when we want to present n rows and one column. However, if we want to present n rows and m columns, we should prefer using a JTable. With a JTable, we can build an application as complicated as a spreadsheet application, where we can edit each cell. Our application is not going to be as complicated as a spreadsheet application. We want to restrict who can update the data; therefore, making all of the cells not-editable will help in making the data more secure.

The JTable is a very powerful class. JTable has several constructors that you can use; however, there are two that we will consider for this tutorial.

  
JTable(int numRows, int numColumns)
          Constructs a JTable with numRows and numColumns 
           of empty cells using the DefaultTableModel.

JTable(Vector rowData, Vector columnNames)
          Constructs a JTable to display the values in the 
            Vector of Vectors, rowData, with column names, 
             columnNames.
  
Figure 4: JTable constructors


Since one of the requirements indicates that the size of the data file will contain 250 entries, first glance might lead one to believe that an array of type int will suffice. However, this may be a disinformation ploy perpetrated by Professor Moriarity. As we build this application, we must constantly consider scalability. If we use the JTable(int numRows, int numColumns), every time the file entries exceeded the array capacity we would have to recompile. This would be necessary because arrays are fixed size. When the number of entries in the data file exceed the size of our array, we have to recompile to allocate more space to our array. Making a change to a small application and recompiling is not catastrophic; however, when are making small changes to an enterprise level application, the cost could be prohibitive. Think Y2K!

The JTable(Vector rowData, Vector columnNames) shrinks and grows, which is not like the array that is fixed in size. This would appear to be the correct choice. At this point, let me throw you a curve ball. For our application, we will use the following constructor:

  
JTable(Object[][] rowData, Object[] columnNames)
          Constructs a JTable to display the values in the 
           two dimensional array, rowData, with column names, 
            columnNames.
  

where the Object[][] rowData will be

String[][] rowData = new String[ 250 ] [ 7 ] ;
 


and our ReadRec() method will look something like:

 /**
    * Read a record from the specified RandomAccessFile
    */

   public void ReadRec( RandomAccessFile file ) throws IOException
   {
      char f[] = new char[ 45 ];
      StringTokenizer tokens ;
      StringBuffer buf1  = new StringBuffer("");

      recID = file.readInt();

      quantity = file.readInt();

      for ( int i = 0; i < f.length; i++ ) {
         f[ i ] = file.readChar();
         if ( !Character.isLetterOrDigit( f[ i ] ) )
             f[ i ] = ' ' ;
      }
      toolType = new String( f );
      toolType = toolType.trim() ;

      for ( int i = 0; i < f.length; i++ ) {
         f[ i ] = file.readChar();
         if ( !Character.isLetterOrDigit( f[ i ] ) )
             f[ i ] = ' ' ;
      }
      brandName = new String( f );
      brandName = brandName.trim() ;

      for ( int i = 0; i < f.length; i++ ) {
         f[ i ] = file.readChar();
         if ( !Character.isLetterOrDigit( f[ i ] ) )
             f[ i ] = ' ' ;
      }
      toolDesc = new String( f );
      toolDesc = toolDesc.trim() ;
      tokens =  new StringTokenizer( toolDesc, "?") ;
      while (tokens.hasMoreTokens()) {
         buf1.append( tokens.nextToken() ) ;
      }
      toolDesc = buf1.toString() ;

      for ( int i = 0; i < f.length; i++ ) {
         f[ i ] = file.readChar();
         if ( !Character.isLetterOrDigit( f[ i ] ) )
             f[ i ] = ' ' ;
      }
      partNum = new String( f );
      partNum = partNum.trim() ;

      for ( int i = 0; i < f.length; i++ ) {
         f[ i ] = file.readChar();
         if ( !Character.isLetterOrDigit( f[ i ] ) )
             f[ i ] = ' ' ;
      }
      cost = new String( f );
      cost = cost.trim() ;
   }

Figure 5: JTable and ReadRec class


where file is declared as RandomAccessFile file; Some of the advanced Java programmers will realize that we could have performed:

MyRecord record;

record.read ( file ) ;


When we get the application working, we may consider modifying it to make the code more efficient.

The Object[] columnNames will be


String[] columnNames [] = {"RecordID", "ToolType", "BrandName", 
                           "ToolDescription", "PartNumber", 
                            "Quantity", "Price"} ;  


How do we put it together? The code for constructing and filling a JTable will look something like this.


 public ListRecs( RandomAccessFile f , String p_Data[] [] ,
                       HardwareStore hw_Store ) {
      super(  new Frame(), "List All Records", true );


      cancel = new JButton( "Cancel" );
      cancel.addActionListener( this );
      data = new Record();
      pData = new String [ 250 ] [ 7 ] ;
      hwStore = hw_Store ;


      pData = p_Data ;

      try {
         loopLimit = f.length() ;
         while ( ii <  ( (int)loopLimit )  ){
             f.seek( ( ii ) * data.getSize() );
             data.ReadRec( f );

             if ( data.getRecID() > 0 && data.getRecID() < 251
                    &&   !data.getToolName().equals( "" )  ) {
                pData[ iii ] [ 0 ]  =  String.valueOf( data.getRecID() ) ;
                pData[ iii ] [ 1 ]  =  data.getToolName().trim()  ;
                pData[ iii ] [ 2 ]  =  data.getBrandName().trim()  ;
                pData[ iii ] [ 3 ]  =  data.getToolDesc().trim()  ;
                pData[ iii ] [ 4 ]  =  data.getPartNumber().trim() ;
                pData[ iii ] [ 5 ]  =  String.valueOf( data.getQuantity() ) ;
                pData[ iii ] [ 6 ]  =  data.getCost().trim()  ;

                iii++;
             }
             ii++ ;
         }
      }
       catch ( IOException ex ) {
            //partNum.setText( "Error reading file" );
      }

      table = new JTable( pData, columnNames );

      table.addMouseListener( new MouseClickedHandler( f, table , pData ) ) ;

      JScrollPane scrollpane = JTable.createScrollPaneForTable( table ) ;
      add( scrollpane ) ;

      add( cancel , BorderLayout.SOUTH);
      setSize( 600, 300 );
      setModal( false ) ;
   }

Figure 6: Constructing and filling a JTable


The pData array is loaded using contiguous locations. JTable tends to provide unpredictable results if the pData array has empty rows.

In the past, when I built a shopping cart, it looked something like this:

  • item 1
  • item 2
  • item 3
  • item ...
  • item n
Add ->

<- Remove 
  • item a
  • item b
  • item c
  • item ...
  • item m


However, in this case we will use an algorithm similar to the one we used for the "views". As the user selects items, we will add these items to a buyData array and use that array as a parameter in

   
JTable(int numRows, int numColumns)
          Constructs a JTable with numRows and numColumns 
           of empty cells using the DefaultTableModel.

JTable table = new JTable( buyData, columnNames );

 


Design Point Four: Add, Update, Delete, Buying Item, and Customer Information

Design Points:

 
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;
 

What vehicle can we use that will allow the user to Add, Update, or Delete items from the data file. We can use JLabels and JTextfields on a JPanel, Dialog or a JTabbedPane. Before we start pseudocoding our approach, we need to consider whether we need to password protect access to our business data. Not password protecting the business data is comparable to leaving the cash register drawer open and loaded with money in front of the store; it is an invitation for a malicious situation. Business data should always have restricted access. With that in mind, we need to also use JPasswordField. The concept we will use is every time someone wants to add, update, or delete a hardware item a modal dialog will be displayed. If the user enters a valid userID and password, then the application will display a modal Add, Update, or a Delete dialog.

The logic for the Buying Item Dialog is similar to the logic used in the Add and Update dialogs.

Design Point Five: Password Dialog

When we consider the password dialog, we should consider a two-column design. The left column should contain the instructions for entering data, and the right column should contain the text entry fields (JTextFields). In addition, we will add an enter and a cancel button to this dialog. We will need to use layout managers to manage the columnar layout and the positioning of the buttons.

A GridLayout manager is useful in managing columnar data. The constructor we will use looks like:

 
A GridLayout(int rows, int cols)
 
The GridLayout manager creates a grid layout with the specified number of rows and columns. Our password dialog might look like:

           Password dialog            
Enter your userID  
                 
Enter your password 
                 
Enter 
Cancel

We will create two JPanels, and on one (mainPanel) will add the JLables and JTextFields, using a GridLayout manager. On the other JPanel (buttonPanel), we will add the JButtons. Next we use the BordeLayout to add the mainPanel to the center of the dialog, and the BordeLayout to add the buttonPanel to the bottom of the dialog. The code looks something like:

 
class PassWord  extends Dialog
         implements ActionListener {   

   public PassWord(  ) {

      super( new Frame(), "Password Check", true );      

      enter = new JButton( "Enter" );
      cancel = new JButton( "Cancel" );

      buttonPanel = new JPanel() ;
      mainPanel   = new JPanel() ;
      mainPanel.setLayout( new GridLayout( 3, 2 ) );
      add( mainPanel , BorderLayout.CENTER) ;

      /** add the labels and text fields to the main panel */
      mainPanel.add( userIDLabel );
      mainPanel.add( userID );
      mainPanel.add( passwordLabel );
      mainPanel.add( password );

      buttonPanel.add( enter ) ;
      buttonPanel.add( cancel ) ;
      add( buttonPanel , BorderLayout.SOUTH);

      /** add the actionlisteners to the buttons */
      enter.addActionListener( this );
      cancel.addActionListener( this );

      setSize( 400, 300 );

   }

Please note that this code is incomplete.
 
Figure 7: PassWord class


The logic used in the Password dialog is similar to the logic that we will use for the Add, Update, and Delete dialogs.

Design Point Six: Using ActionListeners

ActionListeners allow the program to respond to user-initiated events. These events could be the pressing of a button, pressing a menu item, entering data in test field, etc. In such cases, the program is designed and coded to take some action. The primary purpose of GUI applications is to wait for some user initiated event.

In the previous section, you will note the following code.

 
/** add the actionlisteners to the buttons */
      enter.addActionListener( this );
      cancel.addActionListener( this );
  


The purpose of this code is indicate to the JVM that when the enter or cancel buttons are pressed, this class will respond to the event. The psuedocode for the ActionListener looks like:
 
class PassWord  extends Dialog
         implements ActionListener {

   code...

   /**
    * This method responds to the enter or cancel button
    *  being pressed on the Password dialog.
    */
   public void actionPerformed( ActionEvent e )    {
      if ( e.getSource() == enter ) {
         response code
      }
      else {
         respond to the cancel button being pressed
      }
   }

   code...
}
 
Figure 8: Psuedocode for the ActionListener


Design Point Seven: Creating an Invoice

What do we need to do to create an invoice? What is an invoice? An invoice is

    an itemized list of goods shipped or services rendered, stating quantities, prices, fees, shipping charges, etc.; bill
Therefore, we need to create an itemized list of goods and prices. To accomplish the task, we will use code similar to the following:

 
FileOutputStream fos = new FileOutputStream ( pathname );
ObjectOutputStream oos = new ObjectOutputStream ( fos );
oos.flush();
fos.flush();
oos.writeChars ( "<html>" );
 


What we will do is create a HTML file and use one of the browsers to display it.

Putting It All Together

Even though have shown you some code, you should have not tried to do any coding yourself. You should be working only with pseudocode. My high-level psuedocode looks like:

 
public class HardwareStore extends JFrame
          implements ActionListener {

   public HardwareStore()   {

      setupMenu();
      setup();
   }

   public void actionPerformed( ActionEvent e )
   {
      
      cleanup();
   }

   public void cleanup() {
      
   }

   public void displayDeleteDialog() {

   }


   public void displayUpdateDialog() {

   }

   public void displayAddDialog() {

   }

   public void setEntries( int ent )   {

   }

   public String getPData( int ii , int iii )   {

   }

   public int getEntries(  )   {

   }

   public static void main( String args[] )
   {

   }


   class MenuHandler implements ActionListener {
      public void actionPerformed( ActionEvent e )  {

      }
   }

   
   class WindowHandler extends WindowAdapter {
      HardwareStore h;

      public WindowHandler( HardwareStore s ) { h = s; }

      public void windowClosing( WindowEvent e ) { h.cleanup(); }
   }
}

class PassWord  extends Dialog
         implements ActionListener {
  

   public PassWord( HardwareStore hw_Store ) {
      
   }

   public void displayDialog ( String which_Dialog ) {

   }

   
   public void actionPerformed( ActionEvent e )    {

   }

   private void clear()    {

   }

}
class ListRecs extends Dialog
         implements ActionListener {


   public ListRecs( RandomAccessFile f , String p_Data[] [] ,
                       HardwareStore hw_Store ) {

   }

   public ListRecs( HardwareStore hw_Store , String str,
                    String strTitle ) {

   }
}

class MouseClickedHandler extends MouseAdapter {


   MouseClickedHandler( RandomAccessFile fPassed , JTable tablePassed ,
                    String p_Data[] []) {


   }

   public void mouseClicked( MouseEvent e )    {

   }
}

class UpdateRec extends Dialog
         implements ActionListener {


   public UpdateRec( RandomAccessFile f , String p_Data [] [], int iiPassed)
   {

   }

   public void actionPerformed( ActionEvent e )
   {

   }

   private void clear()
   {

   }
}

class NewRec extends Dialog
        implements ActionListener {


   public NewRec( HardwareStore hw_store, RandomAccessFile
                     f, JTable tab,  String p_Data[] []  )
   {

   }

   public void actionPerformed( ActionEvent e )
   {
      
   }

   private void clear()
   {

   }
}

class DeleteRec extends Dialog
          implements ActionListener {


   public DeleteRec( HardwareStore hw_store,  RandomAccessFile f,
                   JTable tab, String p_Data[] []  )
   {
      
   }

   public void actionPerformed( ActionEvent e )   {
      
   }

   private void clear()   {

   }
}

class BuyRec extends Dialog
         implements ActionListener {
}

class ShoppingCart extends Dialog
         implements ActionListener {
}

class Customer  extends Dialog
         implements ActionListener {
}

and 


public class Record  {
 
   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 a record to the specified RandomAccessFile
    */
   public void write( RandomAccessFile file ) throws IOException
   {

   }

   public int getRecID() { return recID; }

   public String getToolName() { return toolType.trim(); }

   public String getToolDesc() { return toolDesc.trim(); }

   public String getPartNumber() { return partNum.trim(); }

   public int getQuantity() { return quantity; }

   public String getBrandName() { return brandName.trim(); }

   public String getCost() { return cost.trim(); }

   public void setToolName( String f ) { toolType = f; }

   public void setRecID( int p ) { recID = p; }

   public void setCost( String f ) { cost = f; }

   public void setBrandName( String f ) { brandName = f; }

   public void setToolDesc( String f ) { toolDesc = f; }

   public void setPartNumber( String f ) { partNum = f; }

   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
    */
   public static int getSize() { return 233; }
}
 
Figure 9: Putting it all together


The code provided violates some structured programming rules. I leave it to the reader to find and fix them.

Definitions

random-access - When you access an array, you use an index or subscript to access a particular element. Similarly, you can access a rand-access file. A random access file behaves like a large array of bytes stored in the file system.

DBMS - DataBase Management System e.g. Oracle.

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.

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











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


To contact us

2002 - 2012 All Rights Reserved Total Application Works