| | |
setters and getters
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 239
Reputation:
Solved Threads: 0
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.
is this combination close to what I need?
along with
JSP Syntax (Toggle Plain Text)
/* * 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?
JSP Syntax (Toggle Plain Text)
private void setNewAccount() { double r = Math.random(); AccountNo = (long)(r * 100000000); }
JSP Syntax (Toggle Plain Text)
private long getNewAccount() { return AccountNo;
along with
JSP Syntax (Toggle Plain Text)
<% if(request.getParameter("createacct" != null)){%> <jsp:useBean id= "creditCardBean" class = "creditcardproject.CreditCard"/> <jsp:getProperty name="creditCardBean" property="NewAccount" parameter/> <%}%>
Last edited by ceyesuma; Sep 4th, 2007 at 10:10 pm.
![]() |
Similar Threads
- struts tutorials (Java)
- Need Help on some methods (Java)
- Java class design question. (Java)
- object oriented programme help (Java)
- Please some one urgent help me in this code (C++)
- Please some one help me in this code (C++)
- Need Big Help !! (Java)
- lost on writing a Java class (Java)
- QuickSort (Computer Science)
Other Threads in the JSP Forum
- Previous Thread: Very Very Urgent...Need Code for Calculating Execution Time For Jsp Page
- Next Thread: form
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write





