vault backup: 2024-03-21 22:58:58
This commit is contained in:
65
Semester 2/Programming 2/Assessment 4 Notes
Normal file
65
Semester 2/Programming 2/Assessment 4 Notes
Normal file
@@ -0,0 +1,65 @@
|
||||
private void readFilmData(String fileName) throws IOException //1
|
||||
{
|
||||
File filmFile = new File(filename); //2
|
||||
Scanner scanner1 = new Scanner( filmFile ); //3
|
||||
while (scanner1.hasNext() ) //4 could throw a FileNotFoundExcpetion
|
||||
{
|
||||
String line = scanner1.nextLine(); //5
|
||||
Scanner scanner2 = new Scanner(line);
|
||||
scanner2.useDelimiter("[ ]*(,)[ ]*");
|
||||
String filmTitle = scanner2.next();
|
||||
String filmRating = scanner2.next();
|
||||
int short = scanner2.nextInt();
|
||||
// other code here to read & store rest of data
|
||||
scanner2.close();
|
||||
}
|
||||
scanner1.close();
|
||||
}
|
||||
|
||||
Citizen ->
|
||||
English ->
|
||||
Mancunian,
|
||||
Londoner
|
||||
Scots
|
||||
|
||||
Citizen person1;
|
||||
English person2;
|
||||
Scots person3;
|
||||
Mancunian person4;
|
||||
Londoner person5;
|
||||
|
||||
person1 = new Londoner();
|
||||
person1 type Citizen. Legal
|
||||
|
||||
person2 = new Mancunian();
|
||||
person2 type English. Legal
|
||||
|
||||
person5 = new English();
|
||||
person5 type Londoner. Illegal
|
||||
|
||||
persona2 = new Scots();
|
||||
person2 type English. Illegal
|
||||
|
||||
factorial(3) ->
|
||||
x = 2
|
||||
y = factorial(2)
|
||||
factorial(2) ->
|
||||
x = 1
|
||||
y = factorial(1) -> 1
|
||||
n*y = 2*1 = 2
|
||||
n*y = 2*3 = 6
|
||||
|
||||
|
||||
|
||||
public int countTree(BinTreeNode t)
|
||||
{
|
||||
int count;
|
||||
if (t == null)
|
||||
count = 0;
|
||||
else
|
||||
count = countTree(t.leftChild) + 1 + countTree(t.rightChild);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
BIN
Semester 2/Programming 2/Project/Part 2/Diary$1.class
Normal file
BIN
Semester 2/Programming 2/Project/Part 2/Diary$1.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
Semester 2/Programming 2/Project/Part 2/Diary$DayInDiary.class
Normal file
BIN
Semester 2/Programming 2/Project/Part 2/Diary$DayInDiary.class
Normal file
Binary file not shown.
BIN
Semester 2/Programming 2/Project/Part 2/Diary.class
Normal file
BIN
Semester 2/Programming 2/Project/Part 2/Diary.class
Normal file
Binary file not shown.
17
Semester 2/Programming 2/Project/Part 2/Diary.ctxt
Normal file
17
Semester 2/Programming 2/Project/Part 2/Diary.ctxt
Normal file
@@ -0,0 +1,17 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Diary()
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Diary\n
|
||||
comment1.params=itemReservation
|
||||
comment1.target=void\ addReservation(LibraryReservation)
|
||||
comment1.text=\n\ Method\ for\ adding\ a\ reservation\ to\ the\ diary.\ \n\ @parameter\ itemReservation,\ of\ type\ ItemReservation\ \n
|
||||
comment2.params=startDate\ endDate
|
||||
comment2.target=void\ printEntries(java.util.Date,\ java.util.Date)
|
||||
comment2.text=\n\ Method\ for\ displaying\ the\ reservations\ between\ specified\ dates.\ \n\n\ @parameter\ \ \ \ \ startDate,\ of\ type\ Date\n\ @parameter\ \ \ \ \ endDate,\ of\ type\ Date\n
|
||||
comment3.params=itemReservation
|
||||
comment3.target=void\ deleteReservation(LibraryReservation)
|
||||
comment3.text=\n\ Method\ for\ deleting\ a\ reservation\ from\ the\ diary.\ \n\ @parameter\ itemReservation,\ of\ type\ ItemReservation\ \n
|
||||
comment4.params=date
|
||||
comment4.target=LibraryReservation[]\ getReservations(java.util.Date)
|
||||
comment4.text=\n\ Accessor\ method\ for\ returning\ all\ reservations\ that\ have\ entries\ \n\ in\ the\ diary\ for\ a\ particular\ date.\ \n\n\ @parameter\ \ \ \ \ date,\ of\ type\ Date\ \n\ @return\ \ \ \ \ \ \ \ an\ array\ of\ reservations,\ or\ null\ if\ no\ entry\ for\ that\ date\n
|
||||
numComments=5
|
205
Semester 2/Programming 2/Project/Part 2/Diary.java
Normal file
205
Semester 2/Programming 2/Project/Part 2/Diary.java
Normal file
@@ -0,0 +1,205 @@
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
/**
|
||||
* A class Diary that represents a "diary" of library item reservations.
|
||||
*
|
||||
* The diary is structured as a Map of entries in which each entry corresponds
|
||||
* to a specific day. As the map is not accessed in a sequential fashion, it
|
||||
* doesn't matter whether the actual map class is a TreeMap or a HashMap.
|
||||
*
|
||||
* @author D E Newton
|
||||
*
|
||||
*/
|
||||
public class Diary
|
||||
{
|
||||
private Map<Date, DayInDiary> dayInDiaryMap;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Diary
|
||||
*/
|
||||
public Diary()
|
||||
{
|
||||
// create diary as a map
|
||||
dayInDiaryMap = new HashMap<Date, DayInDiary>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for adding a reservation to the diary.
|
||||
* @parameter itemReservation, of type ItemReservation
|
||||
*/
|
||||
public void addReservation(LibraryReservation itemReservation)
|
||||
{
|
||||
Date date = itemReservation.getStartDate();
|
||||
for(int day=1; day<=itemReservation.getNoOfDays(); day++)
|
||||
{
|
||||
if( !dayInDiaryMap.containsKey(date) )
|
||||
{
|
||||
// add new day to diary if no previous entries for this day
|
||||
dayInDiaryMap.put(date, new DayInDiary(date));
|
||||
}
|
||||
|
||||
dayInDiaryMap.get(date).addEntry(itemReservation, day);
|
||||
date = DateUtil.nextDate(date);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for displaying the reservations between specified dates.
|
||||
*
|
||||
* @parameter startDate, of type Date
|
||||
* @parameter endDate, of type Date
|
||||
*/
|
||||
public void printEntries(Date startDate, Date endDate)
|
||||
{
|
||||
if( DateUtil.daysBetween(startDate, endDate)<0 )
|
||||
{
|
||||
// startDate after endDate
|
||||
System.out.println("*** Error in method displayEntries(): The specified end date is before the start date ***");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("\n\nDiary: Reservations for period " + DateUtil.convertDateToShortString(startDate)
|
||||
+ " to " + DateUtil.convertDateToShortString(endDate) + " inclusive");
|
||||
System.out.println("=================================================================");
|
||||
for(Date date=startDate; date.compareTo(endDate)<=0; date = DateUtil.nextDate(date))
|
||||
{
|
||||
String longDate = DateUtil.convertDateToLongString(date);
|
||||
System.out.print(longDate + ":");
|
||||
if( dayInDiaryMap.containsKey(date) )
|
||||
{
|
||||
DayInDiary dayInDiary = dayInDiaryMap.get(date);
|
||||
dayInDiary.printEntries();
|
||||
}
|
||||
else
|
||||
System.out.println(" No reservations\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for deleting a reservation from the diary.
|
||||
* @parameter itemReservation, of type ItemReservation
|
||||
*/
|
||||
public void deleteReservation(LibraryReservation itemReservation)
|
||||
{
|
||||
Date date = itemReservation.getStartDate();
|
||||
for(int day=1; day<=itemReservation.getNoOfDays(); day++)
|
||||
{
|
||||
DayInDiary dayInDiary = dayInDiaryMap.get(date);
|
||||
dayInDiary.deleteEntry(itemReservation);
|
||||
|
||||
if( dayInDiary.getDaysEntries().size()==0 )
|
||||
dayInDiaryMap.remove(date);
|
||||
|
||||
date = DateUtil.nextDate(date);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor method for returning all reservations that have entries
|
||||
* in the diary for a particular date.
|
||||
*
|
||||
* @parameter date, of type Date
|
||||
* @return an array of reservations, or null if no entry for that date
|
||||
*/
|
||||
public LibraryReservation[] getReservations(Date date)
|
||||
{
|
||||
DayInDiary dayinDiary = dayInDiaryMap.get(date);
|
||||
if( dayinDiary==null )
|
||||
return null;
|
||||
else
|
||||
return dayinDiary.getReservations();
|
||||
}
|
||||
|
||||
// inner class, only needed in the Diary class
|
||||
private class DayInDiary
|
||||
{
|
||||
// reservations for the day
|
||||
private ArrayList<Entry> daysEntries;
|
||||
private Date date;
|
||||
|
||||
/*
|
||||
* Constructor for objects of class DayInDiary
|
||||
*/
|
||||
private DayInDiary(Date date)
|
||||
{
|
||||
this.date = date;
|
||||
daysEntries = new ArrayList<Entry>();
|
||||
}
|
||||
|
||||
private ArrayList<Entry> getDaysEntries()
|
||||
{
|
||||
return daysEntries;
|
||||
}
|
||||
|
||||
private LibraryReservation[] getReservations()
|
||||
{
|
||||
int noOfEntries = daysEntries.size();
|
||||
LibraryReservation[] itemReservations = new LibraryReservation[noOfEntries];
|
||||
for(int i=0; i<noOfEntries; i++)
|
||||
itemReservations[i] = daysEntries.get(i).getReservation();
|
||||
return itemReservations;
|
||||
}
|
||||
|
||||
private void addEntry(LibraryReservation itemReservation, int dayNo)
|
||||
{
|
||||
daysEntries.add(new Entry(itemReservation, dayNo));
|
||||
}
|
||||
|
||||
private void deleteEntry(LibraryReservation itemReservation)
|
||||
{
|
||||
// find the entry for this reservation and delete it
|
||||
Entry toBeDeletedEntry = null;
|
||||
for(Entry entry : daysEntries)
|
||||
{
|
||||
if( entry.getReservation()==itemReservation ) // in this situation, this is better than using "equals()"
|
||||
{
|
||||
toBeDeletedEntry = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
daysEntries.remove(toBeDeletedEntry);
|
||||
}
|
||||
|
||||
private void printEntries()
|
||||
{
|
||||
int size = daysEntries.size();
|
||||
if( size>0 )
|
||||
{
|
||||
System.out.println(" " + size + " reservation(s)");
|
||||
for( Entry entry: daysEntries )
|
||||
{
|
||||
LibraryReservation itemReservation = entry.getReservation();
|
||||
int reservationDay = DateUtil.daysBetween(itemReservation.getStartDate(), date) + 1;;
|
||||
System.out.println(" " + itemReservation + ", day " + reservationDay + " of " + itemReservation.getNoOfDays());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("*** Unexpected error in displayEntries() ***");
|
||||
System.out.println("*** No entries for this date so it should not be in the diary ***");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
// an inner class of the DaysDiary class
|
||||
private class Entry
|
||||
{
|
||||
private LibraryReservation itemReservation;
|
||||
private int reservationDay; // e.g. second day is day 2 of 4 for a reservation spanning 4 days
|
||||
|
||||
private Entry(LibraryReservation itemReservation, int reservationDay)
|
||||
{
|
||||
this.itemReservation = itemReservation;
|
||||
this.reservationDay = reservationDay;
|
||||
}
|
||||
|
||||
private LibraryReservation getReservation()
|
||||
{
|
||||
return itemReservation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -5,22 +5,41 @@ comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Library\n
|
||||
comment1.params=item
|
||||
comment1.target=void\ storeItem(LibraryItem)
|
||||
comment1.text=\n\ Inserts\ object\ value\ item\ alongside\ key\ of\ @itemCode\ into\ @itemsMap.\n
|
||||
comment10.params=
|
||||
comment10.target=void\ writeUserData()
|
||||
comment10.text=\n\ A\ method\ to\ output\ all\ user\ data\ to\ a\ file\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ \n
|
||||
comment11.params=
|
||||
comment11.target=void\ readLibraryReservationData()
|
||||
comment11.text=\n\ Read\ Library\ Reservation\ Data\ from\ a\ file\ specified\ by\ the\ user.\n
|
||||
comment12.params=
|
||||
comment12.target=void\ readData()
|
||||
comment12.text=\n\ A\ method\ to\ read\ all\ data\ from\ files\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ This\ will\ create\ the\ corresponding\ objects\ depending\ on\ flags\ contained\ in\ the\ file\n\ and\ populate\ it's\ fields.\n\ \n\ Default\ flag\ value\:\ "book",\ to\ support\ legacy\ files.\ This\ will\ not\ interfere\ with\ \n\ files\ of\ different\ flag\ orders.\n
|
||||
comment13.params=userID\ itemCode\ startDate\ noOfDays
|
||||
comment13.target=boolean\ makeLibraryReservation(java.lang.String,\ java.lang.String,\ java.lang.String,\ int)
|
||||
comment13.text=\n\ Create\ a\ reservation\ to\ allow\ a\ user\ to\ reserve\ an\ item\ from\ the\ library.\n
|
||||
comment14.params=reservationNo
|
||||
comment14.target=void\ deleteLibraryReservation(java.lang.String)
|
||||
comment2.params=user
|
||||
comment2.target=void\ storeUser(LibraryUser)
|
||||
comment2.text=\n\ Inserts\ object\ value\ user\ alongside\ key\ of\ @userID\ into\ @customerMap.\n\ If\ the\ userID\ is\ set\ to\ unknown,\ it\ will\ call\ @generateUserID.\n
|
||||
comment3.params=reservation
|
||||
comment3.target=void\ storeLibraryReservation(LibraryReservation)
|
||||
comment3.text=\n\ Inserts\ object\ value\ reservation\ alongside\ key\ of\ @reservationNo\ into\ @libraryReservationMap.\n
|
||||
comment4.params=prefix\ length
|
||||
comment4.target=java.lang.String\ generateUserID(java.lang.String,\ int)
|
||||
comment4.text=\n\ Returns\ a\ random\ unique\ user\ ID\ by\ specifying\ \n\ @prefix\ -\ arbitrary\ alphanumeric\ prefix\n\ @length\ -\ length\ of\ numeric\ ID\n\ and\ returning\ a\ unique\ user\ id\n\ @uuid\ -\ a\ unique\ string\ starting\ with\ @prefix,\ and\ concat.\ with\ a\ random\ number\n\ \n\ Example\:\ length\ \=\ 6,\ expected\ result\ should\ be\ under\ 999,999\ and\ above\ 99,999.\n\ If\ we\ just\ use\ 10^(length),\ this\ would\ generate\ any\ number\ under\ 1,000,000.\n\ This\ is\ an\ issue\ since\ any\ integers\ below\ 100,000\ can\ be\ used,\ which\ would\ be\ incorrect.\n\ By\ using\ the\ offset\ of\ a\ factor\ of\ 10\ below\ the\ desired\ length\ we\ can\ generate\ between\ 0\ and\ 899,999.\n\ After\ this,\ we\ can\ add\ 100,000\ back\ to\ the\ number\ to\ ensure\ a\ baseline\ length\ is\ maintained.\n\ \n\ Note\:\ I\ am\ aware\ that\ this\ is\ overengineered,\ and\ that\ several\ random\ integers\ of\ amount\ @length\ could\ be\ used,\ \n\ but\ this\ is\ considerably\ more\ efficient\ since\ there\ is\ no\ iteration\ involved\ in\ the\ creation\ of\ the\ ID.\ O(1)\n
|
||||
comment5.params=
|
||||
comment5.target=void\ writeUserData()
|
||||
comment5.text=\n\ A\ method\ to\ output\ all\ user\ data\ to\ a\ file\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ \n\ Note\:\ Potentially\ could\ implement\ the\ HashSet\ made\ for\ GenerateUserID\ to\ avoid\ unnecessary\ recursion.\n
|
||||
comment4.params=
|
||||
comment4.target=java.lang.String\ generateReservationNo()
|
||||
comment4.text=\n\ Generate\ a\ sequential\ reservation\ number.\ Since\ Maps\ do\ not\ have\ an\ index,\ we\ cannot\ simply\ get\ the\ last\ value,\ \n\ and\ recursion\ would\ be\ too\ intensive\ for\ this\ application.\ As\ a\ placeholder\ for\ the\ file\ output,\ a\ field\ variable\n\ is\ used\ to\ hold\ the\ last\ highest\ value\ for\ the\ reservation\ number.\ Unlike\ @generateUserID,\ this\ has\ a\ maximum\ value\n\ hardcoded\ to\ the\ spec.\ This\ likely\ will\ not\ be\ an\ issue\ since\ we\ can\ still\ have\ 1,000,000\ reservations.\n
|
||||
comment5.params=prefix\ length
|
||||
comment5.target=java.lang.String\ generateUserID(java.lang.String,\ int)
|
||||
comment5.text=\n\ Returns\ a\ random\ unique\ user\ ID\ by\ specifying\ \n\ @prefix\ -\ arbitrary\ alphanumeric\ prefix\n\ @length\ -\ length\ of\ numeric\ ID\n\ and\ returning\ a\ unique\ user\ id\n\ @uuid\ -\ a\ unique\ string\ starting\ with\ @prefix,\ and\ concat.\ with\ a\ random\ number\n\ \n\ Example\:\ length\ \=\ 6,\ expected\ result\ should\ be\ under\ 999,999\ and\ above\ 99,999.\n\ If\ we\ just\ use\ 10^(length),\ this\ would\ generate\ any\ number\ under\ 1,000,000.\n\ This\ is\ an\ issue\ since\ any\ integers\ below\ 100,000\ can\ be\ used,\ which\ would\ be\ incorrect.\n\ By\ using\ the\ offset\ of\ a\ factor\ of\ 10\ below\ the\ desired\ length\ we\ can\ generate\ between\ 0\ and\ 899,999.\n\ After\ this,\ we\ can\ add\ 100,000\ back\ to\ the\ number\ to\ ensure\ a\ baseline\ length\ is\ maintained.\n\ \n\ Note\:\ I\ am\ aware\ that\ this\ is\ overengineered,\ and\ that\ several\ random\ integers\ of\ amount\ @length\ could\ be\ used,\ \n\ but\ this\ is\ considerably\ more\ efficient\ since\ there\ is\ no\ iteration\ involved\ in\ the\ creation\ of\ the\ ID.\ O(1)\n
|
||||
comment6.params=
|
||||
comment6.target=void\ printAll()
|
||||
comment6.text=\n\ Prints\ to\ the\ terminal,\ in\ a\ human-readable\ format,\ all\ items\ in\ the\ itemList\n\ \n\ Contains\ a\ marker\ at\ the\ start\ and\ end\ to\ visualise\ in\ terminal\ output.\n
|
||||
comment6.target=void\ printLibraryReservations()
|
||||
comment6.text=\n\ Prints\ to\ the\ terminal,\ in\ a\ human-readable\ format,\ library\ reservation\ in\ the\ itemList\n\ \n\ Contains\ a\ marker\ at\ the\ start\ and\ end\ to\ visualise\ in\ terminal\ output.\n
|
||||
comment7.params=
|
||||
comment7.target=void\ readData()
|
||||
comment7.text=\n\ A\ method\ to\ read\ all\ data\ from\ files\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ This\ will\ create\ the\ corresponding\ objects\ depending\ on\ flags\ contained\ in\ the\ file\n\ and\ populate\ it's\ fields.\n\ \n\ Default\ flag\ value\:\ "book",\ to\ support\ legacy\ files.\ This\ will\ not\ interfere\ with\ \n\ files\ of\ different\ flag\ orders.\n
|
||||
numComments=8
|
||||
comment7.target=void\ printAll()
|
||||
comment7.text=\n\ Prints\ to\ the\ terminal,\ in\ a\ human-readable\ format,\ all\ items\ in\ the\ itemList\n\ \n\ Contains\ a\ marker\ at\ the\ start\ and\ end\ to\ visualise\ in\ terminal\ output.\n
|
||||
comment8.params=start\ end
|
||||
comment8.target=void\ printDiaryEntries(java.lang.String,\ java.lang.String)
|
||||
comment9.params=
|
||||
comment9.target=void\ writeLibraryReservationData()
|
||||
comment9.text=\n\ Write\ all\ current\ library\ reservations\ to\ a\ file\ specified\ by\ the\ user.\n
|
||||
numComments=15
|
||||
|
@@ -1,11 +1,3 @@
|
||||
|
||||
/**
|
||||
* Class to create objects of a Library, which can hold and report on assets held within
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @3.0
|
||||
*/
|
||||
|
||||
// Import all required libraries. Not using .* as it is not good practice due to potential conflicts.
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
@@ -14,21 +6,33 @@ import java.util.Scanner;
|
||||
import java.util.Random;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Date;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Class to create objects of a Library, which can hold and report on assets held within
|
||||
*
|
||||
* @author George Wilkinson
|
||||
* @version 3.0
|
||||
*/
|
||||
public class Library
|
||||
{
|
||||
// private List<LibraryItem> itemList; // Initialise an ArrayList of name itemList to store Library Items
|
||||
// private List<LibraryUser> userList; // Initialise an ArrayList of name userList to store Library Users
|
||||
private HashSet<String> uuidSet; // Initialise a Hash Set of name uuidSet ( unique user identifier ) to store unique user IDs for efficient O(1) searching
|
||||
|
||||
/* No longer needed, as we can use the keys of customerMap.
|
||||
private HashSet<String> uuidSet; // Initialise a Hash Set of name uuidSet ( unique user identifier ) to store unique user IDs for efficient O(1) searching
|
||||
*/
|
||||
|
||||
private Map<String, LibraryUser> customerMap;
|
||||
private Map<String, LibraryItem> itemsMap;
|
||||
private Map<String, LibraryReservation> libraryReservationMap;
|
||||
|
||||
private Diary diary;
|
||||
/*
|
||||
* Constructor for objects of class Library
|
||||
*/
|
||||
@@ -36,17 +40,26 @@ public class Library
|
||||
{
|
||||
// itemList = new ArrayList<LibraryItem>();
|
||||
// userList = new ArrayList<LibraryUser>();
|
||||
uuidSet = new HashSet<String>();
|
||||
|
||||
/* No longer needed, can use keys of customerMap.
|
||||
uuidSet = new HashSet<String>();
|
||||
*/
|
||||
|
||||
customerMap = new HashMap<String, LibraryUser>();
|
||||
itemsMap = new HashMap<String, LibraryItem>();
|
||||
libraryReservationMap = new HashMap<String, LibraryReservation>();
|
||||
diary = new Diary();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Storing Objects Start
|
||||
*/
|
||||
|
||||
/*
|
||||
* Inserts object value item alongside key of @itemCode into @itemsMap.
|
||||
*/
|
||||
public void storeItem( LibraryItem item )
|
||||
private void storeItem( LibraryItem item )
|
||||
{
|
||||
// itemList.add( item );
|
||||
itemsMap.put( item.getItemCode(), item );
|
||||
@@ -56,31 +69,55 @@ public class Library
|
||||
* Inserts object value user alongside key of @userID into @customerMap.
|
||||
* If the userID is set to unknown, it will call @generateUserID.
|
||||
*/
|
||||
public void storeUser( LibraryUser user )
|
||||
private void storeUser( LibraryUser user )
|
||||
{
|
||||
// userList.add( user );
|
||||
System.out.println( "User Storing: " + user.getFirstName() );
|
||||
if ( user.getUserID().equals( "unknown" ) )
|
||||
{
|
||||
user.setUserID( generateUserID( "AB-", 6 ) );
|
||||
}
|
||||
customerMap.put( user.getUserID(), user );
|
||||
customerMap.put( user.getUserID(), user ); // Store the user along with the userID.
|
||||
}
|
||||
|
||||
/*
|
||||
* Inserts object value reservation alongside key of @reservationNo into @libraryReservationMap.
|
||||
*/
|
||||
public void storeLibraryReservation( LibraryReservation reservation )
|
||||
private void storeLibraryReservation( LibraryReservation reservation )
|
||||
{
|
||||
libraryReservationMap.put( reservation.getReservationNo(), reservation );
|
||||
diary.addReservation( reservation );
|
||||
}
|
||||
|
||||
public void generateReservationNo()
|
||||
/**
|
||||
* Storing Objects End
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Generate IDs Start
|
||||
*/
|
||||
|
||||
/*
|
||||
* Generate a sequential reservation number. Since Maps do not have an index, we cannot simply get the last value,
|
||||
* and recursion would be too intensive for this application. As a placeholder for the file output, a field variable
|
||||
* is used to hold the last highest value for the reservation number. Unlike @generateUserID, this has a maximum value
|
||||
* hardcoded to the spec. This likely will not be an issue since we can still have 1,000,000 reservations.
|
||||
*/
|
||||
public String generateReservationNo()
|
||||
{
|
||||
if( libraryReservationMap.values() = null )
|
||||
return "000001";
|
||||
|
||||
/*
|
||||
* Originally, I did not check if the number was already taken, however the last part of step 4 introduced deletion.
|
||||
* When a reservation is deleted that does not have the highest reservation number, conflicting reservation numbers are generated.
|
||||
* e.g. 5 reservations, reservation 3 ID: 000003 is deleted. The next reservation number would be 000004, as the size + 1 = 4
|
||||
*/
|
||||
String candidateNo = String.format("%06d", libraryReservationMap.size() + 1);
|
||||
for ( int i = 1; libraryReservationMap.containsKey( candidateNo ); i++ )
|
||||
{
|
||||
candidateNo = String.format( "%06d", libraryReservationMap.size() + i );
|
||||
}
|
||||
return candidateNo;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a random unique user ID by specifying
|
||||
* @prefix - arbitrary alphanumeric prefix
|
||||
@@ -97,13 +134,13 @@ public class Library
|
||||
* Note: I am aware that this is overengineered, and that several random integers of amount @length could be used,
|
||||
* but this is considerably more efficient since there is no iteration involved in the creation of the ID. O(1)
|
||||
*/
|
||||
public String generateUserID( String prefix, int length )
|
||||
private String generateUserID( String prefix, int length )
|
||||
{
|
||||
Random random = new Random();
|
||||
final int offset = (int) Math.pow( 10, (length-1) ); // Static integer equal to 10^(length-1) lower than length. This will allow for the factor to be consistent.
|
||||
int intLength = (int) ( Math.pow( 10, length ) ) - offset ; // Integer equal to 10^(length) minus the offset. This creates a ceiling for the ID range.
|
||||
|
||||
if ( uuidSet.size() > ( intLength - 1 ) ) { // No idea why I get an error for equals FIX LATER
|
||||
if ( customerMap.size() == intLength ) {
|
||||
System.out.println("Too many user IDs delegated for current range, increasing ID range by a factor of 10");
|
||||
return generateUserID( prefix, length+1 );
|
||||
/*
|
||||
@@ -118,19 +155,100 @@ public class Library
|
||||
* Add the offset to a random number, to create a floor to the ID range.
|
||||
*/
|
||||
|
||||
if ( uuidSet.contains( uuid ) )
|
||||
if ( customerMap.containsKey( uuid ) ) // Previously uuidSet.contains, replaced to de-dupe held data.
|
||||
{
|
||||
generateUserID( prefix, length ); // If the ID generated is already contained in the hashset, the method should be called again.
|
||||
}
|
||||
|
||||
uuidSet.add( uuid ); // Add the UUID to the hash set so it cannot be returned from this method more than once.
|
||||
|
||||
/* No longer needed, as we add the user and the ID to the customerMap when storing.
|
||||
* uuidSet.add( uuid )
|
||||
*/
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate IDs End
|
||||
*/
|
||||
|
||||
/**
|
||||
* Print Object Details Start
|
||||
*/
|
||||
|
||||
/*
|
||||
* Prints to the terminal, in a human-readable format, library reservation in the itemList
|
||||
*
|
||||
* Contains a marker at the start and end to visualise in terminal output.
|
||||
*/
|
||||
public void printLibraryReservations() {
|
||||
System.out.println( "Reservation Details Start" );
|
||||
for ( LibraryReservation reservation : libraryReservationMap.values() ){
|
||||
System.out.println("---------------");
|
||||
reservation.printDetails();
|
||||
}
|
||||
System.out.println( "---------------\nReservation Details End\n" );
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints to the terminal, in a human-readable format, all items in the itemList
|
||||
*
|
||||
* Contains a marker at the start and end to visualise in terminal output.
|
||||
*/
|
||||
public void printAll()
|
||||
{
|
||||
System.out.println("\n\nItem Details Start");
|
||||
for( LibraryItem item : itemsMap.values() )
|
||||
{
|
||||
System.out.println("---------------");
|
||||
item.printDetails();
|
||||
}
|
||||
System.out.println("---------------");
|
||||
System.out.println("Items Details End\n\n---------------\n\nUser Details Start\n");
|
||||
for ( LibraryUser user : customerMap.values() )
|
||||
{
|
||||
System.out.println("---------------");
|
||||
user.printDetails();
|
||||
}
|
||||
System.out.println("---------------\nUser Details End\n");
|
||||
printLibraryReservations();
|
||||
}
|
||||
|
||||
public void printDiaryEntries( String start, String end )
|
||||
{
|
||||
diary.printEntries( DateUtil.convertStringToDate( start ), DateUtil.convertStringToDate( end ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print Object Details End
|
||||
*/
|
||||
|
||||
/**
|
||||
* Write Files Start
|
||||
*/
|
||||
|
||||
/*
|
||||
* Write all current library reservations to a file specified by the user.
|
||||
*/
|
||||
public void writeLibraryReservationData()
|
||||
{
|
||||
try {
|
||||
Frame frame = null; // Initialise null frame
|
||||
FileDialog fileBox = new FileDialog( frame, "Save", FileDialog.SAVE ); // Initialise file dialog box to save written data.
|
||||
fileBox.setVisible( true );
|
||||
PrintWriter writer = new PrintWriter( new File( fileBox.getDirectory() + fileBox.getFile() ) );
|
||||
|
||||
for ( LibraryReservation reservation : libraryReservationMap.values() ) {
|
||||
reservation.writeData( writer );
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
|
||||
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A method to output all user data to a file using a fileDialog to specify file location.
|
||||
*
|
||||
* Note: Potentially could implement the HashSet made for GenerateUserID to avoid unnecessary recursion.
|
||||
*/
|
||||
public void writeUserData()
|
||||
{
|
||||
@@ -140,6 +258,7 @@ public class Library
|
||||
fileBox.setVisible( true );
|
||||
PrintWriter writer = new PrintWriter( new File( fileBox.getDirectory() + fileBox.getFile() ) );
|
||||
// for ( LibraryUser user : userList ){
|
||||
writer.println("[Library User data]");
|
||||
for ( LibraryUser user : customerMap.values() ) {
|
||||
user.writeData( writer );
|
||||
}
|
||||
@@ -150,20 +269,37 @@ public class Library
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints to the terminal, in a human-readable format, all items in the itemList
|
||||
*
|
||||
* Contains a marker at the start and end to visualise in terminal output.
|
||||
/**
|
||||
* Write Files End
|
||||
*/
|
||||
public void printAll()
|
||||
|
||||
/**
|
||||
* Read Files Start
|
||||
*/
|
||||
|
||||
/*
|
||||
* Read Library Reservation Data from a file specified by the user.
|
||||
*/
|
||||
public void readLibraryReservationData()
|
||||
{
|
||||
System.out.println("\n\nStart Detail Print");
|
||||
for( LibraryItem item : itemsMap.values() )
|
||||
{
|
||||
System.out.println("---------------");
|
||||
item.printDetails();
|
||||
try {
|
||||
Frame frame = null; // Initialise null frame
|
||||
FileDialog fileBox = new FileDialog( frame, "Load", FileDialog.LOAD ); // Initialise file dialog box to save written data.
|
||||
fileBox.setVisible( true );
|
||||
Scanner reservationScanner = new Scanner ( new File( fileBox.getDirectory() + fileBox.getFile() ) );
|
||||
while ( reservationScanner.hasNextLine() )
|
||||
{
|
||||
Scanner detailScanner = new Scanner( reservationScanner.nextLine() ).useDelimiter(",");
|
||||
LibraryReservation reservation = new LibraryReservation();
|
||||
reservation.readData( detailScanner );
|
||||
storeLibraryReservation( reservation );
|
||||
detailScanner.close();
|
||||
}
|
||||
reservationScanner.close(); // Close Scanner
|
||||
}
|
||||
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
|
||||
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
|
||||
}
|
||||
System.out.println("End Detail Print\n");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -184,7 +320,7 @@ public class Library
|
||||
Scanner fileScanner = new Scanner( new File( fileBox.getDirectory() + fileBox.getFile() ) );
|
||||
String typeFlag = "book"; // Set a default flag to support legacy files.
|
||||
|
||||
while( fileScanner.hasNextLine() ){
|
||||
while( fileScanner.hasNextLine() ) {
|
||||
|
||||
String lineItem = fileScanner.nextLine();
|
||||
|
||||
@@ -211,54 +347,116 @@ public class Library
|
||||
|
||||
}
|
||||
|
||||
// Could be a switch case to be more efficient
|
||||
// Unfortunately cannot use switch case with string comparisons in Java 8.
|
||||
// Check current flag for data processing.
|
||||
else {
|
||||
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list
|
||||
LibraryItem item = null; // Initialise LibraryItem object. Java compiler was being cautious here, so I have to assign the value null.
|
||||
if ( typeFlag.equals( "book" ) ) {
|
||||
// Process Book Data
|
||||
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list
|
||||
LibraryItem book = new Book();
|
||||
book.readItemData( detailScanner );
|
||||
storeItem( book ); // Store the new LibraryItem in the itemList
|
||||
item = new Book();
|
||||
}
|
||||
else if ( typeFlag.equals( "periodical" ) ) {
|
||||
// Process Periodic Data
|
||||
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(",");
|
||||
LibraryItem periodical = new Periodical();
|
||||
periodical.readItemData( detailScanner );
|
||||
storeItem( periodical );
|
||||
item = new Periodical();
|
||||
}
|
||||
else if ( typeFlag.equals( "cd" ) ) {
|
||||
//Process CD Data
|
||||
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(",");
|
||||
LibraryItem cd = new CD();
|
||||
cd.readItemData( detailScanner );
|
||||
storeItem( cd );
|
||||
item = new CD();
|
||||
}
|
||||
else if ( typeFlag.equals( "dvd" ) ) {
|
||||
//Process DVD Data
|
||||
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(",");
|
||||
LibraryItem dvd = new DVD();
|
||||
dvd.readItemData( detailScanner );
|
||||
storeItem( dvd );
|
||||
item = new DVD();
|
||||
}
|
||||
else if ( typeFlag.equals( "user" ) ) {
|
||||
//Process User Data
|
||||
System.out.println( "User: " + lineItem );
|
||||
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(",");
|
||||
LibraryUser user = new LibraryUser();
|
||||
user.readData( detailScanner );
|
||||
storeUser( user );
|
||||
continue;
|
||||
}
|
||||
else if ( typeFlag.equals( "generic" ) ) {
|
||||
// Output unaccepted lines to terminal
|
||||
System.out.println( lineItem );
|
||||
continue;
|
||||
}
|
||||
|
||||
item.readItemData( detailScanner );
|
||||
storeItem( item );
|
||||
detailScanner.close();
|
||||
}
|
||||
}
|
||||
fileScanner.close();
|
||||
}
|
||||
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
|
||||
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Files End
|
||||
*/
|
||||
|
||||
/**
|
||||
* Other Methods
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create a reservation to allow a user to reserve an item from the library.
|
||||
*/
|
||||
public boolean makeLibraryReservation( String userID, String itemCode, String startDate, int noOfDays )
|
||||
{
|
||||
if ( !customerMap.containsKey( userID ) )
|
||||
{
|
||||
System.out.println( "User does not exist" );
|
||||
return false;
|
||||
}
|
||||
if ( !itemsMap.containsKey( itemCode ) )
|
||||
{
|
||||
System.out.println( "Item does not exist in library" );
|
||||
return false;
|
||||
}
|
||||
if ( !DateUtil.isValidDateString( startDate ) )
|
||||
{
|
||||
System.out.println( "Date is not valid" );
|
||||
return false;
|
||||
}
|
||||
if ( !(noOfDays > 0) )
|
||||
{
|
||||
System.out.println( "Reservation must be more than 0 days" );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Date start = DateUtil.convertStringToDate( startDate );
|
||||
/*
|
||||
* Unneeded, since addReservations returns any item currently on loan. Dates do not need to be checked for every day in loan.
|
||||
* Date end = DateUtil.incrementDate( start, noOfDays-1 );
|
||||
*/
|
||||
String rID = generateReservationNo();
|
||||
LibraryReservation reservation = new LibraryReservation( rID, itemCode, userID, startDate, noOfDays );
|
||||
/** Instead of the following For loop, I could've implemented
|
||||
* Arrays.asList( diary.getReservation( start, end ).contains( reservation )
|
||||
* Although this would've been easier, this implementation is more in the scope of what we have learned.
|
||||
**/
|
||||
for ( LibraryReservation diaryReservation : diary.getReservations( start ) )
|
||||
{
|
||||
if ( diaryReservation.toString().equals( reservation.toString() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
storeLibraryReservation( reservation );
|
||||
return true;
|
||||
}
|
||||
|
||||
public void deleteLibraryReservation( String reservationNo )
|
||||
{
|
||||
if ( libraryReservationMap.containsKey( reservationNo ) )
|
||||
{
|
||||
diary.deleteReservation( libraryReservationMap.get( reservationNo ) );
|
||||
libraryReservationMap.remove( reservationNo );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@@ -1,15 +1,13 @@
|
||||
|
||||
/**
|
||||
* Superclass of items / assets stored in a Library.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @3.1
|
||||
*/
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Superclass of items / assets stored in a Library.
|
||||
*
|
||||
* @author George Wilkinson
|
||||
* @version 3.1
|
||||
*/
|
||||
public abstract class LibraryItem
|
||||
{
|
||||
// instance variables
|
||||
|
Binary file not shown.
@@ -3,33 +3,44 @@ comment0.params=reservationNo\ itemCode\ userID\ startDate\ noOfDays
|
||||
comment0.target=LibraryReservation(java.lang.String,\ java.lang.String,\ java.lang.String,\ java.lang.String,\ int)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryReservation\n
|
||||
comment1.params=
|
||||
comment1.target=java.lang.String\ getReservationNo()
|
||||
comment1.text=\n\ Return\ value\ of\ @reservationNo\n
|
||||
comment10.params=noOfDays
|
||||
comment10.target=void\ setNoOfDays(int)
|
||||
comment10.text=\n\ Set\ @noOfDays\ to\ a\ new\ value\n
|
||||
comment1.target=LibraryReservation()
|
||||
comment10.params=
|
||||
comment10.target=int\ getNoOfDays()
|
||||
comment10.text=\n\ Return\ value\ of\ @noOfDays\n
|
||||
comment11.params=reservationNo
|
||||
comment11.target=void\ setReservationNo(java.lang.String)
|
||||
comment11.text=\n\ Set\ @reservationNo\ to\ a\ new\ value\n
|
||||
comment12.params=itemCode
|
||||
comment12.target=void\ setItemCode(java.lang.String)
|
||||
comment12.text=\n\ Set\ @itemCode\ to\ a\ new\ value\n
|
||||
comment13.params=userID
|
||||
comment13.target=void\ setUserID(java.lang.String)
|
||||
comment13.text=\n\ Set\ @userID\ to\ a\ new\ value\n
|
||||
comment14.params=startDate
|
||||
comment14.target=void\ setStartDate(java.lang.String)
|
||||
comment14.text=\n\ Set\ @startDate\ to\ a\ new\ value\n
|
||||
comment15.params=noOfDays
|
||||
comment15.target=void\ setNoOfDays(int)
|
||||
comment15.text=\n\ Set\ @noOfDays\ to\ a\ new\ value\n
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getItemCode()
|
||||
comment2.text=\n\ Return\ value\ of\ @itemCode\n
|
||||
comment2.target=java.lang.String\ toString()
|
||||
comment3.params=
|
||||
comment3.target=java.lang.String\ getUserID()
|
||||
comment3.text=\n\ Return\ value\ of\ @userID\n
|
||||
comment4.params=
|
||||
comment4.target=java.util.Date\ getStartDate()
|
||||
comment4.text=\n\ Return\ value\ of\ @startDate\n
|
||||
comment5.params=
|
||||
comment5.target=int\ getNoOfDays()
|
||||
comment5.text=\n\ Return\ value\ of\ @noOfDays\n
|
||||
comment6.params=reservationNo
|
||||
comment6.target=void\ setReservationNo(java.lang.String)
|
||||
comment6.text=\n\ Set\ @reservationNo\ to\ a\ new\ value\n
|
||||
comment7.params=itemCode
|
||||
comment7.target=void\ setItemCode(java.lang.String)
|
||||
comment7.text=\n\ Set\ @itemCode\ to\ a\ new\ value\n
|
||||
comment8.params=userID
|
||||
comment8.target=void\ setUserID(java.lang.String)
|
||||
comment8.text=\n\ Set\ @userID\ to\ a\ new\ value\n
|
||||
comment9.params=startDate
|
||||
comment9.target=void\ setStartDate(java.lang.String)
|
||||
comment9.text=\n\ Set\ @startDate\ to\ a\ new\ value\n
|
||||
numComments=11
|
||||
comment3.target=void\ printDetails()
|
||||
comment3.text=\n\ Prints\ to\ terminal,\ the\ details\ of\ the\ reservation.\n
|
||||
comment4.params=writer
|
||||
comment4.target=void\ writeData(java.io.PrintWriter)
|
||||
comment5.params=detailScanner
|
||||
comment5.target=void\ readData(java.util.Scanner)
|
||||
comment6.params=
|
||||
comment6.target=java.lang.String\ getReservationNo()
|
||||
comment6.text=\n\ Return\ value\ of\ @reservationNo\n
|
||||
comment7.params=
|
||||
comment7.target=java.lang.String\ getItemCode()
|
||||
comment7.text=\n\ Return\ value\ of\ @itemCode\n
|
||||
comment8.params=
|
||||
comment8.target=java.lang.String\ getUserID()
|
||||
comment8.text=\n\ Return\ value\ of\ @userID\n
|
||||
comment9.params=
|
||||
comment9.target=java.util.Date\ getStartDate()
|
||||
comment9.text=\n\ Return\ value\ of\ @startDate\n
|
||||
numComments=16
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
|
||||
import java.util.Date;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class LibraryReservation
|
||||
{
|
||||
@@ -29,6 +31,42 @@ public class LibraryReservation
|
||||
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
|
||||
*/
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=LibraryUser()
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser\n
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser.\ As\ fields\ \n
|
||||
comment1.params=
|
||||
comment1.target=java.lang.String\ getUserID()
|
||||
comment1.text=\n\ Accessor\ start\ -\ return\ values\ of\ corresponding\ variables.\n
|
||||
|
@@ -15,7 +15,7 @@ public class LibraryUser
|
||||
private String userID, surname, firstName, otherInitials, title;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class LibraryUser
|
||||
* Constructor for objects of class LibraryUser. As fields
|
||||
*/
|
||||
public LibraryUser(){}
|
||||
|
||||
|
@@ -0,0 +1 @@
|
||||
0,LM005002,AB-217000,24-03-2024,3
|
@@ -1,4 +1,5 @@
|
||||
AB-906182, Smith, Sara, C, Ms
|
||||
AB-241496, Evans, David, , Dr
|
||||
AB-769390, Newton, David, E, Dr
|
||||
AB-396038, Gregson, Brian, R T, Mr
|
||||
[Library User data]
|
||||
AB-217000, Gregson, Brian, R T, Mr
|
||||
AB-711612, Smith, Sara, C, Ms
|
||||
AB-861906, Evans, David, , Dr
|
||||
AB-573164, Newton, David, E, Dr
|
||||
|
379
Semester 2/Programming 2/Project/Part 2/doc/DateUtil.html
Normal file
379
Semester 2/Programming 2/Project/Part 2/doc/DateUtil.html
Normal file
@@ -0,0 +1,379 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
DateUtil
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
<SCRIPT type="text/javascript">
|
||||
function windowTitle()
|
||||
{
|
||||
if (location.href.indexOf('is-external=true') == -1) {
|
||||
parent.document.title="DateUtil";
|
||||
}
|
||||
}
|
||||
</SCRIPT>
|
||||
<NOSCRIPT>
|
||||
</NOSCRIPT>
|
||||
|
||||
</HEAD>
|
||||
|
||||
<BODY BGCOLOR="white" onload="windowTitle();">
|
||||
<HR>
|
||||
|
||||
<HR>
|
||||
<!-- ======== START OF CLASS DATA ======== -->
|
||||
<H2>
|
||||
Class DateUtil</H2>
|
||||
<PRE>
|
||||
java.lang.Object
|
||||
<IMG SRC="./resources/inherit.gif" ALT="extended by "><B>DateUtil</B>
|
||||
</PRE>
|
||||
<HR>
|
||||
<DL>
|
||||
<DT><PRE>public class <B>DateUtil</B><DT>extends java.lang.Object</DL>
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
A class DateUtil with the following methods for dealing with dates.
|
||||
|
||||
public static String convertDateToLongString(Date date)
|
||||
public static String convertDateToShortString(Date date)
|
||||
public static Date convertStringToDate(String dateString)
|
||||
public static int daysBetween(Date startDate, Date endDate)
|
||||
public static Date incrementDate(Date date, int noOfDays)
|
||||
public static boolean isLeapYear(int year)
|
||||
public static boolean isValidDateString(String dateString)
|
||||
public static Date nextDate(Date date)
|
||||
<P>
|
||||
|
||||
<P>
|
||||
<DL>
|
||||
<DT><B>Author:</B></DT>
|
||||
<DD>D E Newton</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<P>
|
||||
<!-- =========== FIELD SUMMARY =========== -->
|
||||
|
||||
<A NAME="field_summary"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||
<B>Field Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static java.text.SimpleDateFormat</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#dateFormatter">dateFormatter</A></B></CODE>
|
||||
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
|
||||
|
||||
<A NAME="constructor_summary"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||
<B>Constructor Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD><CODE><B><A HREF="DateUtil.html#DateUtil()">DateUtil</A></B>()</CODE>
|
||||
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<!-- ========== METHOD SUMMARY =========== -->
|
||||
|
||||
<A NAME="method_summary"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||
<B>Method Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static java.lang.String</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#convertDateToLongString(java.util.Date)">convertDateToLongString</A></B>(java.util.Date date)</CODE>
|
||||
|
||||
<BR>
|
||||
Converts a Date object to a corresponding String in
|
||||
the long date pattern style "Saturday, 25 March 2023".</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static java.lang.String</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#convertDateToShortString(java.util.Date)">convertDateToShortString</A></B>(java.util.Date date)</CODE>
|
||||
|
||||
<BR>
|
||||
Converts a Date object to a corresponding String in
|
||||
the short date pattern style "25-03-2023".</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static java.util.Date</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#convertStringToDate(java.lang.String)">convertStringToDate</A></B>(java.lang.String dateString)</CODE>
|
||||
|
||||
<BR>
|
||||
Converts a string in the short date pattern style "25-03-2023"
|
||||
to a corresponding Date object.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static int</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#daysBetween(java.util.Date, java.util.Date)">daysBetween</A></B>(java.util.Date startDate,
|
||||
java.util.Date endDate)</CODE>
|
||||
|
||||
<BR>
|
||||
Calculates the number of days between two given dates, startDate and endDate.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static java.util.Date</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#incrementDate(java.util.Date, int)">incrementDate</A></B>(java.util.Date date,
|
||||
int noOfDays)</CODE>
|
||||
|
||||
<BR>
|
||||
Given date, a Date object, and noOfDays, an int, the method returns
|
||||
a Date object corresponding to noOfDays later than date.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static boolean</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#isLeapYear(int)">isLeapYear</A></B>(int year)</CODE>
|
||||
|
||||
<BR>
|
||||
Given year, an int, the method checks to see if the year
|
||||
is a leap year.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static boolean</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#isValidDateString(java.lang.String)">isValidDateString</A></B>(java.lang.String dateString)</CODE>
|
||||
|
||||
<BR>
|
||||
Given dateString, a String, the method checks to see if string
|
||||
corresponds to a valid shortDatePattern.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>static java.util.Date</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="DateUtil.html#nextDate(java.util.Date)">nextDate</A></B>(java.util.Date date)</CODE>
|
||||
|
||||
<BR>
|
||||
Given date, a Date object, the method returns
|
||||
a Date object corresponding to the next day.</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
|
||||
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<P>
|
||||
|
||||
<!-- ============ FIELD DETAIL =========== -->
|
||||
|
||||
<A NAME="field_detail"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||
<B>Field Detail</B></FONT></TH>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<A NAME="dateFormatter"><!-- --></A><H3>
|
||||
dateFormatter</H3>
|
||||
<PRE>
|
||||
public static java.text.SimpleDateFormat <B>dateFormatter</B></PRE>
|
||||
<DL>
|
||||
<DL>
|
||||
</DL>
|
||||
</DL>
|
||||
|
||||
<!-- ========= CONSTRUCTOR DETAIL ======== -->
|
||||
|
||||
<A NAME="constructor_detail"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||
<B>Constructor Detail</B></FONT></TH>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<A NAME="DateUtil()"><!-- --></A><H3>
|
||||
DateUtil</H3>
|
||||
<PRE>
|
||||
public <B>DateUtil</B>()</PRE>
|
||||
<DL>
|
||||
</DL>
|
||||
|
||||
<!-- ============ METHOD DETAIL ========== -->
|
||||
|
||||
<A NAME="method_detail"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||
<B>Method Detail</B></FONT></TH>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<A NAME="convertDateToLongString(java.util.Date)"><!-- --></A><H3>
|
||||
convertDateToLongString</H3>
|
||||
<PRE>
|
||||
public static java.lang.String <B>convertDateToLongString</B>(java.util.Date date)</PRE>
|
||||
<DL>
|
||||
<DD>Converts a Date object to a corresponding String in
|
||||
the long date pattern style "Saturday, 25 March 2023".
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>date</CODE> - a Date object
|
||||
<DT><B>Returns:</B><DD>a String, containing a long date pattern</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="convertDateToShortString(java.util.Date)"><!-- --></A><H3>
|
||||
convertDateToShortString</H3>
|
||||
<PRE>
|
||||
public static java.lang.String <B>convertDateToShortString</B>(java.util.Date date)</PRE>
|
||||
<DL>
|
||||
<DD>Converts a Date object to a corresponding String in
|
||||
the short date pattern style "25-03-2023".
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>date</CODE> - a Date object
|
||||
<DT><B>Returns:</B><DD>a String, containing a short date pattern</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="convertStringToDate(java.lang.String)"><!-- --></A><H3>
|
||||
convertStringToDate</H3>
|
||||
<PRE>
|
||||
public static java.util.Date <B>convertStringToDate</B>(java.lang.String dateString)</PRE>
|
||||
<DL>
|
||||
<DD>Converts a string in the short date pattern style "25-03-2023"
|
||||
to a corresponding Date object.
|
||||
|
||||
Any leading or trailing spaces are first removed from the date string.
|
||||
The String parameter that represent a date as a string must be in the
|
||||
format dd-mm-yyy (e.g. 25-03-2023 or 25-3-2023) where dd represents
|
||||
one or two digits representing the day in the month, similarly for
|
||||
mm representing the month in the year and yyyy represents the four
|
||||
digits for the year.
|
||||
|
||||
A RuntimeException is thrown if the date string is not recognised as
|
||||
a valid date. Such exceptions do not need to be caught or thrown as
|
||||
they are unchecked exceptions, but can be caught if necessary.
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>dateString</CODE> - a Date object
|
||||
<DT><B>Returns:</B><DD>the Date object</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="daysBetween(java.util.Date, java.util.Date)"><!-- --></A><H3>
|
||||
daysBetween</H3>
|
||||
<PRE>
|
||||
public static int <B>daysBetween</B>(java.util.Date startDate,
|
||||
java.util.Date endDate)</PRE>
|
||||
<DL>
|
||||
<DD>Calculates the number of days between two given dates, startDate and endDate.
|
||||
|
||||
If startDate is after endDate then the number of days returned will be negative.
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>startDate</CODE> - a Date object<DD><CODE>endDate</CODE> - a Date object
|
||||
<DT><B>Returns:</B><DD>an int, number of days between the dates</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="incrementDate(java.util.Date, int)"><!-- --></A><H3>
|
||||
incrementDate</H3>
|
||||
<PRE>
|
||||
public static java.util.Date <B>incrementDate</B>(java.util.Date date,
|
||||
int noOfDays)</PRE>
|
||||
<DL>
|
||||
<DD>Given date, a Date object, and noOfDays, an int, the method returns
|
||||
a Date object corresponding to noOfDays later than date.
|
||||
|
||||
If noOfDays is negative, the resulting Date object will be before date.
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>date</CODE> - a Date object<DD><CODE>noOfDays</CODE> - an int
|
||||
<DT><B>Returns:</B><DD>a Date</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="isLeapYear(int)"><!-- --></A><H3>
|
||||
isLeapYear</H3>
|
||||
<PRE>
|
||||
public static boolean <B>isLeapYear</B>(int year)</PRE>
|
||||
<DL>
|
||||
<DD>Given year, an int, the method checks to see if the year
|
||||
is a leap year.
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>year,</CODE> - an int
|
||||
<DT><B>Returns:</B><DD>a boolean, true only if the year is a leap year.</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="isValidDateString(java.lang.String)"><!-- --></A><H3>
|
||||
isValidDateString</H3>
|
||||
<PRE>
|
||||
public static boolean <B>isValidDateString</B>(java.lang.String dateString)</PRE>
|
||||
<DL>
|
||||
<DD>Given dateString, a String, the method checks to see if string
|
||||
corresponds to a valid shortDatePattern.
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>dateString,</CODE> - a String
|
||||
<DT><B>Returns:</B><DD>a boolean, true only if the dateString is a valid pattern</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="nextDate(java.util.Date)"><!-- --></A><H3>
|
||||
nextDate</H3>
|
||||
<PRE>
|
||||
public static java.util.Date <B>nextDate</B>(java.util.Date date)</PRE>
|
||||
<DL>
|
||||
<DD>Given date, a Date object, the method returns
|
||||
a Date object corresponding to the next day.
|
||||
<P>
|
||||
<DD><DL>
|
||||
<DT><B>Parameters:</B><DD><CODE>noOfDays</CODE> - an int
|
||||
<DT><B>Returns:</B><DD>a Date</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<!-- ========= END OF CLASS DATA ========= -->
|
||||
<HR>
|
||||
|
||||
<HR>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
220
Semester 2/Programming 2/Project/Part 2/doc/Diary.html
Normal file
220
Semester 2/Programming 2/Project/Part 2/doc/Diary.html
Normal file
@@ -0,0 +1,220 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 21:31:47 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
Diary
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
<SCRIPT type="text/javascript">
|
||||
function windowTitle()
|
||||
{
|
||||
if (location.href.indexOf('is-external=true') == -1) {
|
||||
parent.document.title="Diary";
|
||||
}
|
||||
}
|
||||
</SCRIPT>
|
||||
<NOSCRIPT>
|
||||
</NOSCRIPT>
|
||||
|
||||
</HEAD>
|
||||
|
||||
<BODY BGCOLOR="white" onload="windowTitle();">
|
||||
<HR>
|
||||
|
||||
<HR>
|
||||
<!-- ======== START OF CLASS DATA ======== -->
|
||||
<H2>
|
||||
Class Diary</H2>
|
||||
<PRE>
|
||||
java.lang.Object
|
||||
<IMG SRC="./resources/inherit.gif" ALT="extended by "><B>Diary</B>
|
||||
</PRE>
|
||||
<HR>
|
||||
<DL>
|
||||
<DT><PRE>public class <B>Diary</B><DT>extends java.lang.Object</DL>
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
A class Diary that represents a "diary" of library item reservations.
|
||||
|
||||
The diary is structured as a Map of entries in which each entry corresponds
|
||||
to a specific day. As the map is not accessed in a sequential fashion, it
|
||||
doesn't matter whether the actual map class is a TreeMap or a HashMap.
|
||||
<P>
|
||||
|
||||
<P>
|
||||
<DL>
|
||||
<DT><B>Author:</B></DT>
|
||||
<DD>D E Newton</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<P>
|
||||
|
||||
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
|
||||
|
||||
<A NAME="constructor_summary"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||
<B>Constructor Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD><CODE><B><A HREF="Diary.html#Diary()">Diary</A></B>()</CODE>
|
||||
|
||||
<BR>
|
||||
Constructor for objects of class Diary</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<!-- ========== METHOD SUMMARY =========== -->
|
||||
|
||||
<A NAME="method_summary"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||
<B>Method Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE> void</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="Diary.html#addReservation(LibraryReservation)">addReservation</A></B>(LibraryReservation itemReservation)</CODE>
|
||||
|
||||
<BR>
|
||||
Method for adding a reservation to the diary.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE> void</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="Diary.html#deleteReservation(LibraryReservation)">deleteReservation</A></B>(LibraryReservation itemReservation)</CODE>
|
||||
|
||||
<BR>
|
||||
Method for deleting a reservation from the diary.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE> LibraryReservation[]</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="Diary.html#getReservations(java.util.Date)">getReservations</A></B>(java.util.Date date)</CODE>
|
||||
|
||||
<BR>
|
||||
Accessor method for returning all reservations that have entries
|
||||
in the diary for a particular date.</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE> void</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="Diary.html#printEntries(java.util.Date, java.util.Date)">printEntries</A></B>(java.util.Date startDate,
|
||||
java.util.Date endDate)</CODE>
|
||||
|
||||
<BR>
|
||||
Method for displaying the reservations between specified dates.</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
|
||||
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<P>
|
||||
|
||||
<!-- ========= CONSTRUCTOR DETAIL ======== -->
|
||||
|
||||
<A NAME="constructor_detail"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||
<B>Constructor Detail</B></FONT></TH>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<A NAME="Diary()"><!-- --></A><H3>
|
||||
Diary</H3>
|
||||
<PRE>
|
||||
public <B>Diary</B>()</PRE>
|
||||
<DL>
|
||||
<DD>Constructor for objects of class Diary
|
||||
<P>
|
||||
</DL>
|
||||
|
||||
<!-- ============ METHOD DETAIL ========== -->
|
||||
|
||||
<A NAME="method_detail"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||
<B>Method Detail</B></FONT></TH>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<A NAME="addReservation(LibraryReservation)"><!-- --></A><H3>
|
||||
addReservation</H3>
|
||||
<PRE>
|
||||
public void <B>addReservation</B>(LibraryReservation itemReservation)</PRE>
|
||||
<DL>
|
||||
<DD>Method for adding a reservation to the diary.
|
||||
<P>
|
||||
<DD><DL>
|
||||
</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="deleteReservation(LibraryReservation)"><!-- --></A><H3>
|
||||
deleteReservation</H3>
|
||||
<PRE>
|
||||
public void <B>deleteReservation</B>(LibraryReservation itemReservation)</PRE>
|
||||
<DL>
|
||||
<DD>Method for deleting a reservation from the diary.
|
||||
<P>
|
||||
<DD><DL>
|
||||
</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="getReservations(java.util.Date)"><!-- --></A><H3>
|
||||
getReservations</H3>
|
||||
<PRE>
|
||||
public LibraryReservation[] <B>getReservations</B>(java.util.Date date)</PRE>
|
||||
<DL>
|
||||
<DD>Accessor method for returning all reservations that have entries
|
||||
in the diary for a particular date.
|
||||
<P>
|
||||
<DD><DL>
|
||||
|
||||
<DT><B>Returns:</B><DD>an array of reservations, or null if no entry for that date</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="printEntries(java.util.Date, java.util.Date)"><!-- --></A><H3>
|
||||
printEntries</H3>
|
||||
<PRE>
|
||||
public void <B>printEntries</B>(java.util.Date startDate,
|
||||
java.util.Date endDate)</PRE>
|
||||
<DL>
|
||||
<DD>Method for displaying the reservations between specified dates.
|
||||
<P>
|
||||
<DD><DL>
|
||||
</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<!-- ========= END OF CLASS DATA ========= -->
|
||||
<HR>
|
||||
|
||||
<HR>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
174
Semester 2/Programming 2/Project/Part 2/doc/Library.html
Normal file
174
Semester 2/Programming 2/Project/Part 2/doc/Library.html
Normal file
@@ -0,0 +1,174 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 11:36:09 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
Library
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
<SCRIPT type="text/javascript">
|
||||
function windowTitle()
|
||||
{
|
||||
if (location.href.indexOf('is-external=true') == -1) {
|
||||
parent.document.title="Library";
|
||||
}
|
||||
}
|
||||
</SCRIPT>
|
||||
<NOSCRIPT>
|
||||
</NOSCRIPT>
|
||||
|
||||
</HEAD>
|
||||
|
||||
<BODY BGCOLOR="white" onload="windowTitle();">
|
||||
<HR>
|
||||
|
||||
<HR>
|
||||
<!-- ======== START OF CLASS DATA ======== -->
|
||||
<H2>
|
||||
Class Library</H2>
|
||||
<PRE>
|
||||
java.lang.Object
|
||||
<IMG SRC="./resources/inherit.gif" ALT="extended by "><B>Library</B>
|
||||
</PRE>
|
||||
<HR>
|
||||
<DL>
|
||||
<DT><PRE>public class <B>Library</B><DT>extends java.lang.Object</DL>
|
||||
</PRE>
|
||||
|
||||
<P>
|
||||
<HR>
|
||||
|
||||
<P>
|
||||
|
||||
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
|
||||
|
||||
<A NAME="constructor_summary"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||
<B>Constructor Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD><CODE><B><A HREF="Library.html#Library()">Library</A></B>()</CODE>
|
||||
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<!-- ========== METHOD SUMMARY =========== -->
|
||||
|
||||
<A NAME="method_summary"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||
<B>Method Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE> void</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="Library.html#printAll()">printAll</A></B>()</CODE>
|
||||
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE> void</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="Library.html#readData()">readData</A></B>()</CODE>
|
||||
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE> void</CODE></FONT></TD>
|
||||
<TD><CODE><B><A HREF="Library.html#writeUserData()">writeUserData</A></B>()</CODE>
|
||||
|
||||
<BR>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
|
||||
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<P>
|
||||
|
||||
<!-- ========= CONSTRUCTOR DETAIL ======== -->
|
||||
|
||||
<A NAME="constructor_detail"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||
<B>Constructor Detail</B></FONT></TH>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<A NAME="Library()"><!-- --></A><H3>
|
||||
Library</H3>
|
||||
<PRE>
|
||||
public <B>Library</B>()</PRE>
|
||||
<DL>
|
||||
</DL>
|
||||
|
||||
<!-- ============ METHOD DETAIL ========== -->
|
||||
|
||||
<A NAME="method_detail"><!-- --></A>
|
||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||
<B>Method Detail</B></FONT></TH>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<A NAME="printAll()"><!-- --></A><H3>
|
||||
printAll</H3>
|
||||
<PRE>
|
||||
public void <B>printAll</B>()</PRE>
|
||||
<DL>
|
||||
<DD><DL>
|
||||
</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="readData()"><!-- --></A><H3>
|
||||
readData</H3>
|
||||
<PRE>
|
||||
public void <B>readData</B>()</PRE>
|
||||
<DL>
|
||||
<DD><DL>
|
||||
</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<HR>
|
||||
|
||||
<A NAME="writeUserData()"><!-- --></A><H3>
|
||||
writeUserData</H3>
|
||||
<PRE>
|
||||
public void <B>writeUserData</B>()</PRE>
|
||||
<DL>
|
||||
<DD><DL>
|
||||
</DL>
|
||||
</DD>
|
||||
</DL>
|
||||
<!-- ========= END OF CLASS DATA ========= -->
|
||||
<HR>
|
||||
|
||||
<HR>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
@@ -2,13 +2,13 @@
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 -->
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
All Classes
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-02-29">
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
@@ -22,7 +22,7 @@ All Classes
|
||||
|
||||
<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
|
||||
<TR>
|
||||
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="Book.html" title="class in <Unnamed>" target="classFrame">Book</A>
|
||||
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="DateUtil.html" title="class in <Unnamed>" target="classFrame">DateUtil</A>
|
||||
<BR>
|
||||
</FONT></TD>
|
||||
</TR>
|
||||
|
@@ -2,13 +2,13 @@
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 -->
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
All Classes
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-02-29">
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
@@ -22,7 +22,7 @@ All Classes
|
||||
|
||||
<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
|
||||
<TR>
|
||||
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="Book.html" title="class in <Unnamed>">Book</A>
|
||||
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="DateUtil.html" title="class in <Unnamed>">DateUtil</A>
|
||||
<BR>
|
||||
</FONT></TD>
|
||||
</TR>
|
||||
|
@@ -2,13 +2,13 @@
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 -->
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
Constant Field Values
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-02-29">
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc on Thu Feb 29 11:54:14 GMT 2024-->
|
||||
<!-- Generated by javadoc on Thu Mar 21 22:06:18 GMT 2024-->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
Generated Documentation (Untitled)
|
||||
@@ -23,7 +23,7 @@ Generated Documentation (Untitled)
|
||||
</HEAD>
|
||||
<FRAMESET cols="20%,80%" title="" onLoad="top.loadFrames()">
|
||||
<FRAME src="allclasses-frame.html" name="packageFrame" title="All classes and interfaces (except non-static nested types)">
|
||||
<FRAME src="Book.html" name="classFrame" title="Package, class and interface descriptions" scrolling="yes">
|
||||
<FRAME src="DateUtil.html" name="classFrame" title="Package, class and interface descriptions" scrolling="yes">
|
||||
<NOFRAMES>
|
||||
<H2>
|
||||
Frame Alert</H2>
|
||||
@@ -31,7 +31,7 @@ Frame Alert</H2>
|
||||
<P>
|
||||
This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
|
||||
<BR>
|
||||
Link to<A HREF="Book.html">Non-frame version.</A>
|
||||
Link to<A HREF="DateUtil.html">Non-frame version.</A>
|
||||
</NOFRAMES>
|
||||
</FRAMESET>
|
||||
</HTML>
|
||||
|
@@ -23,13 +23,16 @@ UTF-8
|
||||
/usr/share/bluej/bjdoclet.jar
|
||||
-doclet
|
||||
bluej.doclet.doclets.formats.html.HtmlDoclet
|
||||
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/Book.java
|
||||
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java
|
||||
<---- end of javadoc command ---->
|
||||
Loading source file /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/Book.java...
|
||||
Loading source file /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java...
|
||||
Constructing Javadoc information...
|
||||
Standard Doclet version 1.8.0_392
|
||||
Standard Doclet version 1.8.0_402
|
||||
Building tree for all the packages and classes...
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/Book.html...
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/DateUtil.html...
|
||||
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java:224: warning - @param argument "year," is not a parameter name.
|
||||
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java:238: warning - @param argument "dateString," is not a parameter name.
|
||||
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java:259: warning - @param argument "noOfDays" is not a parameter name.
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/package-frame.html...
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/package-summary.html...
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/constant-values.html...
|
||||
@@ -39,3 +42,4 @@ Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/allclasses-noframe.html...
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/index.html...
|
||||
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/stylesheet.css...
|
||||
3 warnings
|
||||
|
@@ -2,13 +2,13 @@
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 -->
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
<Unnamed>
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-02-29">
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
Classes</FONT>
|
||||
<FONT CLASS="FrameItemFont">
|
||||
<BR>
|
||||
<A HREF="Book.html" title="class in <Unnamed>" target="classFrame">Book</A></FONT></TD>
|
||||
<A HREF="DateUtil.html" title="class in <Unnamed>" target="classFrame">DateUtil</A></FONT></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
|
@@ -2,13 +2,13 @@
|
||||
<!--NewPage-->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 -->
|
||||
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
|
||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<TITLE>
|
||||
|
||||
</TITLE>
|
||||
|
||||
<META NAME="date" CONTENT="2024-02-29">
|
||||
<META NAME="date" CONTENT="2024-03-21">
|
||||
|
||||
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
|
||||
|
||||
@@ -29,8 +29,8 @@ Package <Unnamed>
|
||||
<B>Class Summary</B></FONT></TH>
|
||||
</TR>
|
||||
<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD WIDTH="15%"><B><A HREF="Book.html" title="class in <Unnamed>">Book</A></B></TD>
|
||||
<TD> </TD>
|
||||
<TD WIDTH="15%"><B><A HREF="DateUtil.html" title="class in <Unnamed>">DateUtil</A></B></TD>
|
||||
<TD>A class DateUtil with the following methods for dealing with dates.</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
|
@@ -1,4 +1 @@
|
||||
AB-906182, Smith, Sara, C, Ms
|
||||
AB-241496, Evans, David, , Dr
|
||||
AB-769390, Newton, David, E, Dr
|
||||
AB-396038, Gregson, Brian, R T, Mr
|
||||
[Library User data]
|
||||
|
@@ -165,7 +165,7 @@ target8.width=80
|
||||
target8.x=70
|
||||
target8.y=10
|
||||
target9.editor.height=1049
|
||||
target9.editor.width=960
|
||||
target9.editor.width=1920
|
||||
target9.editor.x=0
|
||||
target9.editor.y=31
|
||||
target9.height=50
|
||||
|
1
Semester 2/Programming 2/Week 10 Revision/Q1.md
Normal file
1
Semester 2/Programming 2/Week 10 Revision/Q1.md
Normal file
@@ -0,0 +1 @@
|
||||
File Input / Output
|
15
Semester 2/Programming 2/Week 10 Revision/Q3.md
Normal file
15
Semester 2/Programming 2/Week 10 Revision/Q3.md
Normal file
@@ -0,0 +1,15 @@
|
||||
Recursion via factorial function
|
||||
```java
|
||||
int fact(int n)
|
||||
{
|
||||
int result;
|
||||
if(n==0 || n==1)
|
||||
return 1;
|
||||
|
||||
result = fact(n-1) * n;
|
||||
return result;
|
||||
}
|
||||
```
|
||||
Since factorial(0) or factorial(1) is just 1, we return 1 in these scenarios
|
||||
If we have factorial(2), we would do factorial(1)\*2 = 2
|
||||
fact(5) = factorial(4) \* 5 = 5\*4\*3\*2\*1 = 120
|
35
Semester 2/Programming 2/Week 10 Revision/Q4.md
Normal file
35
Semester 2/Programming 2/Week 10 Revision/Q4.md
Normal file
@@ -0,0 +1,35 @@
|
||||
```java
|
||||
public class IntNode
|
||||
{
|
||||
public int info;
|
||||
public IntNode next;
|
||||
}
|
||||
```
|
||||

|
||||
a) Write code to add 50 to the appropriate field of the node pointed to by temp.
|
||||
|
||||
```java
|
||||
temp.info += 50;
|
||||
```
|
||||
|
||||
b) Write code to remove from the list the item after temp.
|
||||
```java
|
||||
temp.next = temp.next.next;
|
||||
```
|
||||
|
||||
c) Write the code to remove from the list temp.
|
||||
```java
|
||||
temp.info = temp.next.info; // Assign the next node's value to temp - this will overwrite temp's value.
|
||||
temp.next = temp.next.next; // Set the pointer for temp's next node to the node after the value taken for temp - this effectively clones temp.next and replaces temp.
|
||||
```
|
||||
|
||||
d) Write code to go through the list and to sum all the values within the list. You may assume the existence of head, a reference to the start of the list.
|
||||
|
||||
```java
|
||||
IntNode current = head;
|
||||
int sum = 0;
|
||||
while ( current != null ) {
|
||||
sum += current.info;
|
||||
current = current.next;
|
||||
}
|
||||
```
|
53
Semester 2/Programming 2/Week 10 Revision/Q5.md
Normal file
53
Semester 2/Programming 2/Week 10 Revision/Q5.md
Normal file
@@ -0,0 +1,53 @@
|
||||
a) List the order in which the nodes are visited in:
|
||||
post-order.
|
||||

|
||||
D,B,F,G,E,C,A
|
||||
|
||||
pre-order
|
||||
A,B,D,C,E,F,G
|
||||
|
||||
in-order
|
||||
D,B,F,E,G,C,A
|
||||
|
||||
b)
|
||||
```java
|
||||
public class BinTreeNode
|
||||
{
|
||||
public String info;
|
||||
public BinTreeNode leftChild, rightChild;
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
public void postTraverse( BinTreeNode node )
|
||||
{
|
||||
if ( node != null )
|
||||
{
|
||||
postTraverse( node.leftNode );
|
||||
postTraverse( node.rightNode );
|
||||
System.out.println( node.info );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
c) The following method counts the number of nodes in the tree
|
||||
```java
|
||||
public int countTree(BinTreeNode t)
|
||||
{
|
||||
int count;
|
||||
if (t == null)
|
||||
count = 0
|
||||
else
|
||||
count = countTree(t.leftChild)+countTree(t.rightChild)+1;
|
||||
return count;
|
||||
}
|
||||
```
|
||||

|
||||
|
||||
countTree(root)
|
||||
-> count = countTree(t.leftChild) + countTree(t.rightChild+1)
|
||||
countTree(t.leftChild)
|
||||
-> return 1, since left and right child null
|
||||
countTree(t.rightChild)
|
||||
-> return 1, since left and right child null
|
||||
count = 1 + 1 + 1 = 3
|
Reference in New Issue
Block a user