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.
/*
* CreditCard.java
*
* Created on September 4, 2007, 11:49 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package creditcardproject;
import java.io.File;
public class CreditCard {
private long AccountNo;
private double CreditLimit;
public double TotalCharges;
public double TotalPayments;
public long accountVar;
private int TransResult;
private String TransErr;
private String log;
private File file;
public int inval;
public long acctval;
public CreditCard(long accountVar){
this.accountVar=accountVar;
AccountNo=acctval;
CreditLimit = 1000;
TotalCharges = 0;
TotalPayments =0;
}
public CreditCard( ) {
newAccount();
CreditLimit = 1000;
TotalCharges = 0;
TotalPayments =0;
}
private void newAccount() {
double r = Math.random();
AccountNo = (long)(r * 100000000);
}
public long accountNumber() {
return AccountNo;
}
public double creditLimit() {
return CreditLimit;
}
public void creditIncrease() {
TransResult = 0;
if (Math.random() > .25)
CreditLimit += 100;
else {
System.out.println("Sorry, credit increase not possible at this time.");
TransResult = 1;
}
}
public double Available() {
double Available = CreditLimit - ( TotalCharges - TotalPayments );
return Available;
}
public double Balance() {
double Balance = ( TotalCharges - TotalPayments );
return Balance;
}
public void Transaction( double Amount, String Description ) {
TransResult = 0;
if ( Amount == 0 ) {
TransResult = 1;
TransErr = "Transaction amount is 0.";
return;
}
if ( Amount > Available() ) {
TransResult = 1;
TransErr = "Transaction amount of $" + Amount + " has exceeded the available credit limit $" + Available();
return;
}
if ( Description == "" ) {
TransResult = 1;
TransErr = "No transaction description entered.";
return;
}
if ( Amount > 0 ) {
TotalCharges += Amount;
return;
} else if ( Amount < 0 ) {
TotalPayments += -(Amount);
return;
}
}
}
is this combination close to what I need?
private void setNewAccount() {
double r = Math.random();
AccountNo = (long)(r * 100000000);
}
private long getNewAccount() {
return AccountNo;
along with
<% if(request.getParameter("createacct" != null)){%>
<jsp:useBean id= "creditCardBean" class = "creditcardproject.CreditCard"/>
<jsp:getProperty name="creditCardBean" property="NewAccount" parameter/>
<%}%>