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