Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
 
 
 
 
ELEM004 (2010)  Page 1 of 2 
 
 
Lab 2 Tax Servlet 
 
Writing a Bean and testing it using a POJ (plain old Java) programme. No servlets. 
(a) Write a class called TaxBean to calculate how much tax an individual owes based on 
their gross salary and the following tax rates: 
 
Earnings in the range Tax rate
£0 – 4,535 0% 
£4,536 – 6,415 10% 
£6,416 – 43,935 22% 
£43,935+ 40% 
  For example the tax on £6426 is 22% of 10 + 10% of (6416-4536) + 0% of 4536 
  TaxBean has one attribute called salary, which is set by a method with prototype 
   public void setSalary(double s); 
The constructor has no parameters, and so is unnecessary (You should know why. If not ask 
the demonstrators.) 
Your class should provide a method: 
 public double calculateTax(); 
to compute the tax payable. 
Write a simple Java program that invokes setSalary and then calculateTax and outputs the 
value. 
Writing the HTML 
b)  Write an HTML page that will collect the name and salary data from an individual and 
call a servlet called ComputeTax. (You have not yet written the servlet.) 
Writing the Servlet 
c)  Write the servlet ComputeTax that creates an instance of the TaxBean and sets the 
salary attribute to the value provided in the form. It then uses the method calculateTax and 
returns an HTML page with the result. 
Session Tracking 
d) The individual returns another time. Add session tracking, so that the user can be given a 
friendly message in the output, e.g. Hello Usman, Nice of you to visit again. Your tax is 
£XXXX.  
THEN 
e) Modify the first servlet, so that in its response it also asks the user to predict their salary 
next year. The servlet then returns a final page that says “hello YYYY, your tax this year is 
£XXXX (the value previously calculated) but next year it will be (the value just calculated) 
 
 
 
 
 
 
ELEM004 (2010)  Page 2 of 2 
 
 
 
Note, you may have to modify the session timeout either in web.xml or in the servlet for 
some value that is more practical for development (ie shorter than the default 30 minutes) 
 
Compilation Issue 
The compile should be able to find all files in the same directory. However, sometime this does not 
happen. If this happens you need to add a full-stop (followed by a semi-colon if listing other 
directories) after the classpath instruction to tell the compiler to look in the same directory:: 
javac –classpath .;servlet-api.jar myJavaFile.java      
[Mac/Linux users should use a colon (:) instead of a semi-colon (;) when listing directories]