PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How do I save user input permenantly?

 August 18, 2022     extend, input, java, output, save     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing