943,965 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 1613
  • JSP RSS
Sep 4th, 2007
0

setters and getters

Expand Post »
This class was given to me. I need to work with JSP. Am I correct in thinking that I need to make the methods setters and getters for each method I need data from. And if so could you give me an example of one? Lets say I needed to get a random number to display in a jsp text box.
JSP Syntax (Toggle Plain Text)
  1. /*
  2.  * CreditCard.java
  3.  *
  4.  * Created on September 4, 2007, 11:49 AM
  5.  *
  6.  * To change this template, choose Tools | Template Manager
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. package creditcardproject;
  11.  
  12.  
  13.  
  14. import java.io.File;
  15.  
  16. public class CreditCard {
  17.  
  18. private long AccountNo;
  19. private double CreditLimit;
  20. public double TotalCharges;
  21. public double TotalPayments;
  22. public long accountVar;
  23. private int TransResult;
  24. private String TransErr;
  25. private String log;
  26. private File file;
  27.  
  28. public int inval;
  29. public long acctval;
  30.  
  31. public CreditCard(long accountVar){
  32. this.accountVar=accountVar;
  33. AccountNo=acctval;
  34. CreditLimit = 1000;
  35. TotalCharges = 0;
  36. TotalPayments =0;
  37. }
  38. public CreditCard( ) {
  39. newAccount();
  40. CreditLimit = 1000;
  41. TotalCharges = 0;
  42. TotalPayments =0;
  43. }
  44.  
  45. private void newAccount() {
  46. double r = Math.random();
  47. AccountNo = (long)(r * 100000000);
  48. }
  49.  
  50. public long accountNumber() {
  51. return AccountNo;
  52. }
  53.  
  54. public double creditLimit() {
  55. return CreditLimit;
  56. }
  57.  
  58. public void creditIncrease() {
  59. TransResult = 0;
  60. if (Math.random() > .25)
  61. CreditLimit += 100;
  62. else {
  63. System.out.println("Sorry, credit increase not possible at this time.");
  64. TransResult = 1;
  65. }
  66. }
  67. public double Available() {
  68. double Available = CreditLimit - ( TotalCharges - TotalPayments );
  69. return Available;
  70. }
  71.  
  72. public double Balance() {
  73. double Balance = ( TotalCharges - TotalPayments );
  74. return Balance;
  75. }
  76. public void Transaction( double Amount, String Description ) {
  77. TransResult = 0;
  78.  
  79. if ( Amount == 0 ) {
  80. TransResult = 1;
  81. TransErr = "Transaction amount is 0.";
  82. return;
  83. }
  84.  
  85.  
  86. if ( Amount > Available() ) {
  87. TransResult = 1;
  88. TransErr = "Transaction amount of $" + Amount + " has exceeded the available credit limit $" + Available();
  89. return;
  90. }
  91.  
  92.  
  93. if ( Description == "" ) {
  94. TransResult = 1;
  95. TransErr = "No transaction description entered.";
  96. return;
  97. }
  98.  
  99.  
  100. if ( Amount > 0 ) {
  101. TotalCharges += Amount;
  102. return;
  103.  
  104. } else if ( Amount < 0 ) {
  105.  
  106.  
  107. TotalPayments += -(Amount);
  108.  
  109. return;
  110.  
  111. }
  112. }
  113. }




is this combination close to what I need?
JSP Syntax (Toggle Plain Text)
  1. private void setNewAccount() {
  2. double r = Math.random();
  3. AccountNo = (long)(r * 100000000);
  4. }
JSP Syntax (Toggle Plain Text)
  1. private long getNewAccount() {
  2. return AccountNo;

along with
JSP Syntax (Toggle Plain Text)
  1. <% if(request.getParameter("createacct" != null)){%>
  2. <jsp:useBean id= "creditCardBean" class = "creditcardproject.CreditCard"/>
  3. <jsp:getProperty name="creditCardBean" property="NewAccount" parameter/>
  4. <%}%>
Last edited by ceyesuma; Sep 4th, 2007 at 10:10 pm.
Similar Threads
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Very Very Urgent...Need Code for Calculating Execution Time For Jsp Page
Next Thread in JSP Forum Timeline: form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC