import java.util.Collections; import java.io.PrintWriter; import java.io.FileWriter; import java.text.DateFormat; public class PartofRentalShopforWebSite { public void writeData() { //Sort the ArrayLists Collections.sort(custList); Collections.sort(itemList); try { PrintWriter pw = new PrintWriter(new FileWriter("Customers.txt")); //Loop through the ArrayList for (Customer c : custList) { //Write out the fields, separated by a | pw.print(c.getLastName() + "|" + c.getFirstName() + "|" + c.getAddr() + "|" + c.getCity() + "|" + c.getState() + "|" + c.getZip() + "|" + c.getPhone() + "|" + c.getID() + "|"); //Cycle through all items out and write them out for (String item : c.getItemsOut()) { pw.print(item + "|"); } //Move to a new line pw.println(); } pw.close(); } catch (Exception e) { } //Now write out the Video Rental Items try { PrintWriter pw = new PrintWriter(new FileWriter("LoanItems.txt")); //Loop through the ArrayList for (LoanItem l : itemList) { //Write out the fields, separated by a | if (l instanceof Movie) { //Do Movie Unique Stuff First pw.print("Movie|" + ( (Movie) l).getRating() + "|"); } else { //must be a VideoGame pw.print("VideoGame|" + ( (VideoGame) l).getRating() + "|" + ( (VideoGame) l).getSystem() + "|"); } //Now print out everything common from the parent class /*private boolean checkedOut; private Date dateOut, dateBack; //dates out private String title; private String customerID; //the customer who has this checked out or null private String itemID; //unique ID for this item private float replaceValue; //cost in US$ to replace item */ //Format the Gregorian Calendar Objects to go out to file DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); //is the date out null? String displayOut = null; if(l.getDateOut()!=null) { displayOut = df.format(l.getDateOut().getTime()); } //is the date back null? String displayBack = null; if(l.getDateBack()!=null) { displayBack = df.format(l.getDateBack().getTime()); } pw.print(l.getTitle() + "|" + l.getCheckedOut() + "|" + l.getItemID() + "|" + l.getReplaceValue() + "|" + displayOut + "|" + displayBack + "|" + l.getCustID()); //Move to a new line pw.println(); } pw.close(); } catch (Exception e) { } }