Delivery in day(s): 5
Unit 41 Programming in Java Assignment Sample
LO1: Understand the principles of programming in Java
1.1 Discuss the principles, characteristics and features of programming in java
Java language high level language. A language is known as high level language if it provides human readable syntaxes for programming where as low level languages provides machine instructions which are not user friendly. Java uses English language for programming commands.
Basic characteristics of Java Language:
- Object Oriented Programming: If our problem is solved in terms of classes and objects then it is known as Object Oriented Programing. In object oriented programming every problem is solved in terms of classes and objects. Features of object oriented programming:
Encapsulation: Encapsulation means packaging all class data and code into a class which prevent it for outside access and misuse.
Inheritance: If a class is derived from another class then it is known as Inheritance. Using inheritance we can extend features of a class.
Polymorphism: Polymorphism means one name many forms. Using polymorphism we can define different functionality for a class inheritance hierarchy with same name.
- Distributed: Java provides distributed applications functionality which enables us to run different parts of an application on different machines. Java RMI (Remote method invocation) and EJB (Enterprise Java Beans) enables us to create distributed applications.
- Robust: Robust means strong. Java provides strong memory server management. Java doesn’t provide pointers to avoid security problems. It also provides automatic garbage collection and robust error & type checking.
Advantages and Disadvantages of JDK system with an IDE like Netbeans:
Advantages of using an IDE:
- IDEs provide syntax highlighting to users.
- IDEs provide automatic indentation for code blocks.
- IDEs provide line numbers to its users.
- IDEs provide auto code completion.
- IDEs provide auto code generation for inherited members.
- IDEs provide code debugging functionality and making check points to find out errors.
- Some IDEs provide GUI builder to build application for rapid application development
Disadvantages of using an IDE:
- IDEs prevent novice programmers from basic knowledge of language.
- IDEs generate generalized code which is not optimized for all applications.
- IDEs show compatibility issues with projects of other IDEs.
1.2 critically evaluate the environmental flexibility of programming in Java
Java language is platform independent. First of all its source code gets compiled into a class file which is also known as Byte Code. Byte code contains machine instructions for the operating system. This generated byte code is same for all platforms id Windows, Linux, Mac etc. Byte code is evaluated and interpreted by Java Virtual Machine (JVM). JVM is platform dependent but it is available for all platforms.
Thus byte code instructions and JVM together makes Java platform independent.
Java for Mobile Applications (Java ME)
Java ME stands for Java Micro Edition. It enables us to develop applications for small devices like pages, set-top boxes, mobile phones etc. Java ME is specifically designed for battery operated devices with small memory and processing speed. Java ME provides a special JVM for micro devices which is known as KVM. It is a cut down version of standard JVM and optimized for working in very small amount of memory (256 KB)
Embedded Hardware Programming in Java
Java provides an extension of Micro Edition API which is suitable for embedded applications and known as Java ME Embedded. It enables users to develop highly secure, robust, scalable and functional applications for embedded devices like cameras, flight control systems and ATM machines.
LO2: Be able to design Java Solutions
2.1 Design a java programming solution for to a given problem.
My java programming solution is as follows:
width of room: It is required to calculate area of the room.
Length of room: It is required to calculate area of the room.
Area: The application will display final area on which all work has to be done.
Time: The application will display total time required to complete the work.
Cost: The application will display final cost for the work.
Possible User Interface:
2.2 Explain the components and data file structure required to implement a given design.
Variable Names used in the application
private double roomLength = 0.0;
private double roomBreadth = 0.0;
private double roomArea = 0.0;
private intestimatedTime = 0;
private double cost = 0.0;
private double robertsWage = 0.0;
private double woodCost = 0.0;
Constants used in the application
private final byte avgRateOfInstallation = 3;
private final float assistantPrice = 10.25f;
private final float priceOfWood = 19.95f;
private final float robertsCharge = 85.0f;
Pseudo Code:Pseudo code is step by step instruction set to solve a problem. It specify basic logic which is to be implemented in order to solve a problem. Functionality of this application “Wage Calculator” can be achieved by following these steps:
- Application Start: User starts the application.
- Read number of rooms on which process has to be applied.
- Read length of room and breadth of roomfrom user.
- Calculate the area of room by multiplying room length and breadth ( (area = length*breadth).
- Repeat from Step-3 until area of all rooms has calculated.
- Calculate total area of all rooms by adding individual room area.
- Calculate the time required for installation (in hours), using the area of the room and rate of installation (3m2/hour).
- Calculate cost of assistants by multiplying total time and salary (€10.25/hour).
- Calculate Robert’s Wage by multiplying total time and Robert’s charges (.€85.00/week).
- Calculate the cost of wood by multiplying area and price of wood (€19.95/m2)
- Finally calculate totalwage = (assistants cost) + (Roberts charges) + (cost of wood).
- If wage>€300 then payment mode can be debit and credit only
- If payment mode is debit then final wage = wage +€0.50.
- If payment mode is credit then final wage = wage + 2% of wage.
- Otherwise final wage = wage.
- End of program.
LO3: Be able to implement Java Solutions
3.1 Implement a java programming solution based on a prepared design.
Java Programming Solution
Following is screen shots of java code in net beans editor:
3.2 Define relationships between objects to implement design requirements
3.3 Implement object behaviors using control structures to meet the design algorithms
Following behaviors are defined to calculate wages for the application.
3.4 Identify and implement opportunities for error handling and reporting
Following screens shows error and exception handling in the application
- Error Handling for empty string
- Error Handling for invalid value
3.5 Make effective use of an Integrated web Development Environment (IDE) including code and screen templates.
All screens of the application are designed in Netbeans IDE using Swing editor. Application interface is as follows.
Figure: Initial screen to read number of rooms.
Figure: Screen to read room details from user.
Figure: Screen after filling the data.
Figure: Confirmation message before moving to next screen.
Figure: Error Message if user leaves blank fields and tries to move to next screen.
Figure: Confirmation before final submission
Figure: Final result with debit card option.
Figure: Final result with credit card option.
LO4. Be able to test and document java solutions
4.1 Critically review and test a java programming solution
This application “Wage Calculator” is critically reviewed and tested and results are as follows:
- Review for User Interface: User Interface of this application is very simple and friendly. All input fields have proper labels.
- Review for error handling:This application properly handles all input errors and shows appropriate message to its users.
4.2 Analyse actual test results against expected test results to identify discrepancies.
Test results against expected test results are as follows:
Input Checking and Validation
Application must display error message for invalid input.
Application is displaying error message for every wrong input.
Floating Point Calculation
While calculating cost and area application must perform strict float point calculations for precise results.
Application is performing strict floating point calculation and displaying floating point values preciously.
Wage Calculation / Final output
Application must calculate wages and display output by following guidelines as specified in the assignment.
Application is displaying all outputs, and outputs pass all criteria as specified in assignment.
4.3 Evaluate independent feedback on a developed Java Program solution and make recommendations for improvements.
At evaluation time this application was working fine but all error messages of the application were displaying on the console. So I got a recommendation for displaying messages in a dialog box.
Now we have applied this recommendation by using JOptionPane to display message dialogs.
4.4 Create user documentation for developed java program solution.
This application helps to calculate total wage of wood flooring. It can be used to calculate room area, flooring cost and extra charges for credit or debit card payment.
User can use the application by following these steps:
- Start the application
- Specify number of rooms on which customer want to apply wood flooring.
- Enter details about “Length” and “Breadth” of each room.
- Now press enter on “Breadth” field.
- Application will automatically display “Area of Room”, “Estimated Time” and “Total Cost” for each room.
- Click on “Next Room” button.
- Now repeat from step-3 until details of all rooms are entered.
- After specifying details about all the rooms, click on “View Total Amount” Button.
- On Next screen application displays total rooms on which flooring is applied, Total estimated time for work, total cost and options for payment with debit or credit card.
4.5 Create technical documentation for support and maintenance of a java program solution.
The functionality of the application given in the assignment is defined in class “WageCalculator”. This class keeps details about the work which has to be done (Flooring on rooms) like room’s length and breadth, work cost, time etc. and provides methods to calculate final amount of the work.
It provides following methods:
- calArea(): It is used to calculate area of a room.
- calTime(): It is used to calculate total time required for wood flooring on given area.
- calAssistantsWage(): It is used to calculate total wage for Robert’s assistant for specific time at given rate.
- calRobertsWage(): Since Robert also charges for his service this function is used to calculate Robert’s wage for specific time.
- calPriceOfWood(): It is used to calculate total price of the wood for work.
- calTotalCost(): It is used to calculate total cost of the work which has done.
Java API documentation for Wage Calculator.
Java API Documentation for wage calculator
- Java The Complete Reference (English) 8th Edition by Herb Schildt
- Java Black Book by Steven Holzner
- Flow Charts [Online] [Accessed on 23 November 2014]. Available on world wide web: <http://en.wikipedia.org/wiki/Flowchart>
- UML [Online]. [Accessedon24 November 2014]. Available on world wide web <http://www.tutorialspoint.com/uml/>