Customer.java
public class Customer implements java.io.Serializable{ //
declare a class, name Customer
// Fields
int cID;
String cName;
int cPhone;
boolean cVIP;
// Constructor
public Customer(int id, String name, int phone, boolean
vip){
cID = id;
cName = name;
cPhone = phone;
cVIP = vip;
}
// Methods
public boolean isValidPhone(){
if (cPhone<10000000 || cPhone > 99999999)
return false;
else return true;
}
public String getCInfo(){
return cID + "," + cName + "," + cPhone
+ (cVIP?",VIP":"");
}
}
CustomerFileUtil.java
import java.io.*;
import java.util.ArrayList;
public class CustomerFileUtil { // declare a class
public static Customer[] readCusFile(String rCusFile){ // DO NOT
MODIFY the method header
// .. TO BE COMPLETED BY STUDENTS ..
}
public static void writeVIPCusFile(Customer[] cArr, String
wCFile){ // DO NOT MODIFY the method header
// .. TO BE COMPLETED BY STUDENTS ..
}
public static void writeCusObjectFile(Customer[] cArr, String
wCObjF){ // DO NOT MODIFY the method header
// .. TO BE COMPLETED BY STUDENTS ..
}
public static Customer[] readCusObjectFile(String rCObjF){ // DO
NOT MODIFY the method header
// .. TO BE COMPLETED BY STUDENTS ..
}
}
11 La 14 18 22 9 v public class Customer implements java.io.Serializable{ // declare a class, name Customer 10 // Fields int CID; 12 String cName; 13 int cPhone; boolean CVIP; 15 16 // Constructor 17 v public Customer(int id, String name, int phone, boolean vip) { CID = id; 19 cName = name; 20 cPhone = phone; 21 CVIP = vip; } 23 24 // Methods 25 v public boolean isValidPhone() { 26 if (cPhone<10000000 || cPhone > 99999999) 27 return false; 28 else return true; 29 } 30 31 V public String getInfo() { 32 return CID + "," + cName + "," + cPhone 33 + (CVIP?",VIP":""); 34 } 35 36 } لا لا ليا ๆ ๆ ๆ ๆ
7 import java.io.*; import java.util.ArrayList; public class CustomerFileUtil { // declare a class public static Customer[] readCusFile(String rCusFile){ // DO NOT MODIFY the method header // .. TO BE COMPLETED BY STUDENTS .. } 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 public static void writeVIPCusFile(Customer[] cArr, String wcFile) { // DO NOT MODIFY the method header // .. TO BE COMPLETED BY STUDENTS .. } public static void writeCusObjectFile(Customer[] carr, String wcObjF){ // DO NOT MODIFY the method head // .. TO BE COMPLETED BY STUDENTS .. } public static Customer [] readCusObjectFile(String rcobjF){ // DO NOT MODIFY the method header // .. TO BE COMPLETED BY STUDENTS .. } }
2. Class CustomerFileUtil [8 marks] Create a public Java class CustomerFileUtil, in file CustomerFileUtil.java, as a class supporting File handling of customer records. Text File Format for handling Customer: Each record is stored with one line in CSV format (ID, Name, Phone, VIP or not), followed by a new line character "<CID>, <cName>, <cPhoneX, VIP??>" • E.g. for a VIP customer "2021001, CHAN Tai Man, 98765432, VIP" E.g. for a Non-VIP customer "2021002, CHAN Siu Ming, 98769876" Example Customer Text File A4BCustomers.txt, with 4 records. 20210001, CHAN Tai Man, 33332222, VIP 20214321, AU Candy, 98888888 20215678, CHOW Betty, 33333 20211234, LAU Andy, 98765432, VIP 20202021, AU A.A., 88888888, VIP Write and complete 4 static methods below in this class (DO NOT MODIFY the method header): * NO specific exception handling required. If necessary, students may catch exceptions without doing any specific action or just printing a simple error message. public static Customer [] readCusFile (String rCusFile): read customer records from the text file rCusFile, and return an array of customers public static void writeVIPCusFile (Customer[] cArr, String wCFile): write ONLY the VIP customer records in the input array of customers cArr into a text file wCFile public static void writeCusObjectFile(Customer [] CArr, String wcObjF): write all customer records from the input array of customers cArr, directly as an array of Customer objects (Customer []) into an Object file wcObjF o public static Customer [] readCusObjectFile(String rcobjF): read and return all customer records, directly as an array of Customer objects (Customer []) from an Object file rСObjF
Customer.java public class Customer implements java.io.Serializable{ // declare a class, name Customer // Fields int cID
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am