like IntObj in lab8, we can use an inner class to represent a client record of billing transaction
import java.io.*;
import java.util.*;
public class ReadClientData {
static class ClientData {
String clientName;
String clientAddress;
char trxCode;
double trxAmount;
ClientData (String clientName, String clientAddress,
char trxCode, double trxAmount){
this.clientName=clientName;
this.clientAddress=clientAddress;
this.trxCode=trxCode;
this.trxAmount=trxAmount;
}
public String toString() {
return(clientName + " " +
clientAddress + " " +
trxCode + " " +
trxAmount);
}
}
public static void main(String[] args) throws IOException {
String text;
ClientData clientData;
int count = 0;
BufferedReader fileIn;
fileIn = new BufferedReader(new FileReader("client.dat"));
while ( ( text = fileIn.readLine() ) != null ) {
StringTokenizer st = new StringTokenizer(text, "_");
String clientName = st.nextToken();
String clientAddress= st.nextToken();
char trxCode= st.nextToken().charAt(0);
double trxAmount= Double.parseDouble(st.nextToken());
clientData = new ClientData(clientName,
clientAddress,
trxCode,
trxAmount);
System.out.println(++count + " " + clientData.toString());
}
fileIn.close();
}
}