/** * 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; } public LibraryReservation(){} 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" ); } public void writeData( PrintWriter writer ) { writer.print( reservationNo + "," + itemCode + "," + userID + "," + DateUtil.convertDateToShortString( startDate ) + "," + noOfDays ); writer.flush(); } 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() ); } } /* * Start Accessor */ /* * Return value of @reservationNo */ public String getReservationNo() { return reservationNo; } /* * Return value of @itemCode */ public String getItemCode() { return itemCode; } /* * Return value of @userID */ public String getUserID() { return userID; } /* * Return value of @startDate */ public Date getStartDate() { return startDate; } /* * Return value of @noOfDays */ public int getNoOfDays() { return noOfDays; } /* * End Accessor * * Start Mutator */ /* * Set @reservationNo to a new value */ public void setReservationNo( String reservationNo ) { this.reservationNo = reservationNo; } /* * Set @itemCode to a new value */ public void setItemCode( String itemCode ) { this.itemCode = itemCode; } /* * Set @userID to a new value */ public void setUserID( String userID ) { this.userID = userID; } /* * Set @startDate to a new value */ public void setStartDate( String startDate ) { this.startDate = DateUtil.convertStringToDate( startDate ); } /* * Set @noOfDays to a new value */ public void setNoOfDays( int noOfDays ) { this.noOfDays = noOfDays; } /* * End Mutator */ }