Unit 41 Programming in Java Sample Assignment

Programming in Java Assignment

Unit 41 Programming in Java Sample Assignment

Task 1: Understands the principles of programming in Java

1.1 Briefly list and discuss three main features of programming in Java

Solution:

Java is a very powerful programming language which provide functionality for developing applications that can target multiple platforms and to create highly customizable features. Following features are provide by Java:

  1. Platform Independent: Java is platform independent language. Program written in Java can execute on variety of machines which support JRE (Java Runtime Environment). Java follows the principal write once and run anywhere thus programs using Java can be run on different platforms without making any changes.
  2. Easy to adapt: Java programming language is simple and easy language to adapt. It provides clear and easy to understand syntaxes that can be understood and learn easily.
  3. Security: Java programming language enable developer to implement high security features for users. JRE also checks for security of an application for example Applets which can run on any browser that support java, are not allowed to access hard disk to prevent unwanted access of user data that can be confidential to enhance user data security.

Java programming language provide many feature to the programmers and there are many more features of java programming language. It serves a very wide range of features to its developers. Following are other features of Java:

  • Object Oriented Programming.
  • Multithread Application Support to utilize full performance of CPU.
  • Provides API’s for distributed applications.
  • Automatic garbage collection to remove and release memory from unused objects and object pooling to enhance application performance.
  • Can be used to develop a variety of application like Console Applications, Desktop Applications, Web and Mobile Applications.

1.2 What do we mean by BYTECODE and JVM in Java and thus discuss the environmental flexibility of programming in Java?

Solution:

Java says write once and run anywhere so when we create a program in Java and then compile the java program source, instead of generated specific machine targeted code the java compiler generates BYTECODE. The BYTECODE that java compiler generates is platform independent i.e. it can be executed on a variety of machine which has Java Runtime Environment installed on it. This BYTECODE is executed by a program called Java Virtual Machine which is a part of Java Runtime Environment.
The Java program source file has the extension .java and the BYTECODE file which is generated by Java compiler after successful compilation of the java program source file has the extension .class. We can have multiple classes in a java program source file but best practice is to create individual java source file for each class that we want to design for our application usage. The BYTECODE file which has the .class extension is generated for each class and has the classname.class name format. This file is automatically generated by the Java Compiler after the successful compilation of code.
The Java Virtual Machine uses .class file which contains BYTECODE to execute the java programs. JRE has a compiler called JIT (Just-In-Time) compiler which is responsible to converts the BYTECODE targeting the platform in which it is executing.

Task 2: Design Java solutions

2.1 Design a Computing programming assignment  solution to the rental system by using use-case diagrams that show interaction of user with the system.

Designing of Java Programming Solution: A system has been designed for CD/DVD rental system. Two type of user can use the system.

  1. Administrator
  2. General User or Customer

To use the system there is login functionality for user which decides the type of user as administrator or as a customer.
Is the user is an administrator then he/she can perform the tasks that are decided for administrator like:

  1. Add New Customer
  2. Update Existing Customer
  3. Delete Existing Customer
  4. Add a CD/DVD
  5. View all CDs/DVDs
  6. Update Existing CD/DVD
  7. Remove Existing CD/DVD

If the user is a customer then he/she can perform the tasks that are decided for the customer as following:

  1. View all Existing CDs/DVDs
  2. Rent any CD/DVD
  3. Returning any Rented CD/DVD

Admin Use Case Diagram
Unit 41 Programming in Java Sample Assignment

User Use Case Diagram
Unit 41 Programming in Java Sample Assignment

 

2.2 Identify the components and file structures required to implement the rental system.

Components: In the system requirements, the CD/DVD Rental System can be divided into 3(three) components:

  1. CD/DVD Item: In the “CD/DVD Rental System” it is required to save information about CDs and DVDs available in the store. To have an integrated format we have created an Interface by name “BasicItem”. It defines base functionality for the item. CDItem and DVDItem classes implement BasicItem interface in order to provide functionality.
  2. Users for application: There are two types of the users in the application. One admin and another one a general customer. User class in the CD/DVD rental system stores user information.
  3. Data Storage: Data storage is required to save data permanently. So it is one of the necessary components in the system. DataStorageUtility class provides functionality for data storage.

