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:
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:
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.
Designing of Java Programming Solution: A system has been designed for CD/DVD rental system. Two type of user can use the system.
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:
If the user is a customer then he/she can perform the tasks that are decided for the customer as following:
User Use Case Diagram
Components: In the system requirements, the CD/DVD Rental System can be divided into 3(three) components:
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:
Structure for this file is as follows:
user-id;password;user-name;mobile-number;is-special-customer;credit-limit.
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
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.
(Figure: Sample rent data for user adminuser. Rented-Items-adminuser.txt)
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.
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:
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:
SearchItemDialog class: it displays an item selection dialog to select items for update or remove.
AppLoginDialog Class: It displays login dialog to the user. All users must logged in before using the application.
MyItemsPanel Class: This class is used to display current rented items of a particular user.
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.
RentedItem Class: It represents an item which is rented by the user.
AppUser Class: It stores information about application users such as their name, username, password, mobile number, credit limit etc.
MyAddEditItemPanel Class: It displays an interface for addition and update of an item to admin user.
MyCustomerPanel Class: This class displays an interface for addition and update of a customer to the administrator.
SearchUserDialog Class: It displays a user selection dialog to the administrator for update and removal of users.
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:
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.
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
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
We have also created some classes using inheritance hierarchy for user interface from javax.swing package.
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.
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:
Instance creation and method calling in SearchItemDialog class
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.
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.
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.
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
Following image shows the message to the user if he//she get and extra discount on items
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.
Below are some of screen shots of application to showcase the test results:
Message of successful user creation
Message when user gets a discount based on conditions defined in application
Application flow:
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:
System Requirements For the proposed application
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…
Details
Other Assignments
Related Solution
Other Solution