Unit 41 Programming in Java Assignment Solution

Home
breadCrumb image
Solution
breadCrumb image
Unit 41 Programming in Java Assignment Solution
Unit 41 Programming in Java Assignment Solution
Unit 41 Programming in Java Assignment Solution

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

Unit 41 Programming in Java Assignment Solution

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 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 programming language is simple and easy to adapt. Java provides easy and clear to understand syntaxes that can be learn easily.
  • is platform independent language. If we use Java to write software then they can be executed on machines which has Java Runtime Environment. Java has a concept to write program once and run anywhere.
  • Java programming language provides developers high control to implement security features for the applications developed in Java. Also the Java Runtime Environment also keeps check for security for example in case of Applets, the Applets are not allowed to access the users system. Applets can be run on a web browser though internet, and this features enhances the user data security (BLOCH, Joshua, 2008)

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:

  • Object Oriented Programming Capabilities
  • Multithread Application Environment Support to utilize full performance of CPU in today’s multi core processors environment.
  • API’s for distributed applications
  • Garbage Collection facility that removes overhead from programmers, when to make release and retain memory for their programs
  • Java can be used to develop and design of websites, desktop applications, mobile application and the console application like the old C style.

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

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.

Task 2: Design Java solutions

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

Design the Java Programming Solution:

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.

  • If the user is an administrator then he can perform the following task:
  • Add New Customer
  • Update Existing Customer
  • Delete Existing Customer
  • Add a CD/DVD
  • View all CDs/DVDs
  • Update Existing CD/DVD
  • Remove Existing CD/DVD
  • The normal user of the application which is the customer will be able to perform the following task:
  • View all Existing CDs/DVDs
  • Rent any CD/DVD
  • Returning any Rented CD/DVD
Use Case Diagram

Use Case Diagram

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

Components for the CD/DVD Rental System: Primarily the CD/DVD Rental System can have 3 (three) components:

  1. CD/DVD Item: In the proposed application it is required to storedetails about the items (CDs and DVDs) available in the store. To persistformatI have designed an Interface named“MySuperItem”. It specifies the base functionality for the item (CD and DVD). MyCDItem and MyDVDItem classes implement MySuperItem interface and provides the functionality.
  2. Application Users: There can be two types of the users that are proposed for the application. First is administrator and second one a general user/customer. MyApplicationUser class in the proposed CD/DVD Rental System application stores user information.
  3. Storing Application Data: Data storage is a must requirement for the application to save the data permanently, hence, it is one of the most necessary components in the CD/DVD Rental System application. MyServiceForStorage class provides mechanism for retrieving and storing data.

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:

  1. :- It is used by the application to store information about the users of the application that will be created by the application administrator. The information is stored in the fileas one record per line. Following is the format:

user-id; password; user-name; mobile-number; is-special-customer; credit-limit

Sampledatabase_of_app_users
(Figure:Sampledatabase_of_app_users.txt)

  1. :- It is used by the application to store information for all items that can be CD or DVD. The information is stored in the file as one record per line. Following is the format:

movie-title; item-price; item-quantity; movie-category; item-type

Sample database_of_cd_dvd
(Figure: Sample database_of_cd_dvd.txt)

  1. :- It is used by the application to store the information of the rented items that are rented by the user. Individual file will be created for each user of the application. The information is stored in the file as one record per line. Following is the format:

[movie_title; item_type; quantity]

Sample rent data for user adminuser. Items-Rented-adminuser
(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.

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

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.

MySuperItem Interface

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:

  • item_name
  • item_category
  • item_type
  • item_quantity
  • item_price

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:

  • item_name
  • item_category
  • item_type
  • item_quantity
  • item_price

MyDialogForSearchDialog class: It forms the GUI for item update and remove

MyDialogForSearchDialog class

MyLoginDialog Class: It forms the GUI for user login.

MyLoginDialog Class

MyPanelForItems Class: This is used to display list of rented items.

MyPanelForItems Class

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.

MyServiceForStorage Class

MyRentedItem Class: It is used to represent arented item.

MyRentedItem Class

MyApplicationUser Class: It represents information about users such as their name, username, password, contact number, credit limit etc.

MyApplicationUser Class

MyPanelForItems Class: It generated interface for adding and update of an item.

MyPanelForItems Class

MyPanelForCustomers Class: It is used to displays an interface for adding and update of a customer.

MyPanelForCustomers Class

MyDialogForUsers Class: It shows a selection dialog to the administrator to update and remove a user.

 (FOWLER, Martin, 2003)

Task 3: Implement Java solutions

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

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:

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.

3.2 Implement classes using inheritance relationship.

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

Screen shot ofMyCDItem.java

MyDVDItem.java: This class implements MySuperItem interface. It defines the functionality and properties of DVD.

Screen shot ofMyDVDItem.java

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.

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

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

(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.

Displaying Login Dialog for user authentication

 

3.4 Identify and implement opportunities for error handling and reporting

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:

  • Unexpected/Invalid values stored in application storage files: during the application test, some error was found in the data formatting in the files. Due to this the application was not able to read data from the files when it gets restarted. I have done some modification to generate the desired output format of data in files.
  • Store Information files does not exist: Initially when the storage file was not available and my application tries to open it, it is terminating with error. I put a check for the existence of the information and now if the files were not found it will be created in the hard disk, so that it can be used by the application to store the information. (VERMEULEN, Al, 2000)

3.5 Make Effective Use of An Integrated Development Environment (Ide) Including Code and Screen Templates.

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)

References:

  1. BLOCH, Joshua. 2008. Effective Java (2nd Edition). Addison-Wesley.
  2. ECKEL, Bruce. 2003. Thinking in Java. Prentice Hall Professional.
  3. FARRELL, Joyce. 2011. Java Programming. Cengage Learning.
  4. FOWLER, Martin. 2003. UML Distilled: A Brief Guide to the Standard Object Modeling Language (3rd Edition). Addison-Wesley Professional.
  5. FREEMAN, Elisabeth. 2004. Head First Design Patterns. "O'Reilly Media, Inc.
  6. HUNT, Andrew and David THOMAS. 1999. The Pragmatic Programmer: From Journeyman to Master. Addison-Wesley Professional.
  7. SCHILDT, Herbert. 2006. Java: The Complete Reference, Seventh Edition. McGraw Hill Professional.
  8. SCHILDT, Herbert. 2006. Swing: A Beginner's Guide. McGraw-Hill Osborne Media.
  9. VERMEULEN, Al. 2000. The Elements of Java(TM) Style. Cambridge University Press.
FAQ's