Since we are instructed to use only text files to store the application data, I decided to create different text files to store item information, User login information and information about the rented items for every user.
Here are the description of files created by the application:

  • users-of-application.txt:- This file is used to store information about the application users. It stores user’s information in semi-colon separated format and single user per line.

 Structure for this file is as follows:
user-id;password;user-name;mobile-number;is-special-customer;credit-limit.
Unit 41 Programming in Java Sample Assignmnet
collection-cd-dvd.txt:- This file is used to store information for all available items in the store i.e. CD or DVD. It stores information in semi-colon separated format and single item information per line.
Format for this file is as follows
movie-title; item-price; item-quantity; movie-category; item-type
Unit 41 Programming in Java Sample Assignment
Rented-Items-[Username].txt:- This file is used to store the information of items those were taken on rent by a user. A separate file is created for each user who is using this application to take items on rent and file name is same as the username of the user. It stores information in semicolon separated format with one item information per line.

Unit 41 Programming in Java Sample Assignmnet
(Figure: Sample rent data for user adminuser. Rented-Items-adminuser.txt)

 

2.3 Use UML class diagrams to show the classes in your system, attributes and operations of each class and the relationship between classes. Define clearly each class, main methods and properties

BasicItem Interface: To provide similar behavior for all items we designed an interface named BasicItem. It provides basic characteristics and behaviors of an item available in the application. It abstracts behaviors of items which must be implemented by all the item classes.
UML classes
CDItem class: It is a sub class of BasicItem. It provides functionality for the item “CD”in the applicaiton. It defines some basic properties for CD Item. These are:

  1. itemName
  2. itemCategory
  3. itemType
  4. itemQuantity
  5. itemPrice

DVDItem class: It is a sub class of BasicItem. It provides functionality for the item “DVD”in the application. It defines some basic properties for DVD Item. These are:

  1. itemName
  2. itemCategory
  3. itemType
  4. itemQuantity
  5. itemPrice

SearchItemDialog class: it displays an item selection dialog to select items for update or remove.

jDialog Programming in Java Sample Assignment

AppLoginDialog Class: It displays login dialog to the user. All users must logged in before using the application.

app login

MyItemsPanel Class: This class is used to display current rented items of a particular user.

my items

DataStorageService Class: It provides functionality to read and write information to or from persistent storage i.e. hard disk. It defines some static methods to store application data in text files as semicolon separated values with single value per line.

data storage

RentedItem Class: It represents an item which is rented by the user.

rentedltem class

AppUser Class: It stores information about application users such as their name, username, password, mobile number, credit limit etc.

app user classes

MyAddEditItemPanel Class: It displays an interface for addition and update of an item to admin user.

MyAddEditItemPanel Class

MyCustomerPanel Class: This class displays an interface for addition and update of a customer to the administrator.

MyAddEditItemPanel Class

SearchUserDialog Class: It displays a user selection dialog to the administrator for update and removal of users.

SearchUserDialog Class

Task 3: Implement Java solutions

3.1 Implement the CD/DVD rental system solution based on your design.

I have implemented the “CD/DVD Rental System” based the design described above. Inheritance hierarchy is used wherever possible to implement classes. BasicItem interface is defined to specify similar functionality for all items. It defines basic behaviors for the items available on the store.

Code Screen Shot form BasicItem.java:

Implement Java solutions

Here:

GetItemName() and SetItemName() methods are used to get and set name of item (Cd/Dvd).
GetItemCategory() and SetItemCategory() methods are used to get and set category of the item.
GetItemPrice() and SetItemPrice() methods are used to get and set price of the item.
GetItemQuantity() and SetItemQuantity() methods are used to get and set quantity of the item.
GetItemType() method is used to get type of the item whether item is a CD or DVD.

