Programme |
Diploma in Computing and Systems Development |
Unit Number and Title |
Unit 41 Programming in Java |
QFC Level |
Level 5 |
Unit Code |
F/601/1528 |
Solution:
Java is a language comes with great power and functionalities using which we can develop applications to that can be used on various platforms. Java provides the following features:
Java provides many feature to the application developers and has many more. It provides a larges set of features to the application developers. Following are some of the features of the Java programming language that are offered to the application programmers:
|
|
|
|
|
Solution:
When a Java program source file is compiled the Java compliers generates Byte code that is not specific to any platform, instead these are the instructions for the JVM. The Byte code that the Java compilers generates can be executed on the machines that has the Java Runtime Environment installed. The Byte code gets executed by the Java Virtual Machine which is a part of Java Runtime Environment.
All Java program source files are save with the extension .java and the file that is generated by the Java compiler which contains the Byte code has the extension .class. The .class file which is generated by the Java compiler has the same name as the class defined in the Java program source file (.java). A Java program source file can contain multiple classed defined in it but according to Java it is best way to have only one class defined in Java program source file. We must have individual source file for every Java class. This improves the overhead that if there is a need to modify or update any specific class so the Java source file in which the Java class is defined, can be easily identified by its name. Any ways if we have defined multiple classes in a single Java source file the byte code file which has the .class extension is generated for each class defined in Java source file.
The Java Virtual Machine has a compiler Just-In-Time (JIT) which uses the byte code file with the extension .class and is responsible to convert the byte code targeting the current platform on which the .class file is executing.
The application system designed for CD/DVD rental system has two types of user
Administrator
Users
To be able to use the proposed CD/DVD rental system the users must be logged into the application in order to use the application.
Components for the CD/DVD Rental System: Primarily the CD/DVD Rental System can have 3 (three) components:
It is mentioned in the assignment help to use simple text files to store CD/DVD Rental System application data. This CD/DVD Rental System application will use simple text files to save application data.
Following is the description of files created to store information:
user-id; password; user-name; mobile-number; is-special-customer; credit-limit
(Figure:Sampledatabase_of_app_users.txt)
movie-title; item-price; item-quantity; movie-category; item-type
(Figure: Sample database_of_cd_dvd.txt)
[movie_title; item_type; quantity]
(Figure: Sample rent data for user adminuser. Items-Rented-adminuser.txt)
Note: - Above files stores data in semicolon separated values and each new record is stored on a new line.
MySuperItem Interface: This purpose for designing this interface is to provide similar behaviour to all items and to gain polymorphic approach in the application. It defines common behaviour of an item that is CD and DVD in the application.
MyCDItem class: It implementsMySuperItem interface and promises to provide functionality for the item CD in the CD/DVD Rental System. It defines following properties for CD Item:
MyDVDItem class: It implements MySuperItem interface and promises to provide functionality for the item DVD in the CD/DVD Rental System. It defines following properties for CD Item:
MyDialogForSearchDialog class: It forms the GUI for item update and remove
MyLoginDialog Class: It forms the GUI for user login.
MyPanelForItems Class: This is used to display list of rented items.
MyServiceForStorage Class: It defines operations to get and set data to the text files. This class is a collection of static methods which are used for the read and write.
MyRentedItem Class: It is used to represent arented item.
MyApplicationUser Class: It represents information about users such as their name, username, password, contact number, credit limit etc.
MyPanelForItems Class: It generated interface for adding and update of an item.
MyPanelForCustomers Class: It is used to displays an interface for adding and update of a customer.
MyDialogForUsers Class: It shows a selection dialog to the administrator to update and remove a user.
(FOWLER, Martin, 2003)
The CD/DVD Rental System application is designed as per the design describe above. Inheritance is used whenever possible to implement classes. MySuperItem interface is defined to specify similar behaviour for all items. It defines basic functionality for allitems available.
Screen Shot fromMySuperItem.java:
Here:
Get_Item_Name() and Set_Item_Name() methods are used to get and set name of item (Cd/Dvd).
Get_Item_Category() and Set_Item_Category() methods are used to get and set category of the item.
Get_Item_Price() and Set_Item_Price() methods are used to get and set price of the item.
Get_Item_Quantity() and Set_Item_Quantity() 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.
Post declaring theMySuperItem interface,there are two more classes implementing this interface theMyCDItem class and MyDVDItem class.
MyCDItem.java: This class implementsMySuperItem interface. It defines the functionality and properties of CD.
Screen shot ofMyCDItem.java
MyDVDItem.java: This class implements MySuperItem interface. It defines the functionality and properties of DVD.
Screen shot ofMyDVDItem.java
There are more classed define in the application to achieve the desired functionality of the application using inheritance for the application GUI. These are the subclasses of the classes from javax.swing package.
Super Class from javax.swing package |
Sub class in the application |
Purpose in the application |
javax.swing.JFrame |
MyMainFrame.java |
main frame for the application |
javax.swing.JPanel |
MyPanelForCustomers |
PreparesGUI for Add, Update and Remove Customer. |
javax.swing.JPanel |
MyPanelForItems |
Prepares to Add, Update and Remove Item. |
javax.swing.JDialog |
MyDialogForSearchItems |
PreparesGUI to load items for update and remove. |
javax.swing.JDialog |
MyLoginDialog |
Constructs login dialog for users. It provides login behaviour for bothtype of users. |
A class provide definition for an object or we can say that a class is a collection of entities that have common characteristics. A class provide data encapsulation and methods to manipulate that data. A class is often referred as a user defined type. If we want to full use of a defined class then we have to instantiate the class. By creating object of the class we can use the data encapsulated in the class and the operations provided in the class definition.
The overall functionality is distributed and defined in various classed and these all classes are instantiated in “MyMainFrame.java” (Main class). This is the entry point for this application, which contains main method. This class is a subclass of JFrame class from javax.swing package and it provides the main interface of the application.
(Screen shot ofMyMainFrame.java)
The above shown code screen shot is of the file MyMainFrame.java. It is the class which contains main method and is responsible for instantiating other classes to achieve the desired functionality.
All of the following tests were performed by designing the basic functionality of the application. The system is tested against invalid, empty and unexpected inputs. System generated error message and info messages on an error or unexpected case and also in case of success of any particular operation.
Following were found in testing the system:
Net Beans IDE is used to create and manage the classes used in the application more easily and efficiently. In Net Beans IDE developing an application is a good experience. It provides code helps as we type it as well as it automatically generates for the derived classes that we define from existing classes
Net Beans code templates and screen templates are used to generate the application functionality. (SCHILDT, Herbert, 2006)
Details
Other Assignments
Related Solution
Other Solution