Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Overview
This example creates a session bean that contains business logic to calculate the total amount of money accrued for a savings scheme. This session bean is accessed by an application client and web client (Part i. below). You are then required to add a mobile client (Part ii. below).

Part i. Create J2EE Application
The following steps are followed:

Business-tier components run on the J2EE server.
1. Create session bean to represent business logic - Calculator

Client-tier components run on the client machine.
2. Create an application client to access the Calculator
3. Create JSP web client to access the Calculator

Note: Use simple configuration on local host i.e

Part ii. Mobile Client
Build a mobile client for the calculator.
In your system the server should return a result and the number of calculation requests a user has done in a session. Both the result and the number of calculations should be shown on the client.
Hint: Build the basic system, then add the number of calculations functionality.


For part(ii) document the following:
i. Code of the programs.
ii. Output from a complete execution of the system. (screen short)
iii. Brief explanation of system behaviour with respect to all application components.

 

 

 

 

Details

Part i. Create Enterprise Application(with Application Client) : CalculatorApp

0.File>New Project
1. Select Catorgories:Enterprise, Projects:Enterprise Application

 


2. Next>

3. Add Name:CalculatorApp
4. Select Creat Application Client Module
5. Change Project location to your directories

 


6. To Set Server select Manage...

 

7. Select Add Server .....

8. Next window not shown, but in Select box select: Sun Java System Application Server.
9. Next>


Browse to Platform location


10.Next>

11. Add Password
12. Select Finish until Project created



Create Session Bean to hold Business Logic

13. Right click ejb Project > new > Session Bean
14. Add : name= Calculator; Package=ejb;
15. Select Remote and Local Interfaces > Finish

 



16. Add calculate() method
Right click in code > EJB Methods
Wizard Updates interfaces automatically ( beta version required restart to get this
option to show!)
Add name
Use Add... Button to add methods parameters

 

 

17. Calculate Session Bean code:


package ejb;

import javax.ejb.Stateless;

@Stateless
public class CalculatorBean implements CalculatorRemote, CalculatorLocal {

/** Creates a new instance of CalculatorBean */
public CalculatorBean() {
}

public double calculate(int startAge, int endAge, double growthRate,
double savings) {
double tmp =
Math.pow(1. + growthRate / 12., 12. * (endAge - startAge) + 1);
return savings * 12. * (tmp - 1) / growthRate;
}

}

Create Application Client

18. Navigate to the main.java class in the client project
(see screen shot below)

19. Import bean reference:
right click in code area > Enterprise Resources> Call enterprise bean
Select Referenced Interface: Remote
>o.k



18. Client Class main.java



20. Add access code:
Use Alt-Shift-F to generate any necessary imports.

public static void main(String[] args) {
System.out.println("Data to Calculator Bean ");
System.out.println("int start=25, int end=65,
double growthrate=0.01, double saving=£350 ");
try {

NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);

// Access bean
double d = cal.calculate(25,65,0.01,350);
System.out.println("The balance at the End age is " +
nf.format(d));

} catch (Exception e) {
System.out.println("error in Bean Access");;}

}


Run Application Client

21. Set client type from Application properties:
right click on Application project
select:
properties/run/client module URI
select CalculatorApp-app-clientwar

Uncheck Display Browser on Run

 


Deploy and Run Application

22. Right click on Application > Run Project
Note deployment to server and output.


Create Web Client

23. Navigate to the index.jsp class in the web project
(see screen shot below)


24. Replace index code with:
Note code to obtain session bean reference


"http://www.w3.org/TR/html4/loose.dtd">

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="ejb.CalculatorLocal, javax.naming.*, java.text.*"%>

<%!
private CalculatorLocal cal = null;
public void jspInit () {
try {
System.out.println("JSP init");
InitialContext ctx = new InitialContext();
cal = (CalculatorLocal)ctx.lookup(
"java:comp/env/local_ref");


} catch (Exception e) {
System.out.println("EJB REFERENCE PROBLEM");
e.printStackTrace ();
}
}


%>


<%
String result;
int start = 25;
int end = 65;
double growthrate = 0.08;
double saving = 300.0;

try {
start = Integer.parseInt(request.getParameter ("start"));
end = Integer.parseInt(request.getParameter ("end"));
growthrate = Double.parseDouble(request.getParameter ("growthrate"));
saving = Double.parseDouble(request.getParameter ("saving"));
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
result = nf.format(cal.calculate(start, end, growthrate, saving));
} catch (Exception e) {
result = "Please press - Calculate";}
%>

 




JSP Page


Investment calculator2


Start age =

End age =

Annual Growth Rate =

Montly Saving =






The result from the last calculation: The balance at the End age is £
<%=result%>




23. Index.jsp

25. Set client to web client
right click on Application project
select:
properties/run/client module URI
select CalculatorApp-war.war
check Display Browser on Run

 


Set bean reference in Descriptor

26. Input references in web.xml as below to set .
Double click on web.xml
Select References tab
Expand EJB References
Select Add

Deploy and Run Application

27. Right click on Application > Run Project
Note deployment to server and web browser output.
26. Descriptor References

 


Attachment:- Logbook1_Exercise_D_new-1.rar

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91630260
  • Price:- $75

Priced at Now at $75, Verified Solution

Have any Question?


Related Questions in Programming Language

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As