3.2 Implement classes using inheritance relationship.

After defining the BasicItem interface we have created two more classes implementing this interface the CDItem class and DVDItem class.

CDItem.java: It is the subclass of BasicItem interface. This class defines the basic behavior and properties of item CD.

Code screen shot from CDItem.java

Code screen shot from CDItem

DVDItem.java: It is also a subclass of BasicItem interface. This class defines the basic behavior and properties of item DVD.

Code screen shot from DVDItem.java

Code screen shot from DVDItem

We have also created some classes using inheritance hierarchy for user interface from javax.swing package.

javax.swing package

3.3 Use methods and attributes in different classes using instances/objects.

            In Object Oriented Programming (OOP) to access the methods and fields of any call we use object or instance of the class. In the application there are many classes created for various components. So access the method of these classes we have used the instance of the class.

            Instances/Objects of these classes are created in “MainFrame.java” (Main class) file. Main is starting point for this application because of main method. Main is the subclass of the JFrame class of the swing package to generate a user interface of application.

MainFrame.java

This main class uses the method and fields of other classes so this class also has the instance or objects of these classes.

Displaying Login Dialog for user authentication:
applogindilog

creating objects

mycustomer panel

Instance creation and method calling in SearchItemDialog class

SearchItemDialog class

3.4 Identify and implement opportunities for error handling and reporting

Testes are performed after the basic functionality of the CD/DVD Rental System. The application is tested against the user input. I have checked the application for invalid input or empty input values or if the values inputted are not in expected format. Application checks form input and display errors in the application.
After the tests I have found following for error handling and reporting:

1. Data Files does not Exist: While testing the application I found the application terminate by the error it the data file doesn’t exist and my application try to open it. To resolve this issue I implemented a check before processing the file. I made a check for the existence of file and it the file doesn’t exist it will be created.
2. Invalid values in files: While developing the application I found the data was not properly formatted or sometimes not being written in the data files. I made a cross check in the code to remove the error and after that the above mentioned problem is resolved.

3.5 Make effective use of an Integrated Development environment (IDE) including code and screen templates.

The application is developed in NET Beans IDE because IDEs are helpful in code writing and managing the files more easily.
It is helpful for us to create derived classes for the existing classes also. For example if we want to create a derive class from an existing class that java provided. It will automatically generate basic functionality for the class like the constructor. If we want to override a base class method then the basic structure of the function is generated.
In the application “CD-DVD Rental System” I have used Net Beans and its code templates and screen templates are used to generate the application functionality.

Task 4: Test and document Java solutions

4.1 critically review and test your solution. Show screen shots of tests in your discussion.

The testing phase of the application is to test our application about the various inputs that users are going to provide and validate them, and to check about the expected output of the application that the application is going to generate.

  • I have tested it on following criteria:
  • Input validation
  • Authentication of users
  • Information stored in files.
  • Authorization to perform various task

The application checks and performs all validation on the forms when user use the application.

Following images shows the message that will be generated when user is trying to login without providing the valid credentials.

Error on login screen

Error on login screen

Following image shows the message to the user if he//she get and extra discount on items

Discount message to user

Discount message to user

The application has one administrator and this user have all rights. Below image shows the message displayed when administrator tries to create new user without providing valid details

Error message on user creation screen

Error message on user creation screen.

4.2 Analyze actual test results against expected results to identify discrepancies. Show this in a verification table.

verification table

Below are some of screen shots of application to showcase the test results:

Message of successful user creation

Message of successful user creation

Message of successful user creation

Message when user gets a discount based on conditions defined in application

4.3 evaluate independent feedback on your solution and make recommendations for improvements

  • Case 1:  Initially when the application was designed the applicant was displaying the same dialog box pop up for each and every action that is not a good design.
  • Solution: During testing phase, I observed this error and fixed this with appropriate message dialog to distinguish the error message and success message.
  • Case 2: During testing I found that the list of items are not generated in the application frame. It was not display all the items stored in the files.
  • Solution: I rechecked the code and fixed this issue so that the list of items are properly generated to the users.
  • Conclusion: After fixing of these problems, I found no other bug in the code it is working perfectly as per the assignment requirement.

