Issue
So I have created an Account class and i wanted to save the user details permenantly for future use. For example, should the user create an account, i would like him/her to be able to use his info including balance in the future. Please help me!
package mini_project;
import java.util.Random;
import javax.swing.JOptionPane;
public class Account {
private String firstName, surname;
private short transactionNumber;
String input;
private int startingAmount;
public Account(String first, String sur, int amount){
firstName = first;
surname = sur;
startingAmount = amount;
}
public void setFirstName (){
input = JOptionPane.showInputDialog("What Is Your First Name?").toUpperCase();
firstName = input;
}
public String getFirstName (){
return firstName;
}
public void setSurname (){
input = JOptionPane.showInputDialog("What Is Your Surname?").toUpperCase ();
surname = input;
}
public String getSurname (){
return surname;
}
public void setTransactionNumber (){
Random rand = new Random ();
int randomNumber = rand.nextInt(1000)+1;
transactionNumber = (short) randomNumber;
}
public short getTransactionNumber(){
return transactionNumber;
}
public void setShares(){
input = JOptionPane.showInputDialog("How Many Shares Do You Currently Own?");
startingAmount = Integer.parseInt(input);
}
public int getShares(){
return startingAmount;
}
}
Solution
You could always make the account class implement Serializable. This will allow you to save and import the object's instance, in this case individual account objects. These instances can be saved into a text file. They can also be encrypted if your program requires more security.
Answered By - Bautista Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.