Question
Reading and Writing Files of different Formats Using JAVA Consider the following Account Class _______________________________________________________________________ public class Account { private String name; private BigDecimal amount;
Reading and Writing Files of different Formats Using JAVA
Consider the following Account Class
_______________________________________________________________________
public class Account {
private String name;
private BigDecimal amount;
public Account(String acctName, String startAmount) {
this.setName(acctName);
this.setAmount(startAmount);
}
public String getName() {
return this.name;
}
public BigDecimal getAmount() {
return this.amount;
}
public void setName(String newName) {
String pattern = "^[a-zA-Z0-9]*$";
if (newName.matches(pattern)) {
this.name = newName;
}
}
private void setAmount(String newAmount){
this.amount = new BigDecimal(newAmount);
}
}
_______________________________________________________________________
Serialization
- Write a class SerializationHandler that supports a serialize() method, which takes as parameters an instance of the account class and serializes it to a file account.ser. The class also must support a deserialize() method which reads and returns the data of an account object. Write the client code to test the SerializationHandler class.
XML Files
- Write another class called XMLHandler that supports a Write() method that takes a name value pair, as strings, and writes them to an XML file. The class must also support a read() method that takes a name and retrieves its value from the XML file. Use this class to store the name value pair: name=JSONPath value=[path to a JSON file that will be used below in the JSON Files section]
JSON Files
- Write another class called JSONHandler that supports a write() method which takes an Account object and writes it to a file in a JSON format. The class also supports a read() method which reads data from a JSON file into an object. Write the client code to test the process. The JSON file path should be stored in and read from the XML file.
Properties
- Write another class called PropertiesHandler that supports a write() method, which takes a name value pair as strings and stores these in a properties file config.properties. The class must also support a read() method that takes a name and retrieves its value from the config.properties file. Use the Java class library java.util.Properties. Write the client code to test the PropertiesHandler class.
Preferences
- Write another class called PreferencesHandler that supports a write() method, which takes a name value pair as strings and stores these as a user preferences on the machine. The class must also support a read() method that takes a name and retrieves its value from the preferences store. Use the Java class library java.util.prefs.Preferences. Write the client code to test the PreferencesHandler class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started