4.4 create user documentation for the solution

Application flow:

  1. User Starts the application
  2. normal user or admin user
  3. If user is admin, it can do following operations:
    1. Add new item
    2. Remove old item
    3. List all items
    4. Search items
    5. Create new customer/user
    6. Update existing customer/user
    7. Remove old customer/user
  4. If user is normal user,  it can do following things:
    1. List all available items
    2. View details of specific item
    3. Search available items
    4. Rent items

Application allows users to take more than one items to take on rent. If user selects multiple items to rent, it check the amount of rent and will apply the discount if it is applicable. Application will show message also to the user about this to inform the user.
Below are the lists of screen shots of application to showcase the working of an application:

  • login screen
  • Figure: Login Screen
  • add new item
  • Add New Item Interface
  • select item
  • Select item interface for update or remove
  • update item
  • Update item interface
  • remove item
  • Remove an item interface
  • add new customer
  • Add new customer interface
  • user creation
  • Response on successful user creation
  • available user
  • List of available users to modify
  • modify user
  • Modify user details interface
  •  
  • Removal of customer
  • Listing of available items (For User)
  • items available
  • Items available for rent (For Admin)
  • confirmation before
  • Confirmation before renting an item
  • discount massage
  •  Discount message to user
  • message discount
  • List of item available for user to return
  • user to return
  •  

4.5 Create technical documentation for the support and maintenance of your system

System Requirements For the proposed application

  • JRE 1.6 and higher
  • 512 MB RAM Minimum
  • OS Linux/ Windows/ Mac
  • 200 MB Hard Disk Space

The functionality of the CD/DVD Rental System individual classes are designed to perform the various task. These classes are used to hold information about the items (Cd or DVD), user accounts and their rented items. These classes are used to define user interface for the application.
MainFrame class: It contains the main method that is the starting method of the application. It creates the main frame of the application. It is responsible to write and read data by calling methods of DataStorageService class. It provides some methods to present GUI like…

  • CreateAndShowAddCustomerFrame (): It is used to display frame to add customer. MyCustomerPanel class is used to create GUI to add customer which is a child class of JPanel class.
  • CreateAndShowUpdateCustomerFrame (): It is used to displays update customer frame to the admin user. MyCustomerPanel is also used to generate graphical user interface to update customer.  
  • CreateAndShowRemoveCustomerFrame (): It is used to displays remove customer frame to the user. MyCustomerPanel is also used to display GUI to remove customer.
  • SaveApplicationData (): It writes data of the application. It user other methods from DataStorageService class to write data in text files as semicolon separated values.
  • LoadApplicationData (): it gets data of the application. It uses other methods DataStorageService class to retrieve data from files.
  • CreateAndShowAddItemFrame (): This method is used to display GUI form to add item.
  • CreateAndShowUpdateItemFrame ():This method is used to create update item frame which is used to update existing items in the application.
  • CreateAndShowRemoveItemFrame (): This method is used to display remove item frame to the user.
  • CreateAndShowSearchItemFrame (): This method displays the search panel to the user.
  • CreateAndShowAvailableItemsFrame (): This method is used to display frame for the available item and defines the functionality to update them.
  • CreateAndShowMyItemFrame (): This methods is used to display rented items and MyItemPanel class displays the GUI.
  • DisableButtonsForNormalUser (): This method removes administrator options for other users.

 

References:

  1. Flowchart [Online]. [Last accessed on 15 December 2014]. Available on world wide web: <http://en.wikipedia.org/wiki/Flowchart>
  2. Effective Java, Second Edition by Joshua Bloch, Addition-Wesley Professional.
  3. UML Distilled: A Brief Guide to the Standard Object Modelling Language by Martin Fowler.
  4. Swing a Beginner’s Guide, by Herbert Schildt.
  5. Java Programming, Sixth Edition by Joyce Farrell.