setters and getters

Thread Solved

Join Date: Aug 2007
Posts: 239
Reputation: ceyesuma is an unknown quantity at this point 
Solved Threads: 0
ceyesuma ceyesuma is offline Offline
Posting Whiz in Training

setters and getters

 
0
  #1
Sep 4th, 2007
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.
  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?
  1. private void setNewAccount() {
  2. double r = Math.random();
  3. AccountNo = (long)(r * 100000000);
  4. }
  1. private long getNewAccount() {
  2. return AccountNo;

along with
  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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC