/
BusinessAcademy, Roskilde
Datamatician Course

Written Mandatory Assignment No. 3

In the subject

Software Construction

From:Wednesday1st June 2005 at 09:00 a.m.

To: Monday 6thJune 2005 at 08:20 a.m.

All kind of aids is permitted

(For a further description see the Guidelines for Course Work)

This Mandatory Assignment has the approximate weighting of

16 points

It is allowed to make one overall solution treating all questions together

Please check that this paper consists of 11 pages including the front page.

1Process Requirements

  • The work is a personal and individual work
  • Your teachers are not doing any supervising during the assignment period, as this is a test.

2 Product Requirements

  • Your project is to be documented in a report with a front page,some programs and some screen dumps. The report is made in MS-Word and the three programs in Netbeans.
  • Basically, theory must not be described. Put more emphasis on applying and programming. No critical approach to the methods you apply.
  • The report should contain:
  • Front page with the name of the class, name of student, date and assignment no.
  • Evaluation and Conclusion
  • How did you work? Alone or together
  • How good is the program? Explain what it can do or not do.
  • Did you learn anything?
  • SW-Construction in Appendix
  • Class Code printed from Netbeans with line numbers
  • Collection Code printed from Netbeans with line numbers
  • File Class Code printed from Netbeans with line numbers
  • GUI program codeprinted from Netbeans with line numbers
  • Screen dumps of the GUI, when the program is running

Assignment 3Fantasy Library Book(16 point)

You are to develop a Java program for the “FantasyLibrary”. Of course FantasyLibrary has many different kind of business, like lending, performances, exhibitions, purchase etc. etc.

But here we just look at the management and registrations of unlimitednumber of books, some simplefile handling, various inputs and print outs on the graphical based monitor/computer screen.

The program consists of 8 classes:

Book. The model class (the worker class) Book, which holds Book data and methods to carry out the calculations of prices, etc.

BookCollection. The collection class BookCollection which holds the Books and methods to add, find, remove a book as well as other methods. The student MUST base the BookCollection on the ArrayList class.

BookCollectionGUI. The GUI application class with the usual main method, handling the initialisation of an object of the class BookCollection,.offers a GUI-nterface to the user and responds to the user's choice by showing the output on the screen.

BookWriteFile. The Controller Management Class BookWriteFile, which manages the writing of Books from the Book collection to an output file.

BookReadFile. The Controller Management Class BookReadFile, which manages the reading of books from an input file into the Book collection.

BookSplitFile. The Controller Management Class BookSplitFile, which manages the splitting of books from an input file into a sale file and a normal file.

BookConcatenateFile. The Controller Management Class BookConcatenateFile, which manages the splitting of books from a collection file into a sale Book file and a normal file.

BookFileGUI. The GUI Application Class handling the the file administration of the book collection, offers a GUI-nterface to the user and responds to the user's choice by showing the output on the screen.

Where the first 3 classes are very similar to the solution to the former Mandatory Assignment 2. Note that this solution can be found on your teacher’s home page.

Turn to next page 

Mission

You are to have two GUI-classes. One major class BookCollectionGUI managing a book collection and resembling the following:

Notice the button “File Handling”.

When this button is clicked a new window BookFileGUI pops up resembling the following

In this window we are still working on the same book collection, handling some filing by utilizing the 4 file manager classes.

When clicking on the Button “Close Window” the window is closed and now BookCollectionGUI is active again.

This will now be explained more in details on the next pages.

Question 3a Controller Management Class BookWriteFile(2 point):

In order to handle the writing of books from a book collection to a file we need a class BookWriteFile resembling the template:

BookWriteFile

Data fields:

private BookCollection booksCol, a collection of books to be written

private String fileName, name of the output file

Constructor

BookWriteFile(BookCollection booksCol, String fileName)

Methods operating on the data fields

public void doIt()

Now create a class BookWriteFile with the mentioned data fields, the constructor and the method doIt():

-constructor

initializes the data fields: booksCol and fileName with the parameters.

-public void doIt()

Must catch exceptions and must use a FileOutputStream and an ObjectOutputStream.

Writes the number of books to the file.

Traverses the collection of books and write each object to the file.

Question 3b Main in the Management Class BookWriteFile(2 point):

In the main you must try to test the class by declaring an object of BokCollection using 3 objects of the Book class. In main show these constructions:

-declare and construct the object, booksCol ,of the class BookCollection

-declare and construct the 3 objects, b1, b2, b3, of the class Book

-add the these book-objects to the collection of books

-declare a file name

-declare and construct an object, cmc_WriteFile of the class BookWriteFile

-write the books to the file by calling the method cmc_WriteFile.doIt().

Check the folder and see if you can find the file.

Tip:

File names can be tricky if you want to write on H-drive. Use something like this:

Filename = “H:” + “\\” + “SW-Construction” + “\\” + “Solutions” + “\\” + “book.data”

Question 3c GUI Presentation Class BookFileGUI(2 point):

In Netbeans create a Java GUI class BookFileGUI like this:

As you can see there are four JButton (writeButton, readButton, splitButton, concatButton), one JLabel (dataLabel) and one JTextArea (dataArea).

What you cannot see is that a JScroolPane is assigned to each JTextArea. Remember to do this..

Now extend it with the following data fields

BookCollection booksCol

Book b

And the following constructor and methods:

public BookCollectionGUI(BookCollection booksCol)

Initialises the components (i.e. initComponents)

Initialises the data field with the parameter.

public void writeBooksToFile()

Reads in a file name from the screen. Declares and construct an object, cmc_WriteFile of the class BookWriteFile and write the borrowers to this file by calling the method cmc_WriteFile.doIt().

Must be called when the writeButton is clicked.

public void closeWindow()

Disposes the window

Must be called when the closeButton is clicked.

Question 3d Controller Management Class BookReadFile(1 point):

In order to handle the reading of books from a file into a collection of books we need a class BookReadFile resembling the template:

BookReadFile

Data fields:

private BookCollection booksCol, a collection of books to be constructed

private String fileName, name of the input file

Constructor

BookReadFile(BookCollection booksCol, String fileName)

Methods operating on the data fields

public void doIt()

Now create a class BookReadFile with the mentioned data fields, the constructor and the method doIt():

-constructor

initializes the data fields: books and fileName with the parameters.

-public void doIt()

Must catch exceptions and must use a FileInputStream and an ObjectInputStream.

Reads the number of books from the file.

Traverses the file and add each object to the book collection.

Question 3e GUI Presentation Class BookFileGUIextended(1 point):

Extend the class BookFileGUI with the following method:

public void readBooksFromFile()

Reads in a file name from the screen. Declares and construct an object, cmc_ReadFile of the class BookReadFile and read the books from this file by calling the method cmc_ReadFile.doIt().

Shows the books read in in the JTextArea

Must be called when the readButton is clicked.

Question 3f Controller Management Class BookSplitFile(3 point):

When a book becomes too old it must be stored in a storage in the basement. This check is done category by category. Therefore the books in the book file are split into two files: a file for old books to be stored and a normal file for all the other books. In order to split a file into two files we need a new class BookSplitFile resembling the following template:

Datafields:

private String inputFileName, oldFileName, normalFileName

Constructor

BookSplitFile( String inputFileName,

String okldFileName,

String normalFileName)

Methods operating on the data fields

public void doIt(String bookCategory, int aYear)

Now create a class BookSplitFile with the mentioned data fields, the constructor and the method doIt():

-constructor

initializes the data fields with the parameters.

-public void doIt(String bookCategory, int aYear)

Reads the books from the input file and depending on the book category and if the year of the book is less than aYear it saves a book in a old book collection or an normal book collection. Finally it writes two collections to the two new files.

Question 3g GUI Presentation Class BookFileGUIextended(1 point):

Extend the class BookFileGUI with the following method:

public void splitBookFileInToFiles()

Reads in the file names from the screen. Also reads in the year limit and the book category. Declares and construct an object cmc_Split of the class BookSplitFile and transfer the books from the input file to the two files by calling the cmc_Split.doIt(bookCategory, aYear) method.

Shows the books to be stored in the JTextArea.

Must be called when the splitButton is clicked.

Question 3h Controller Management Class BookConcatenateFile(2 point):

This question is an open question; i.e. the student must take some independent decisions on how this implementation can be done.

The problem

Whe new books arrives they are first registered (using the normal create book in BookCollectionGUI) and saved in a special file NewBookData.

This file is to be concatenated with all the other books in the books.dat file.

Create a class BookConcatenateFile, which can handle the described functionality.

Extend the BookFileGUI with a method to handle this, when the concatButton is clicked.

Question 3i GUI Application class BookCollectionGUI(2 point):

In NetBeans create a Java GUI Form named BookCollectionGUI like:

As you can see there is a new Jbutton (fileButton). Note that the dataArea and dataAllArea are empty at starting point, whereas numberTextField shows 0 at starting point.

What you cannot see is that a JScroolPane is assigned to each JTextArea. Remember to do this..

Extend the class with a method:

public void fileHandling()

Creates and shows an object of the class BookFileGUI and transfers the collection of books by using the constructor BookFileGUI(BookCollectionGUI booksCol).

Must be called when the fileButton is clicked.

Side 1/11