Forums Register Login

Coding Problem

+Pie Number of slices to send: Send
I am in an Into to Java class and this is my last week. Up until now, I have been able to keep up to some degree by using the code in my book and altering it. However, for my final project, I have to do something that I am unable to locate any similar code for in the book...any help would be appreciated. Up to this point, the java assignments have only been writing Java applications in TextPad and running them. I have not even had any classes in HTML coding yet, I have had one class in QBasic and am comfortable with procedural programming, and one class in SQL. This is my first OOP class and I am really struggling trying to move from the the concept of procedural code to objects.

I am not wanting someone to write the code for me. I just would like some directions of what I need to do...like write an applet for something then a class for something else....whatever it is.


Problem:
Write a Java servlet, HTML.Bank.java, that creates a HTML form that contains: A text box for entering an amount, a text field that displays a formatted balance, and three buttons ("Deposit" to add the amount to the balance, "Withdraw" to subtract the amount from the balance, and "Balance" to display the balance) Use an instance variable for the balance. If no amount is entered in the text box or if it is a zero or negative number, output a simple HTML page that displays an error message. Also, be sure that an amount was entered before converting the string variable for amount to a double.

I have to be able to run this on my Tomcat server with my web browser. I have no idea where to even start.
+Pie Number of slices to send: Send
Java Servlets are part of the J2EE api's. You can read about them in this tutorial.
+Pie Number of slices to send: Send
Hi Janice,

For Tomcat setup, you can check out this thread.

You can also download free online version of Core Servlets & JSP, 1st Edition at the CoreServlets.com.

Joyce
+Pie Number of slices to send: Send
I know the lost feeling of not knowing where to start so I'll tell you what I'd try.

You could have a single servlet with
* A method (1) to handle buttons being pushed on the normal html page (this method will check for input errors and decide whether to call method 2 or method 3 for further action
* A method (2) to update the balance and display the normal page
* A method (3) to display the error page (from the error page you return to normal page with last "good" values for balance, withdrawl and deposit.
* Variables to hold balance and the amount to withdraw or deposit, maybe booleans such as isWithdrawl and isDeposit (obviously one will do but maybe 2 is easier to understand).

Long streches of html that are used time and again can be static string variables of the servlet.

When the servlet starts up you give balance and withdrawl/deposit amount default values (presumably zeros) and display the normal page.
Apparently the same text field that originally displays the balance will be used to enter the amt. of a deposit or withdrawl, this means you should maintain your start balance in the html code as a hidden value.

When processing input (1) read the balance from the hidden value and (2) make sure you do not change the balance until deposit/withdrawl input is verified as OK.
After making a withdrawl or deposit and thereby changing your balance value remember to reset the withdrawl/deposit amt. to zero (this might later help with finding errors).

-There is a lot I might have missed but start working and you should begin to see for yourself how the project is fleshing out.

[ November 17, 2004: Message edited by: Elouise Kivineva ]
[ November 17, 2004: Message edited by: Elouise Kivineva ]
+Pie Number of slices to send: Send
However, for my final project, I have to do something that I am unable to locate any similar code for in the book...any help would be appreciated.
Did your teacher recommend any books on Servlet? If not, you might want to consider getting this book Core Servlets and JavaServer Pages, Vol. 1: Core Technologies, Second Edition by Marty Hall. The examples given in the book can be downloaded here.
What's gotten into you? Could it be this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 940 times.
Similar Threads
Servlet handling its own outputted HTML form
Bank Account Project
Whats Wrong in my Thread program
ATM Machine program
Help on testprogram and subclass please
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:42:35.