diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 2313e38..8785af3 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -7,16 +7,6 @@ "id": "74175e978d06be55", "type": "tabs", "children": [ - { - "id": "6ff62909f822ba9b", - "type": "leaf", - "state": { - "type": "pdf", - "state": { - "file": "Semester 2/Database Systems/Exercise Booklet.pdf" - } - } - }, { "id": "90e6fc52439b47f9", "type": "leaf", @@ -37,8 +27,7 @@ "state": {} } } - ], - "currentTab": 1 + ] }, { "id": "1177e1c9853f407d", @@ -53,8 +42,19 @@ "file": "Semester 2/Database Systems/Exercise Booklet.pdf" } } + }, + { + "id": "e96e468fb0a709e5", + "type": "leaf", + "state": { + "type": "pdf", + "state": { + "file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf" + } + } } - ] + ], + "currentTab": 1 } ], "direction": "vertical" @@ -121,7 +121,7 @@ "state": { "type": "backlink", "state": { - "file": "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md", + "file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -138,7 +138,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md", + "file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -161,7 +161,7 @@ "state": { "type": "outline", "state": { - "file": "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md" + "file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf" } } }, @@ -201,22 +201,25 @@ "switcher:Open quick switcher": false } }, - "active": "90e6fc52439b47f9", + "active": "e96e468fb0a709e5", "lastOpenFiles": [ + "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md", + "Semester 2/Programming 2/Project/Part 2/Book.java#", + "Semester 2/Programming 2/Project/Part 2/Periodical.java#", + "Semester 2/Programming 2/Project/Part 2/LibraryItem.java#", + "Semester 2/Programming 2/Project/Part 2/Library.java#", + "images/Pasted image 20240227171728.png", + "images/Pasted image 20240227171700.png", + "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", + "images/Pasted image 20240227171626.png", "images/Pasted image 20240227162324.png", "images/Pasted image 20240227161946.png", "images/Pasted image 20240227161426.png", "Semester 2/Database Systems/Exercise Booklet.pdf", - "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", - "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md", "images/Pasted image 20240227133544.png", "images/Pasted image 20240227133521.png", "images/Pasted image 20240227132816.png", "images/Pasted image 20240227132741.png", - "images/Pasted image 20240227132007.png", - "images/Pasted image 20240227131954.png", - "images/Pasted image 20240227131936.png", - "images/Pasted image 20240227131321.png", "Semester 2/Database Systems/Week 7", "Semester 2/Database Systems/Week 6/Week 6 Database Systems.md", "Semester 2/Computer Systems Internals & Linux/Week 6/Week 6 Computer Systems Internals.md", @@ -228,10 +231,6 @@ "Semester 2/Programming 2/Assessment 3 Revision", "Semester 2/Database Systems/Week 5/Week 5 Database Systems.md", "Semester 2/Database Systems/Week 6", - "Semester 2/Programming 2/Project/Part 2/Library.java#", - "Semester 2/Programming 2/Project/Part 2/Periodical.java#", - "Semester 2/Programming 2/Project/Part 2/data/item_data_2.txt", - "Semester 2/Programming 2/Project/Part 2/data/item_data_1_v2.txt", "Semester 2/Database Systems/Week 4/Week 4 Database Systems.md", "Semester 2/HCI/Week 2/Week 2 Human Computer Interfaces.md", "Semester 2/HCI/Week 3/Week 3 Human Computer Interfaces.md", diff --git a/Semester 2/Database Systems/Week 7/Week 7 Database Systems.md b/Semester 2/Database Systems/Week 7/Week 7 Database Systems.md index c6f99d8..1e7a55a 100644 --- a/Semester 2/Database Systems/Week 7/Week 7 Database Systems.md +++ b/Semester 2/Database Systems/Week 7/Week 7 Database Systems.md @@ -102,12 +102,149 @@ Several issues that DBMS needs to address | T1 | X | | | T2 | Z | | | T3 | | Z | + ![](Pasted%20image%2020240227161426.png) -3. ![](Pasted%20image%2020240227161946.png) +1. ![](Pasted%20image%2020240227161946.png) There is no deadlock since there are no cycles. -4. ![](Pasted%20image%2020240227162324.png) +2. ![](Pasted%20image%2020240227162324.png) There may be a deadlock, since there are multiple cycles in the WFG # Database Recovery Part 1 + +Database recovery is the process of restoring the database to a correct state after a failure + +## Types of Failures + +- Media Failures + - Hard Disk head crashes + - Loss of secondary storage +- System Crashes + - Hardware or software errors + - Results in loss of primary storage ( RAM ) +- Application software errors + - Logical errors in programs that access the database + - Causes one or more transactions to fail +- Carelessness + - Unintentional destruction of data by users or operators +- Sabotage + - Intentional corruption or destruction of data, hardware, or software facilities +- Natural disasters + - Fires, floods, solar flares, earthquakes, power failure, bit flips, etc. + +## Facilities Required for Recovery + +Log File ( Journal ) + +- Keeps track of transactions and database changes +Backups / Snapshots +- Periodic ( Incremental ) copies of database and journal +Checkpoint facility +- Used to make recovery more efficient +DBMS recovery subsystem ( Recovery Manager ) +- Allows system to restore the database to a consistent state during a failure + +Just having backups is not a solution if the facility to recover ( backup protocol ) does not exist. + +## Buffers + +The database buffers occupy an area of primary storage from which data is transferred to and from secondary storage. + +Only when buffers have been written to secondary storage can any updates be regarded permanent. + +Flushing can be triggered by: + +- Commits +- Buffer full + +## Effects of Failure + +- Loss of primary storage ( buffer loss ) +- Loss of database on secondary storage + +DBMS recovery subsystem uses techniques that minimise effects + +## Atomicity and Durability + +Recovery manager is responsible for maintaining atomicity and durability of transactions in event of failure. + +### Atomicity + +All operations of transaction are performed, or none. + +- Recovery manager ensures all effects of committed transactions reach the database, and effects of uncommitted transactions are undone or ignored. + +### Durability + +Effects of committed transactions are permanent + +- Effects must survive both loss of RAM and disk storage. + +## Recovery Management + +### System Failure + +- Transaction can commit once writes are made to database buffers. +- Updates made to buffer are not automatically written to secondary storage. +- There may be delay between committing and writing to secondary storage + - If system fails during this delay, recovery manager must ensure updates reach the copy of the database on secondary storage. +- If system failure occurs: + - Database buffers are lost + - Copy of the database on secondary storage may be incorrect. + +### Log File ( Journal ) + +To keep track of database transactions, the DBMS maintains a journal. +Two or three copies of the log file are kept on secondary storage due to the importance in the recovery process. +If the system fails, the log file is examined to see which transactions to redo / which transactions to undo or ignore. + +#### Contents of Journal + +- Transaction identifier +- Type of log record + - Start, insert, update, delete, abort, commit +- Identifier of data item affected by database action + - Insert, delete, update +- Before Image + - Value of data item before operation of log entry +- After Image + - Value of data item after operation of log entry +- Log management information +- Checkpoint records + +##### Data Entries + +`Start_transaction( T )` - Records transaction T starts execution +`Write_item( T, X, old_value, new_value )` - Records transaction T changes the value of database item X from the before image to the new image. +`Read_item( T, X )` - Records transaction T reads the value of database item X. Not always logged. +`Commit( T )` - Records transaction T has completed all accesses to the database successfully and its effect can be recorded permanently to the database. +`Checkpoint` - Used to make recovery more efficient. Covered in Part 2. + +##### Example 1 + +![](Pasted%20image%2020240227171626.png) + +##### Example 2 + +Schedule: +![](Pasted%20image%2020240227171700.png) +Log File: +![](Pasted%20image%2020240227171728.png) + +### Recovery Rules + +- Identify transactions that were committed. +- Undo / Ignore uncommitted transactions, depending on protocol. +- Redo committed transactions. + +#### Undoing Transactions + +- If transaction crash occurs, recovery manager may undo transactions. +- This is achieved by examining the transaction log and for every write entry, setting the value of item X in the database to the old value. +- Undoing a number of write item operations from one or more transactions from the log must proceed in the reverse order from the order in which the operations appear in the log. + +#### Redoing Transactions + +- For every write entry in the transaction log, the value of item X in the database is set to the new value. +- Redoing a number of write operations from one or more transactions from the log must proceed in the same order in which the operations were written in the log. diff --git a/Semester 2/Programming 2/Project/Part 2/AudioVisual.class b/Semester 2/Programming 2/Project/Part 2/AudioVisual.class new file mode 100644 index 0000000..8985717 Binary files /dev/null and b/Semester 2/Programming 2/Project/Part 2/AudioVisual.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/AudioVisual.ctxt b/Semester 2/Programming 2/Project/Part 2/AudioVisual.ctxt new file mode 100644 index 0000000..f36b616 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/AudioVisual.ctxt @@ -0,0 +1,13 @@ +#BlueJ class context +comment0.params= +comment0.target=int\ getPlayingTime() +comment0.text=\n\ Field\ Accessor\ Start\n +comment1.params=playingTime +comment1.target=void\ setPlayingTime(int) +comment1.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n +comment2.params= +comment2.target=void\ printDetails() +comment2.text=\n\ Field\ Mutator\ End\n +comment3.params=detailScanner +comment3.target=void\ readItemData(java.util.Scanner) +numComments=4 diff --git a/Semester 2/Programming 2/Project/Part 2/AudioVisual.java b/Semester 2/Programming 2/Project/Part 2/AudioVisual.java new file mode 100644 index 0000000..e327223 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/AudioVisual.java @@ -0,0 +1,52 @@ + +/** + * Write a description of class AudioVisual here. + * + * @author (your name) + * @version (a version number or a date) + */ + +import java.util.Scanner; +import java.util.ArrayList; +import java.util.NoSuchElementException; + +public abstract class AudioVisual extends LibraryItem +{ + private int playingTime; + + /* + * Field Accessor Start + */ + public int getPlayingTime() + { + return playingTime; + } + + /* + * Field Accessor End + * + * Field Mutator Start + */ + + public void setPlayingTime( int playingTime ) + { + this.playingTime = playingTime; + } + + /* + * Field Mutator End + */ + + public void printDetails() + { + System.out.println( "Playing Time: " + playingTime ); + super.printDetails(); + } + + public void readItemData( Scanner detailScanner ){ + if ( detailScanner != null ) { + this.playingTime = Integer.parseInt( detailScanner.next().trim() ); + super.readItemData( detailScanner ); + } + } +} diff --git a/Semester 2/Programming 2/Project/Part 2/Book.class b/Semester 2/Programming 2/Project/Part 2/Book.class index 746a9e0..480c60a 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/Book.class and b/Semester 2/Programming 2/Project/Part 2/Book.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/Book.java b/Semester 2/Programming 2/Project/Part 2/Book.java index 4d6cb5c..dfa1e28 100644 --- a/Semester 2/Programming 2/Project/Part 2/Book.java +++ b/Semester 2/Programming 2/Project/Part 2/Book.java @@ -1,16 +1,14 @@ /** - * Subclass of LibraryItem that emulates a Book item in a Library + * Subclass of LibraryItem that emulates a Book item. * * @George Wilkinson * @1.0 */ import java.util.Scanner; -import java.util.ArrayList; -import java.util.NoSuchElementException; -public class Book extends LibraryItem +public class Book extends PrintedItem { private String author; private String isbn; @@ -21,11 +19,9 @@ public class Book extends LibraryItem public Book(){} public void printDetails() { - System.out.println("\n==================\n( " + getItemCode() + " )" + " ISBN: " + isbn + " Book " + getTitle() + ", written by " + author + ", published by " + getPublisher() + " has " + getNoOfPages() + " pages .\nIt has been borrowed " + getTimesBorrowed() + " times."); - if( getOnLoan() ) - System.out.println( "The Book is currently on loan, and costs " + getCost() + " pence. "); - else - System.out.println( "The Book is currently not on loan, and costs " + getCost() + " pence. "); + System.out.println( "ISBN: " + isbn + + "\nAuthor: " + author ); + super.printDetails(); } public void readItemData( Scanner detailScanner ){ diff --git a/Semester 2/Programming 2/Project/Part 2/CD.class b/Semester 2/Programming 2/Project/Part 2/CD.class new file mode 100644 index 0000000..bfe43d4 Binary files /dev/null and b/Semester 2/Programming 2/Project/Part 2/CD.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/CD.ctxt b/Semester 2/Programming 2/Project/Part 2/CD.ctxt new file mode 100644 index 0000000..90b7fc7 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/CD.ctxt @@ -0,0 +1,17 @@ +#BlueJ class context +comment0.params= +comment0.target=CD() +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ CD\n +comment1.params= +comment1.target=java.lang.String\ getArtist() +comment2.params= +comment2.target=int\ noOfTracks() +comment3.params=artist +comment3.target=void\ setArtist(java.lang.String) +comment4.params=noOfTracks +comment4.target=void\ setNoOfTracks(int) +comment5.params= +comment5.target=void\ printDetails() +comment6.params=detailScanner +comment6.target=void\ readItemData(java.util.Scanner) +numComments=7 diff --git a/Semester 2/Programming 2/Project/Part 2/CD.java b/Semester 2/Programming 2/Project/Part 2/CD.java new file mode 100644 index 0000000..4ea6657 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/CD.java @@ -0,0 +1,55 @@ + +/** + * Write a description of class CD here. + * + * @author (your name) + * @version (a version number or a date) + */ + +import java.util.Scanner; + +public class CD extends AudioVisual +{ + private String artist; + private int noOfTracks; + + /** + * Constructor for objects of class CD + */ + public CD(){} + + public String getArtist() + { + return artist; + } + + public int noOfTracks() + { + return noOfTracks; + } + + public void setArtist( String artist ) + { + this.artist = artist; + } + + public void setNoOfTracks( int noOfTracks ) + { + this.noOfTracks = noOfTracks; + } + + public void printDetails() { + System.out.println( "Artist: " + artist + + "\nTrack Count: " + noOfTracks ); + super.printDetails(); + } + + public void readItemData( Scanner detailScanner ){ + if ( detailScanner != null ) { + this.artist = detailScanner.next().trim(); + this.noOfTracks = Integer.parseInt( detailScanner.next().trim() ); + super.readItemData( detailScanner ); + } + } + +} diff --git a/Semester 2/Programming 2/Project/Part 2/DVD.class b/Semester 2/Programming 2/Project/Part 2/DVD.class new file mode 100644 index 0000000..fb9a4ec Binary files /dev/null and b/Semester 2/Programming 2/Project/Part 2/DVD.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/DVD.ctxt b/Semester 2/Programming 2/Project/Part 2/DVD.ctxt new file mode 100644 index 0000000..4fe780a --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/DVD.ctxt @@ -0,0 +1,13 @@ +#BlueJ class context +comment0.params= +comment0.target=DVD() +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ DVD\n +comment1.params= +comment1.target=java.lang.String\ getDirector() +comment2.params=director +comment2.target=void\ setDirector(java.lang.String) +comment3.params= +comment3.target=void\ printDetails() +comment4.params=detailScanner +comment4.target=void\ readItemData(java.util.Scanner) +numComments=5 diff --git a/Semester 2/Programming 2/Project/Part 2/DVD.java b/Semester 2/Programming 2/Project/Part 2/DVD.java new file mode 100644 index 0000000..d6a88b4 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/DVD.java @@ -0,0 +1,40 @@ + +/** + * Write a description of class DVD here. + * + * @author (your name) + * @version (a version number or a date) + */ + +import java.util.Scanner; + +public class DVD extends AudioVisual +{ + private String director; + /** + * Constructor for objects of class DVD + */ + public DVD(){} + + public String getDirector() + { + return director; + } + + public void setDirector( String director ) + { + this.director = director; + } + + public void printDetails() { + System.out.println( "Director: " + director ); + super.printDetails(); + } + + public void readItemData( Scanner detailScanner ){ + if ( detailScanner != null ) { + this.director = detailScanner.next().trim(); + super.readItemData( detailScanner ); + } + } +} diff --git a/Semester 2/Programming 2/Project/Part 2/Library.class b/Semester 2/Programming 2/Project/Part 2/Library.class index 5d05bd8..2235d20 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/Library.class and b/Semester 2/Programming 2/Project/Part 2/Library.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/Library.ctxt b/Semester 2/Programming 2/Project/Part 2/Library.ctxt index 38a822f..7b62a00 100644 --- a/Semester 2/Programming 2/Project/Part 2/Library.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/Library.ctxt @@ -5,9 +5,19 @@ comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Library\n comment1.params=item comment1.target=void\ storeItem(LibraryItem) comment1.text=\n\ Appends\ a\ LibraryItem\ to\ the\ itemList.\n -comment2.params= -comment2.target=void\ printAllItems() -comment2.text=\n\ Prints\ to\ the\ terminal\ all\ items\ in\ the\ itemList\n -comment3.params= -comment3.target=void\ readItemData() -numComments=4 +comment2.params=user +comment2.target=void\ storeUser(LibraryUser) +comment2.text=\n\ Appends\ a\ LibraryUser\ to\ the\ userList.\n +comment3.params=prefix\ length +comment3.target=java.lang.String\ generateUserID(java.lang.String,\ int) +comment3.text=\n\ Returns\ a\ random\ unique\ user\ ID\ by\ specifying\ \n\ @prefix\ -\ arbitrary\ alphanumeric\ prefix\n\ @length\ -\ length\ of\ numeric\ ID\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 +comment4.params= +comment4.target=void\ writeUserData() +comment4.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 +comment5.params= +comment5.target=void\ printAll() +comment5.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.params= +comment6.target=void\ readData() +comment6.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=7 diff --git a/Semester 2/Programming 2/Project/Part 2/Library.java b/Semester 2/Programming 2/Project/Part 2/Library.java index 399a49d..217b766 100644 --- a/Semester 2/Programming 2/Project/Part 2/Library.java +++ b/Semester 2/Programming 2/Project/Part 2/Library.java @@ -1,22 +1,27 @@ /** - * Write a description of class Library here. + * Class to create objects of a Library, which can hold and report on assets held within * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @2.0 */ // Import all required libraries. Not using .* as it is not good practice due to potential conflicts. import java.util.ArrayList; +import java.util.HashSet; import java.util.Scanner; +import java.util.Random; import java.io.File; import java.io.IOException; import java.awt.FileDialog; import java.awt.Frame; +import java.io.PrintWriter; public class Library { - private ArrayList itemList; // Initialise an ArrayList of name itemList to store LibraryItems + private ArrayList itemList; // Initialise an ArrayList of name itemList to store Library Items + private ArrayList userList; // Initialise an ArrayList of name userList to store Library Users + private HashSet uuidSet; // Initialise a Hash Set of name uuidSet ( unique user identifier ) to store unique user IDs for efficient O(1) searching /* * Constructor for objects of class Library @@ -24,6 +29,8 @@ public class Library public Library() { itemList = new ArrayList(); + userList = new ArrayList(); + uuidSet = new HashSet(); } /* @@ -35,17 +42,110 @@ public class Library } /* - * Prints to the terminal all items in the itemList + * Appends a LibraryUser to the userList. */ - public void printAllItems() + public void storeUser( LibraryUser user ) { - for( LibraryItem item : itemList ) + userList.add( user ); + if ( user.getUserID().equals( "unknown" ) ) { - item.printDetails(); + user.setUserID( generateUserID( "AB-", 6 ) ); } } - public void readItemData() //throws IOException + /* + * Returns a random unique user ID by specifying + * @prefix - arbitrary alphanumeric prefix + * @length - length of numeric ID + * and returning a unique user id + * @uuid - a unique string starting with @prefix, and concat. with a random number + * + * Example: length = 6, expected result should be under 999,999 and above 99,999. + * If we just use 10^(length), this would generate any number under 1,000,000. + * This is an issue since any integers below 100,000 can be used, which would be incorrect. + * By using the offset of a factor of 10 below the desired length we can generate between 0 and 899,999. + * After this, we can add 100,000 back to the number to ensure a baseline length is maintained. + * + * 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 ) + { + 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 + System.out.println("Too many user IDs delegated for current range, increasing ID range by a factor of 10"); + return generateUserID( prefix, length+1 ); + /* + * This is essential for eliminating a stack overflow error when the specified range is full. This would be incorrect to catch. + * By incrementing the length value when the ID range is full, roughly 2.1 billion users can be created without running into an overflow error. + */ + } + + String uuid = prefix + ( random.nextInt( intLength ) + offset ); + /* + * Sets the uid to the prefix, concat. with a random integer of specified length + * Add the offset to a random number, to create a floor to the ID range. + */ + + if ( uuidSet.contains( uuid ) ) + { + 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. + return uuid; + } + + /* + * 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() + { + 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 ( LibraryUser user : userList ){ + user.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." ); + } + } + + /* + * 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\nStart Detail Print"); + for( LibraryItem item : itemList ) + { + System.out.println("---------------"); + item.printDetails(); + } + System.out.println("End Detail Print\n"); + } + + /* + * A method to read all data from files using a fileDialog to specify file location. + * This will create the corresponding objects depending on flags contained in the file + * and populate it's fields. + * + * Default flag value: "book", to support legacy files. This will not interfere with + * files of different flag orders. + */ + public void readData() { Frame frame = null; // Initialise a null frame FileDialog fileBox = new FileDialog( frame, "Open", FileDialog.LOAD ); // Initialise filebox with the null frame pointer @@ -53,30 +153,33 @@ public class Library try { Scanner fileScanner = new Scanner( new File( fileBox.getDirectory() + fileBox.getFile() ) ); - String typeFlag = ""; + String typeFlag = "book"; // Set a default flag to support legacy files. while( fileScanner.hasNextLine() ){ String lineItem = fileScanner.nextLine(); - //System.out.println( lineItem ); // Ensure no comments or empty lines are included if ( lineItem.contains( "//" ) || lineItem.trim().isEmpty() ){} // Check current line is a candidate flag else if ( lineItem.startsWith("[" ) ) { - if ( lineItem.toLowerCase().contains("book") ) { + + if ( lineItem.toLowerCase().contains("book") ) typeFlag = "book"; - //System.out.println( "CHANGED FLAG TO READ BOOKS" ); - } - else if ( lineItem.toLowerCase().contains("periodical") ) { + else if ( lineItem.toLowerCase().contains("periodical") ) typeFlag = "periodical"; - //System.out.println( "CHANGED FLAG TO READ PERIODICALS" ); - } + else if ( lineItem.toLowerCase().contains("cd") ) + typeFlag = "cd"; + else if ( lineItem.toLowerCase().contains("dvd") ) + typeFlag = "dvd"; + else if ( lineItem.toLowerCase().contains("user") ) + typeFlag = "user"; else { System.out.println( "Flag detected, but no accepted format...\n Cannot store item in Library. Changing Flag to generic and skipping the following: "); typeFlag = "generic"; } + } // Could be a switch case to be more efficient @@ -96,8 +199,29 @@ public class Library periodical.readItemData( detailScanner ); storeItem( periodical ); } + else if ( typeFlag.equals( "cd" ) ) { + //Process CD Data + Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); + LibraryItem cd = new CD(); + cd.readItemData( detailScanner ); + storeItem( cd ); + } + else if ( typeFlag.equals( "dvd" ) ) { + //Process DVD Data + Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); + LibraryItem dvd = new DVD(); + dvd.readItemData( detailScanner ); + storeItem( dvd ); + } + else if ( typeFlag.equals( "user" ) ) { + //Process User Data + Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); + LibraryUser user = new LibraryUser(); + user.readData( detailScanner ); + storeUser( user ); + } else if ( typeFlag.equals( "generic" ) ) { - // Output unaccepted lines + // Output unaccepted lines to terminal System.out.println( lineItem ); } } diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryItem.class b/Semester 2/Programming 2/Project/Part 2/LibraryItem.class index 30057d6..8e6a498 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/LibraryItem.class and b/Semester 2/Programming 2/Project/Part 2/LibraryItem.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryItem.ctxt b/Semester 2/Programming 2/Project/Part 2/LibraryItem.ctxt index 209ebc4..7b85381 100644 --- a/Semester 2/Programming 2/Project/Part 2/LibraryItem.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/LibraryItem.ctxt @@ -4,34 +4,26 @@ comment0.target=java.lang.String\ getTitle() comment0.text=\n\ Field\ Accessor\ Start\n comment1.params= comment1.target=java.lang.String\ getItemCode() -comment10.params=timesBorrowed -comment10.target=void\ setTimesBorrowed(int) -comment11.params=onLoan -comment11.target=void\ setOnLoan(boolean) -comment12.params=noOfPages -comment12.target=void\ setNoOfPages(int) -comment13.params=publisher -comment13.target=void\ setPublisher(java.lang.String) -comment14.params= -comment14.target=void\ printDetails() -comment14.text=\n\ Field\ Mutator\ End\n -comment15.params=detailScanner -comment15.target=void\ readItemData(java.util.Scanner) +comment10.params= +comment10.target=void\ printDetails() +comment10.text=\n\ \ \ \ public\ void\ printDetails()\n\ \ \ \ {\n\ \ \ \ \ \ \ \ System.out.println(\ title\ +\ "\ with\ an\ item\ code\ "\ +\ itemCode\ +\ "\ has\ been\ borrowed\ "\ +\ timesBorrowed\ +\ "\ times.");\n\ \ \ \ \ \ \ \ if(\ onLoan\ )\n\ \ \ \ \ \ \ \ \ \ \ \ System.out.println(\ "This\ item\ is\ at\ present\ on\ loan\ and\ when\ new\ cost\ "\ +\ cost\ +\ "\ pence.\\n"\ );\n\ \ \ \ \ \ \ \ else\ \n\ \ \ \ \ \ \ \ \ \ \ \ System.out.println(\ "This\ item\ is\ at\ present\ not\ on\ loan\ and\ when\ new\ cost\ "\ +\ cost\ +\ "\ pence.\\n"\ );\n\ \ \ \ }\n +comment11.params=detailScanner +comment11.target=void\ readItemData(java.util.Scanner) comment2.params= comment2.target=int\ getCost() comment3.params= comment3.target=int\ getTimesBorrowed() comment4.params= comment4.target=boolean\ getOnLoan() -comment5.params= -comment5.target=int\ getNoOfPages() -comment6.params= -comment6.target=java.lang.String\ getPublisher() -comment7.params=title -comment7.target=void\ setTitle(java.lang.String) -comment7.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n -comment8.params=itemCode -comment8.target=void\ setItemCode(java.lang.String) -comment9.params=cost -comment9.target=void\ setCost(int) -numComments=16 +comment5.params=title +comment5.target=void\ setTitle(java.lang.String) +comment5.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n +comment6.params=itemCode +comment6.target=void\ setItemCode(java.lang.String) +comment7.params=cost +comment7.target=void\ setCost(int) +comment8.params=timesBorrowed +comment8.target=void\ setTimesBorrowed(int) +comment9.params=onLoan +comment9.target=void\ setOnLoan(boolean) +numComments=12 diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryItem.java b/Semester 2/Programming 2/Project/Part 2/LibraryItem.java index d691572..c5d0ebe 100644 --- a/Semester 2/Programming 2/Project/Part 2/LibraryItem.java +++ b/Semester 2/Programming 2/Project/Part 2/LibraryItem.java @@ -1,9 +1,9 @@ /** - * Emulates an Item in a Library ( + * Superclass of items / assets stored in a Library. * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @2.1 */ import java.util.Scanner; @@ -18,8 +18,6 @@ public abstract class LibraryItem private int cost; private int timesBorrowed; private boolean onLoan; - private int noOfPages; - private String publisher; /* * Field Accessor Start @@ -48,17 +46,7 @@ public abstract class LibraryItem { return onLoan; } - - public int getNoOfPages() - { - return noOfPages; - } - - public String getPublisher() - { - return publisher; - } - + /* * Field Accessor End * @@ -90,21 +78,13 @@ public abstract class LibraryItem this.onLoan = onLoan; } - public void setNoOfPages( int noOfPages ) - { - this.noOfPages = noOfPages; - } - - public void setPublisher( String publisher ) - { - this.publisher = publisher; - } - /* * Field Mutator End */ // Output to console the details of the fields in a human-readable format. + + /* public void printDetails() { System.out.println( title + " with an item code " + itemCode + " has been borrowed " + timesBorrowed + " times."); @@ -113,12 +93,23 @@ public abstract class LibraryItem else System.out.println( "This item is at present not on loan and when new cost " + cost + " pence.\n" ); } + */ - public void readItemData( Scanner detailScanner ) { + public void printDetails() + { + System.out.println("Item Code: " + itemCode + + "\nTitle: " + title + + "\nCost: £" + ( ( float )( cost ) )/100 + + "\nBorrowed " + getTimesBorrowed() + " times." ); + if( getOnLoan() ) + System.out.println( "On Loan"); + else + System.out.println( "Available to Loan"); + } + + public void readItemData( Scanner detailScanner ) { if ( detailScanner != null ) { - this.noOfPages = Integer.parseInt( detailScanner.next().trim() ); - this.publisher = detailScanner.next().trim(); this.title = detailScanner.next().trim(); this.itemCode = detailScanner.next().trim(); this.cost = Integer.parseInt( detailScanner.next().trim() ); diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryUser.class b/Semester 2/Programming 2/Project/Part 2/LibraryUser.class new file mode 100644 index 0000000..a8c37a1 Binary files /dev/null and b/Semester 2/Programming 2/Project/Part 2/LibraryUser.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryUser.ctxt b/Semester 2/Programming 2/Project/Part 2/LibraryUser.ctxt new file mode 100644 index 0000000..8c4c505 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/LibraryUser.ctxt @@ -0,0 +1,31 @@ +#BlueJ class context +comment0.params= +comment0.target=LibraryUser() +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser\n +comment1.params= +comment1.target=java.lang.String\ getUserID() +comment10.params=title +comment10.target=void\ setTitle(java.lang.String) +comment11.params=writer +comment11.target=void\ writeData(java.io.PrintWriter) +comment12.params= +comment12.target=void\ printDetails() +comment13.params=detailScanner +comment13.target=void\ readData(java.util.Scanner) +comment2.params= +comment2.target=java.lang.String\ getSurname() +comment3.params= +comment3.target=java.lang.String\ getFirstName() +comment4.params= +comment4.target=java.lang.String\ getOtherInitials() +comment5.params= +comment5.target=java.lang.String\ getTitle() +comment6.params=userID +comment6.target=void\ setUserID(java.lang.String) +comment7.params=surname +comment7.target=void\ setSurname(java.lang.String) +comment8.params=firstName +comment8.target=void\ setFirstName(java.lang.String) +comment9.params=otherInitials +comment9.target=void\ setOtherInitials(java.lang.String) +numComments=14 diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryUser.java b/Semester 2/Programming 2/Project/Part 2/LibraryUser.java new file mode 100644 index 0000000..d3a85c9 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/LibraryUser.java @@ -0,0 +1,87 @@ + +/** + * Write a description of class LibraryUser here. + * + * @author (your name) + * @version (a version number or a date) + */ + +import java.util.Scanner; +import java.io.PrintWriter; + +public class LibraryUser +{ + // instance variables - replace the example below with your own + private String userID, surname, firstName, otherInitials, title; + + /** + * Constructor for objects of class LibraryUser + */ + public LibraryUser(){} + + public String getUserID(){ + return userID; + } + + public String getSurname(){ + return surname; + } + + public String getFirstName(){ + return firstName; + } + + public String getOtherInitials(){ + return otherInitials; + } + + public String getTitle(){ + return title; + } + + + + public void setUserID( String userID ){ + this.userID = userID; + } + + public void setSurname( String surname ){ + this.surname = surname; + } + + public void setFirstName( String firstName ){ + this.firstName = firstName; + } + + public void setOtherInitials( String otherInitials ){ + this.otherInitials = otherInitials; + } + + public void setTitle( String title ){ + this.title = title; + } + + public void writeData( PrintWriter writer ) + { + writer.print(userID + ", " + surname + ", " + firstName + ", " + otherInitials + ", " + title + "\n"); + writer.flush(); + } + + public void printDetails() + { + System.out.println( "ID: " + userID + + "\nName: " + title + " " + firstName + " " + otherInitials + " " + surname ); + } + + public void readData( Scanner detailScanner ) + { + if ( detailScanner != null ) { + this.userID = detailScanner.next().trim(); + this.surname = detailScanner.next().trim(); + this.firstName = detailScanner.next().trim(); + this.otherInitials = detailScanner.next().trim(); + this.title = detailScanner.next().trim(); + } + } + +} diff --git a/Semester 2/Programming 2/Project/Part 2/Periodical.class b/Semester 2/Programming 2/Project/Part 2/Periodical.class index 3721c5c..f5375b3 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/Periodical.class and b/Semester 2/Programming 2/Project/Part 2/Periodical.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/Periodical.java b/Semester 2/Programming 2/Project/Part 2/Periodical.java index 2d60d25..1d3275b 100644 --- a/Semester 2/Programming 2/Project/Part 2/Periodical.java +++ b/Semester 2/Programming 2/Project/Part 2/Periodical.java @@ -1,24 +1,22 @@ /** - * Write a description of class Periodical here. + * Subclass of LibraryItem to create a periodical ( e.g. newspaper, tabloid ). * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @1.0 */ import java.util.Scanner; -public class Periodical extends LibraryItem + +public class Periodical extends PrintedItem { private String publicationDate; public Periodical(){} public void printDetails() { - System.out.println("\n==================\n( " + getItemCode() + " )" + " Publication Date: " + publicationDate + " Periodical " + getTitle() + ", published by " + getPublisher() + " has " + getNoOfPages() + " pages .\nIt has been borrowed " + getTimesBorrowed() + " times."); - if( getOnLoan() ) - System.out.println( "The Periodical is currently on loan, and costs " + getCost() + " pence. "); - else - System.out.println( "The Periodical is currently not on loan, and costs " + getCost() + " pence. "); + System.out.println( "Publication Date: " + publicationDate ); + super.printDetails(); } public void readItemData( Scanner detailScanner ){ diff --git a/Semester 2/Programming 2/Project/Part 2/PrintedItem.class b/Semester 2/Programming 2/Project/Part 2/PrintedItem.class new file mode 100644 index 0000000..a657470 Binary files /dev/null and b/Semester 2/Programming 2/Project/Part 2/PrintedItem.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/PrintedItem.ctxt b/Semester 2/Programming 2/Project/Part 2/PrintedItem.ctxt new file mode 100644 index 0000000..7c972b9 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/PrintedItem.ctxt @@ -0,0 +1,17 @@ +#BlueJ class context +comment0.params= +comment0.target=int\ getNoOfPages() +comment0.text=\n\ Field\ Accessor\ Start\n +comment1.params= +comment1.target=java.lang.String\ getPublisher() +comment2.params=noOfPages +comment2.target=void\ setNoOfPages(int) +comment2.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n +comment3.params=publisher +comment3.target=void\ setPublisher(java.lang.String) +comment4.params= +comment4.target=void\ printDetails() +comment4.text=\n\ Field\ Mutator\ End\n +comment5.params=detailScanner +comment5.target=void\ readItemData(java.util.Scanner) +numComments=6 diff --git a/Semester 2/Programming 2/Project/Part 2/PrintedItem.java b/Semester 2/Programming 2/Project/Part 2/PrintedItem.java new file mode 100644 index 0000000..bfd7f5e --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/PrintedItem.java @@ -0,0 +1,64 @@ + +/** + * Write a description of class PrintedItem here. + * + * @author (your name) + * @version (a version number or a date) + */ + +import java.util.Scanner; +import java.util.ArrayList; +import java.util.NoSuchElementException; + +public abstract class PrintedItem extends LibraryItem +{ + private int noOfPages; + private String publisher; + + /* + * Field Accessor Start + */ + public int getNoOfPages() + { + return noOfPages; + } + + public String getPublisher() + { + return publisher; + } + + /* + * Field Accessor End + * + * Field Mutator Start + */ + + public void setNoOfPages( int noOfPages ) + { + this.noOfPages = noOfPages; + } + + public void setPublisher( String publisher ) + { + this.publisher = publisher; + } + + /* + * Field Mutator End + */ + public void printDetails() + { + System.out.println("Page Count: " + noOfPages + + "\nPublisher: " + publisher); + super.printDetails(); + } + + public void readItemData( Scanner detailScanner ){ + if ( detailScanner != null ) { + this.noOfPages = Integer.parseInt( detailScanner.next().trim() ); + this.publisher = detailScanner.next().trim(); + super.readItemData( detailScanner ); + } + } +} diff --git a/Semester 2/Programming 2/Project/Part 2/data/items_all.txt b/Semester 2/Programming 2/Project/Part 2/data/items_all.txt new file mode 100644 index 0000000..dc071cd --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/data/items_all.txt @@ -0,0 +1,43 @@ +// this is a comment, any lines that start with // +// (and blank lines) should be ignored + +[Book data] +// data is author, isbn, noOfPages, publisher, title, itemCode, cost, timesBorrowed, onLoan +Barnes and Kolling, 9780131976290,480, Pearson, Objects First with Java, LM002411,3989,781,true +Aho Sethi and Ullman, 9780201101942,795, Addison-Wesley, Compilers: Principles Techniques and Tools, LM002711,599,500,FALSE +Harvey Paul and Jeffrey, 9780130622211,1568, Prentice Hall, C# How to Program, LM002876,4599,45,TRUE +Muster, 9780072193145,1011, McGraw-Hill, Unix Made Easy: The Basics and Beyond (Made Easy), LM002468,6395,678,TRUE +Thomee, 9783540331216,370, Springer Verlag, Galerkin Finite Element Methods for Parabolic Problems, LM002153,4554,543,FALSE + +[periodical data] +// data is publicationDate, noOfPages, publisher, title, itemCode, cost, timesBorrowed, onLoan +25-03-20,70, News International, The Times, LM005447,80,250000,FALSE +26-03-20,70, News International, The Times, LM005002,80,560562,false +26-04-20, 70, Associated Newspapers, Daily Mail, LM005177,75,478908,false + +[CD data] + +// data is artist, noOfTracks, playingTime, title, itemCode, cost, timesBorrowed, onLoan + +James Blunt,15,68, Back to Bedlam, LM003604,498,234,true +Duffy,10,73, Rockferry, LM003553,898,90,false +Adele,12,19,75, LM003580,798,87,FALSE +Robert Plant and Alison Krauss,13,72, Raising Sand, LM003750,898,89,tRUE +Goldfrapp,10,72, Seventh Tree, LM003873,1299,9876,true +Amy Winehouse,11,70, Back To Black, LM003698,698,8765,false +Jack Johnson,15,67, Sleep Through The Static, LM003773,898,54,True + Mark Ronson,14,74, Version, LM003365,698,56,true +Radiohead,10,75, In Rainbows , LM003771,798,6543,FALSE +Nick Cave,11,68, Dig!!! Lazarus Dig!!!, LM003751,1199,90,False +Nickelback,11,72, All the Right Reasons, LM003915,598,32,true + +[DVD data] + +// data is director, playingTime, title, itemCode, cost, timesBorrowed, onLoan +Chris Miller,92, Shrek The Third, LM004314,1026,900,TRUE +Robert Zemeckis,114, Beowulf , LM004079,900,87,FALSE +Phyllida Lloyd,118, Mamma Mia, LM004984,798,566,true +Joe Wright,130, Atonement, LM004720,1293,66,true +Andrew Adamson,125, The Chronicles of Narnia: Prince Caspian, LM004178,345,45,FALSE + + diff --git a/Semester 2/Programming 2/Project/Part 2/data/items_and_user_data.txt b/Semester 2/Programming 2/Project/Part 2/data/items_and_user_data.txt new file mode 100644 index 0000000..63bc034 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/data/items_and_user_data.txt @@ -0,0 +1,48 @@ +// this is a comment, any lines that start with // +// (and blank lines) should be ignored + +[Book data] +// data is author, isbn, noOfPages, publisher, title, itemCode, cost, timesBorrowed, onLoan +Barnes and Kolling, 9780131976290,480, Pearson, Objects First with Java, LM002411,3989,781,true +Aho Sethi and Ullman, 9780201101942,795, Addison-Wesley, Compilers: Principles Techniques and Tools, LM002711,599,890,FALSE +Harvey Paul and Jeffrey, 9780130622211,1568, Prentice Hall, C# How to Program, LM002876,4599,45,TRUE +Muster, 9780072193145,1011, McGraw-Hill, Unix Made Easy: The Basics and Beyond (Made Easy), LM002468,6395,8765,TRUE +Thomee, 9783540331216,370, Springer Verlag, Galerkin Finite Element Methods for Parabolic Problems, LM002153,4554,780,FALSE + +[CD data] + +// data is artist, noOfTracks, playingTime, title, itemCode, cost, timesBorrowed, onLoan + +James Blunt,15,68, Back to Bedlam, LM003604,498,234,true +Duffy,10,73, Rockferry, LM003553,898,90,false +Adele,12,19,75, LM003580,798,87,FALSE +Robert Plant and Alison Krauss,13,72, Raising Sand, LM003750,898,89,tRUE +Goldfrapp,10,72, Seventh Tree, LM003873,1299,9876,true +Amy Winehouse,11,70, Back To Black, LM003698,698,8765,false +Jack Johnson,15,67, Sleep Through The Static, LM003773,898,54,True + Mark Ronson,14,74, Version, LM003365,698,56,true +Radiohead,10,75, In Rainbows , LM003771,798,6543,FALSE +Nick Cave,11,68, Dig!!! Lazarus Dig!!!, LM003751,1199,90,False +Nickelback,11,72, All the Right Reasons, LM003915,598,32,true + +[DVD data] + +// data is director, playingTime, title, itemCode, cost, timesBorrowed, onLoan +Chris Miller,92, Shrek The Third, LM004314,1026,900,TRUE +Robert Zemeckis,114, Beowulf , LM004079,900,87,FALSE +Phyllida Lloyd,118, Mamma Mia, LM004984,798,566,true +Joe Wright,130, Atonement, LM004720,1293,66,true +Andrew Adamson,125, The Chronicles of Narnia: Prince Caspian, LM004178,345,45,FALSE + +[periodical data] +// data is publicationDate, noOfPages, publisher, title, itemCode, cost, timesBorrowed, onLoan +25-03-08,70, News International, The Times, LM005447,80,0,FALSE +26-03-08,70, News International, The Times, LM005002,80,0,false +26-03-08,60, Associated Newspapers, Daily Mail, LM005177,40,0,false + +[Library User Data] +// data is userID, surname, firstName, otherInitials, title +unknown, Newton, David, E, Dr +unknown, Gregson, Brian, R T, Mr +unknown, Evans, David, , Dr +unknown, Smith, Sara, C, Ms diff --git a/Semester 2/Programming 2/Project/Part 2/data/library_user_data.txt b/Semester 2/Programming 2/Project/Part 2/data/library_user_data.txt new file mode 100644 index 0000000..053eca2 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/data/library_user_data.txt @@ -0,0 +1,12 @@ +// this is a comment, any lines that start with // +// (and blank lines) should be ignored + +// New user data +// data is userID, surname, firstName, otherInitials, title + +[Library User Data] + +unknown, Newton, David, E, Dr +unknown, Gregson, Brian, R T, Mr +unknown, Evans, David, , Dr +unknown, Smith, Sara, C, Ms diff --git a/Semester 2/Programming 2/Project/Part 2/data/testuserwrite.txt b/Semester 2/Programming 2/Project/Part 2/data/testuserwrite.txt new file mode 100644 index 0000000..2df8bad --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/data/testuserwrite.txt @@ -0,0 +1,4 @@ +unknown, Newton, David, E, Dr +unknown, Gregson, Brian, R T, Mr +unknown, Evans, David, , Dr +unknown, Smith, Sara, C, Ms diff --git a/Semester 2/Programming 2/Project/Part 2/doc/Book.html b/Semester 2/Programming 2/Project/Part 2/doc/Book.html new file mode 100644 index 0000000..92f0264 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 2/doc/Book.html @@ -0,0 +1,183 @@ + + + + + + + +Book + + + + + + + + + + + + +
+ +
+ +

+Class Book

+
+java.lang.Object
+  extended by LibraryItem
+      extended by PrintedItem
+          extended by Book
+
+
+
+
public class Book
extends PrintedItem
+ + +

+


+ +

+ + + + + + + + + + + +
+Constructor Summary
Book() + +
+          Constructor for objects of class Book
+  + + + + + + + + + + + + + + + +
+Method Summary
+ voidprintDetails() + +
+           
+ voidreadItemData(java.util.Scanner detailScanner) + +
+           
+ + + + + + + +
Methods inherited from class PrintedItem
getNoOfPages, getPublisher, setNoOfPages, setPublisher
+ + + + + + + +
Methods inherited from class LibraryItem
getCost, getItemCode, getOnLoan, getTimesBorrowed, getTitle, setCost, setItemCode, setOnLoan, setTimesBorrowed, setTitle
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+Book

+
+public Book()
+
+
Constructor for objects of class Book +

+

+ + + + + + + + +
+Method Detail
+ +

+printDetails

+
+public void printDetails()
+
+
+
Overrides:
printDetails in class LibraryItem
+
+
+
+
+
+
+ +

+readItemData

+
+public void readItemData(java.util.Scanner detailScanner)
+
+
+
Overrides:
readItemData in class PrintedItem
+
+
+
+
+
+ +
+ +
+ + + diff --git a/Semester 2/Programming 2/Project/Part 2/doc/allclasses-frame.html b/Semester 2/Programming 2/Project/Part 2/doc/allclasses-frame.html index 41e572a..7555051 100644 --- a/Semester 2/Programming 2/Project/Part 2/doc/allclasses-frame.html +++ b/Semester 2/Programming 2/Project/Part 2/doc/allclasses-frame.html @@ -2,13 +2,13 @@ - + All Classes - + @@ -22,7 +22,7 @@ All Classes - diff --git a/Semester 2/Programming 2/Project/Part 2/doc/allclasses-noframe.html b/Semester 2/Programming 2/Project/Part 2/doc/allclasses-noframe.html index 74c616b..0ed21b1 100644 --- a/Semester 2/Programming 2/Project/Part 2/doc/allclasses-noframe.html +++ b/Semester 2/Programming 2/Project/Part 2/doc/allclasses-noframe.html @@ -2,13 +2,13 @@ - + All Classes - + @@ -22,7 +22,7 @@ All Classes
LibraryItem +Book
- diff --git a/Semester 2/Programming 2/Project/Part 2/doc/constant-values.html b/Semester 2/Programming 2/Project/Part 2/doc/constant-values.html index dc341e1..82e3e81 100644 --- a/Semester 2/Programming 2/Project/Part 2/doc/constant-values.html +++ b/Semester 2/Programming 2/Project/Part 2/doc/constant-values.html @@ -2,13 +2,13 @@ - + Constant Field Values - + diff --git a/Semester 2/Programming 2/Project/Part 2/doc/index.html b/Semester 2/Programming 2/Project/Part 2/doc/index.html index 6d18791..b4acacd 100644 --- a/Semester 2/Programming 2/Project/Part 2/doc/index.html +++ b/Semester 2/Programming 2/Project/Part 2/doc/index.html @@ -2,7 +2,7 @@ - + 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="LibraryItem.html" name="classFrame" title="Package, class and interface descriptions" scrolling="yes"> +<FRAME src="Book.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="LibraryItem.html">Non-frame version.</A> +Link to<A HREF="Book.html">Non-frame version.</A> </NOFRAMES> </FRAMESET> </HTML> diff --git a/Semester 2/Programming 2/Project/Part 2/doc/logfile.txt b/Semester 2/Programming 2/Project/Part 2/doc/logfile.txt index 27bedb5..a92397d 100644 --- a/Semester 2/Programming 2/Project/Part 2/doc/logfile.txt +++ b/Semester 2/Programming 2/Project/Part 2/doc/logfile.txt @@ -23,13 +23,13 @@ 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/LibraryItem.java +/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/Book.java <---- end of javadoc command ----> -Loading source file /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/LibraryItem.java... +Loading source file /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/Book.java... Constructing Javadoc information... Standard Doclet version 1.8.0_392 Building tree for all the packages and classes... -Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/LibraryItem.html... +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/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... diff --git a/Semester 2/Programming 2/Project/Part 2/doc/package-frame.html b/Semester 2/Programming 2/Project/Part 2/doc/package-frame.html index 3c2f0bc..c832d17 100644 --- a/Semester 2/Programming 2/Project/Part 2/doc/package-frame.html +++ b/Semester 2/Programming 2/Project/Part 2/doc/package-frame.html @@ -2,13 +2,13 @@ <!--NewPage--> <HTML> <HEAD> -<!-- Generated by javadoc (build 1.8.0_392) on Fri Feb 16 14:05:04 GMT 2024 --> +<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 --> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE> <Unnamed> - + @@ -24,7 +24,7 @@ Classes 
-LibraryItem
+Book
LibraryItem +Book
diff --git a/Semester 2/Programming 2/Project/Part 2/doc/package-summary.html b/Semester 2/Programming 2/Project/Part 2/doc/package-summary.html index c16fe6f..fa693de 100644 --- a/Semester 2/Programming 2/Project/Part 2/doc/package-summary.html +++ b/Semester 2/Programming 2/Project/Part 2/doc/package-summary.html @@ -2,13 +2,13 @@ - + - + @@ -29,7 +29,7 @@ Package <Unnamed> Class Summary -LibraryItem +Book   diff --git a/Semester 2/Programming 2/Project/Part 2/nullnull b/Semester 2/Programming 2/Project/Part 2/nullnull new file mode 100644 index 0000000..e69de29 diff --git a/Semester 2/Programming 2/Project/Part 2/package.bluej b/Semester 2/Programming 2/Project/Part 2/package.bluej index 45b1bd0..8c8286c 100644 --- a/Semester 2/Programming 2/Project/Part 2/package.bluej +++ b/Semester 2/Programming 2/Project/Part 2/package.bluej @@ -8,66 +8,140 @@ dependency2.type=UsesDependency dependency3.from=Library dependency3.to=LibraryItem dependency3.type=UsesDependency +dependency4.from=Library +dependency4.to=CD +dependency4.type=UsesDependency +dependency5.from=Library +dependency5.to=DVD +dependency5.type=UsesDependency +dependency6.from=Library +dependency6.to=LibraryUser +dependency6.type=UsesDependency objectbench.height=76 -objectbench.width=1900 +objectbench.width=940 package.editor.height=874 -package.editor.width=1774 +package.editor.width=814 package.editor.x=0 package.editor.y=31 -package.numDependencies=3 -package.numTargets=4 +package.numDependencies=6 +package.numTargets=9 package.showExtends=true package.showUses=true project.charset=UTF-8 target1.editor.height=700 target1.editor.width=900 -target1.editor.x=40 -target1.editor.y=52 -target1.height=60 -target1.name=LibraryItem +target1.editor.x=1017 +target1.editor.y=76 +target1.height=50 +target1.name=PrintedItem target1.naviview.expanded=true target1.showInterface=false target1.type=AbstractTarget target1.typeParameters= -target1.width=120 -target1.x=160 -target1.y=80 -target2.editor.height=700 -target2.editor.width=1619 -target2.editor.x=60 -target2.editor.y=71 +target1.width=110 +target1.x=350 +target1.y=220 +target2.editor.height=786 +target2.editor.width=960 +target2.editor.x=34 +target2.editor.y=174 target2.height=50 -target2.name=Periodical +target2.name=CD target2.naviview.expanded=true target2.showInterface=false target2.type=ClassTarget target2.typeParameters= -target2.width=90 -target2.x=30 -target2.y=260 +target2.width=80 +target2.x=580 +target2.y=320 target3.editor.height=700 -target3.editor.width=1734 -target3.editor.x=60 -target3.editor.y=71 -target3.height=50 -target3.name=Book +target3.editor.width=900 +target3.editor.x=557 +target3.editor.y=177 +target3.height=60 +target3.name=LibraryItem target3.naviview.expanded=true target3.showInterface=false -target3.type=ClassTarget +target3.type=AbstractTarget target3.typeParameters= -target3.width=80 -target3.x=330 -target3.y=260 +target3.width=120 +target3.x=470 +target3.y=90 target4.editor.height=1049 target4.editor.width=1920 target4.editor.x=0 target4.editor.y=31 target4.height=50 -target4.name=Library +target4.name=DVD target4.naviview.expanded=true target4.showInterface=false target4.type=ClassTarget target4.typeParameters= -target4.width=100 -target4.x=170 -target4.y=210 +target4.width=80 +target4.x=690 +target4.y=360 +target5.editor.height=700 +target5.editor.width=1619 +target5.editor.x=192 +target5.editor.y=267 +target5.height=50 +target5.name=Periodical +target5.naviview.expanded=true +target5.showInterface=false +target5.type=ClassTarget +target5.typeParameters= +target5.width=90 +target5.x=280 +target5.y=360 +target6.editor.height=700 +target6.editor.width=900 +target6.editor.x=55 +target6.editor.y=274 +target6.height=50 +target6.name=LibraryUser +target6.naviview.expanded=true +target6.showInterface=false +target6.type=ClassTarget +target6.typeParameters= +target6.width=110 +target6.x=320 +target6.y=150 +target7.editor.height=1049 +target7.editor.width=1920 +target7.editor.x=0 +target7.editor.y=31 +target7.height=50 +target7.name=Book +target7.naviview.expanded=true +target7.showInterface=false +target7.type=ClassTarget +target7.typeParameters= +target7.width=80 +target7.x=400 +target7.y=320 +target8.editor.height=1049 +target8.editor.width=1920 +target8.editor.x=0 +target8.editor.y=31 +target8.height=50 +target8.name=Library +target8.naviview.expanded=true +target8.showInterface=false +target8.type=ClassTarget +target8.typeParameters= +target8.width=100 +target8.x=480 +target8.y=220 +target9.editor.height=700 +target9.editor.width=900 +target9.editor.x=960 +target9.editor.y=146 +target9.height=50 +target9.name=AudioVisual +target9.naviview.expanded=true +target9.showInterface=false +target9.type=AbstractTarget +target9.typeParameters= +target9.width=110 +target9.x=600 +target9.y=220 diff --git a/images/Pasted image 20240227171626.png b/images/Pasted image 20240227171626.png new file mode 100644 index 0000000..4ba98f5 Binary files /dev/null and b/images/Pasted image 20240227171626.png differ diff --git a/images/Pasted image 20240227171700.png b/images/Pasted image 20240227171700.png new file mode 100644 index 0000000..a4f7332 Binary files /dev/null and b/images/Pasted image 20240227171700.png differ diff --git a/images/Pasted image 20240227171728.png b/images/Pasted image 20240227171728.png new file mode 100644 index 0000000..9652227 Binary files /dev/null and b/images/Pasted image 20240227171728.png differ