/** * A class to track and allow for reservations in a Library * * @George Wilkinson * @1.0 */ import java.util.Date; import java.io.PrintWriter; import java.util.Scanner; public class LibraryReservation { // instance variables private String reservationNo; private String itemCode; private String userID; private Date startDate; private int noOfDays; /** * Constructor for objects of class LibraryReservation */ public LibraryReservation( String reservationNo, String itemCode, String userID, String startDate, int noOfDays ) { this.reservationNo = reservationNo; this.itemCode = itemCode; this.userID = userID; this.startDate = DateUtil.convertStringToDate( startDate ); this.noOfDays = noOfDays; } /** * Default Constructor for objects of class LibraryReservation */ public LibraryReservation(){} /** * Accessor Start */ public String getReservationNo() { return reservationNo; } public String getItemCode() { return itemCode; } public String userID() { return userID; } public Date getStartDate() { return startDate; } public int getNoOfDays() { return noOfDays; } /** * Accessor End */ /** * Mutator Start */ public void setReservationNo( String reservationNo ) { this.reservationNo = reservationNo; } public void setItemCode( String itemCode ) { this.itemCode = itemCode; } public void setUserID( String userID ) { this.userID = userID; } public void setStartDate( String startDate ) { this.startDate = DateUtil.convertStringToDate( startDate ); } public void setNoOfDays( int noOfDays ) { this.noOfDays = noOfDays; } /** * Mutator End */ /** * Concatenates values to output a formatted string. */ public String toString() { return reservationNo + " " + userID + " " + itemCode; } /** * Prints to terminal, the details of the reservation. */ public void printDetails() { System.out.println( "Reservation Number: " + reservationNo + "\nItem Code: " + itemCode + "\nUser ID: " + userID + "\nDate Commencing: " + DateUtil.convertDateToShortString( startDate ) + "\nDuration: " + noOfDays + " days" ); } /** * Forms field variables in a desired format, prints * to the PrintWriter, and flush to the file. * Takes Parameter * PrintWriter @writer */ public void writeData( PrintWriter writer ) { writer.print( reservationNo + "," + itemCode + "," + userID + "," + DateUtil.convertDateToShortString( startDate ) + "," + noOfDays ); writer.flush(); } /** * Populate the fields with details from the scanner * Takes Parameters * Scanner @detailScanner */ public void readData( Scanner detailScanner ) { if ( detailScanner != null ) { this.reservationNo = detailScanner.next().trim(); this.itemCode = detailScanner.next().trim(); this.userID = detailScanner.next().trim(); this.startDate = DateUtil.convertStringToDate( detailScanner.next().trim() ); this.noOfDays = Integer.parseInt( detailScanner.next().trim() ); } } }