diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 8785af3..a7108f4 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -8,12 +8,12 @@ "type": "tabs", "children": [ { - "id": "90e6fc52439b47f9", + "id": "e96e468fb0a709e5", "type": "leaf", "state": { "type": "markdown", "state": { - "file": "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md", + "file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md", "mode": "source", "source": false } @@ -30,21 +30,11 @@ ] }, { - "id": "1177e1c9853f407d", + "id": "97b758ffb617daa3", "type": "tabs", "children": [ { - "id": "53317c245e573f8c", - "type": "leaf", - "state": { - "type": "pdf", - "state": { - "file": "Semester 2/Database Systems/Exercise Booklet.pdf" - } - } - }, - { - "id": "e96e468fb0a709e5", + "id": "fdb9dea18c7f9c15", "type": "leaf", "state": { "type": "pdf", @@ -53,8 +43,7 @@ } } } - ], - "currentTab": 1 + ] } ], "direction": "vertical" @@ -121,7 +110,7 @@ "state": { "type": "backlink", "state": { - "file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", + "file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -138,7 +127,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", + "file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -161,7 +150,7 @@ "state": { "type": "outline", "state": { - "file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf" + "file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md" } } }, @@ -203,34 +192,36 @@ }, "active": "e96e468fb0a709e5", "lastOpenFiles": [ - "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md", + "images/Pasted image 20240305135229.png", + "images/Pasted image 20240305135043.png", + "images/Pasted image 20240305134944.png", + "images/Pasted image 20240305134930.png", + "images/Pasted image 20240305134835.png", + "images/Pasted image 20240305134734.png", + "images/Pasted image 20240305134506.png", + "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", + "Semester 2/Database Systems/Week 8/Week 8 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/LibraryUser.java#", + "Semester 2/Programming 2/Project/Part 2/CD.java#", + "Semester 2/Programming 2/Project/Part 2/DVD.java#", + "Semester 2/Programming 2/Project/Part 2/AudioVisual.java#", + "Semester 2/Programming 2/Project/Part 2/PrintedItem.java#", "Semester 2/Programming 2/Project/Part 2/Library.java#", + "images/Pasted image 20240305131110.png", + "images/Pasted image 20240305130824.png", + "Semester 2/Database Systems/Week 7/Week 7 Database Systems.md", "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", - "images/Pasted image 20240227133544.png", - "images/Pasted image 20240227133521.png", - "images/Pasted image 20240227132816.png", - "images/Pasted image 20240227132741.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", "Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS3.md", - "Semester 2/Computer Systems Internals & Linux/Week 6", "Semester 2/Computer Systems Internals & Linux/Untitled.md", "Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS2.md", "Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS1.md", - "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/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", @@ -247,7 +238,6 @@ "Semester 2/Database Systems/Week 3/Week 3 Database Systems.md", "Semester 2/Database Systems/Week 2/Week 2 Database Systems.md", "CCNA/1 - Networking Today/1.2 - Network Components.md", - "CCNA/1 - Networking Today/1.1 - Networks Affect our Lives.md", "Database Systems/Untitled.canvas", "Untitled 1.canvas", "Untitled.canvas" diff --git a/Semester 2/Database Systems/Week 8/Week 8 Database Systems.md b/Semester 2/Database Systems/Week 8/Week 8 Database Systems.md new file mode 100644 index 0000000..9624bf6 --- /dev/null +++ b/Semester 2/Database Systems/Week 8/Week 8 Database Systems.md @@ -0,0 +1,90 @@ +# [Undoing & Redoing Transactions](Semester%202/Database%20Systems/Week%207/Week%207%20Database%20Systems.md####Undoing%20Transactions) + +# Deferred Update Protocol + +Updates not written until after transaction has reached commit point. +If transaction fails before committing, no modification is made to database, hence no undoing is required. +May be necessary to redo updates of committed transactions as effect may not have reached database. + +## Procedure + +Redo transaction is both \ and \ are present in the log + +### Example + +![](Pasted%20image%2020240305130824.png) +Failure in different places: +![](Pasted%20image%2020240305131110.png) +In case(a), no commit is present, so no redo or undo is required. +case(b), T0 commits, but T1 does not, hence T0 is redone. +case(b), T0 and T1 commits, so both are redone. + +# Immediate Update Protocol + +Updates applied as they occur. +Following a failure, redo updates of committed transactions. +Undo effects of transactions uncommitted. +If no commit record, transacation was active and must be undone. +Undo operations performed in reverse order in log. +In recovery, use log to undo or redo. + +## Protocol + +Undo + +- If is in the log but is not then restore the value of all data items updated by Ti to their old values, going backwards from the last log record for Ti. +Redo +- If and are both in the log then set the value of all data items updated by Ti to the new values, going forward from the first log record for Ti + +### Example + +![](Pasted%20image%2020240305134506.png) + +# Checkpoints + +After failure, may not know how far back to search log. +Checkpoints limit log searching, made automatically by DBMS +Creation of checkpoints schedules at predetermined intervals. +Definition: Checkpoints are points of sync between database and log file. All buffers are written to secondary storage. + +## Procedure + +1. Write to secondary storage + - All log records + - All modified buffer blocks to database. + - Checkpoint record to log file which contains identities of transactions active at time of checkpoint +2. Resume processing. + +![](Pasted%20image%2020240305134734.png) + +### Example 1 ( Immediate ) + +- Starts at t0, fails at tf. +- T1 and T6 have to be undone +- In absence of other info, recovery manager has to redo T2, 3, 4, and 5. +- ![](Pasted%20image%2020240305134835.png) +### Example 2 ( serial with checkpoint, Immediate ) + +- Dotted lines = checkpoints +- T1 is safe since updates are written to disk +- T4 needs to be undone +- T2 and 3 need to be redone +- ![](Pasted%20image%2020240305134944.png) +### Example 3 ( concurrent with checkpoint, Immediate ) + +- T2 and 3 safe since written to disk +- T1 and 6 need to be undone. +- Since checkpoint, redo T4 and 5. +- ![](Pasted%20image%2020240305135043.png) +# Purpose of Recovery Log File + +- Scan log backwards +- Create undo / redo lists +- Undo List: Transactions active at time of crash + - Perform undo(T) for every transaction in list + - Stop when reaching \ for every transaction in list. +- Redo List: Transactions committed after last checkpoint + - Redo for each transaction in list. + +## Example of Log Use ( Immediate ) +![](Pasted%20image%2020240305135229.png) diff --git a/Semester 2/Programming 2/Project/Part 2/AudioVisual.class b/Semester 2/Programming 2/Project/Part 2/AudioVisual.class index 8985717..5c3c0fc 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/AudioVisual.class and b/Semester 2/Programming 2/Project/Part 2/AudioVisual.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/AudioVisual.java b/Semester 2/Programming 2/Project/Part 2/AudioVisual.java index e327223..3db6f9d 100644 --- a/Semester 2/Programming 2/Project/Part 2/AudioVisual.java +++ b/Semester 2/Programming 2/Project/Part 2/AudioVisual.java @@ -1,14 +1,12 @@ /** - * Write a description of class AudioVisual here. + * Subclass of LibraryItem to create objects of audio and visual items in a library. * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @1.0 */ import java.util.Scanner; -import java.util.ArrayList; -import java.util.NoSuchElementException; public abstract class AudioVisual extends LibraryItem { diff --git a/Semester 2/Programming 2/Project/Part 2/Book.class b/Semester 2/Programming 2/Project/Part 2/Book.class index 480c60a..317197a 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.ctxt b/Semester 2/Programming 2/Project/Part 2/Book.ctxt index e755cf2..c2a789d 100644 --- a/Semester 2/Programming 2/Project/Part 2/Book.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/Book.ctxt @@ -1,9 +1,23 @@ #BlueJ class context comment0.params= comment0.target=Book() -comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Book\n +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Book\n\ Since\ all\ field\ variables\ initialise\ as\ null,\ nothing\ should\ happen\ here.\n comment1.params= -comment1.target=void\ printDetails() -comment2.params=detailScanner -comment2.target=void\ readItemData(java.util.Scanner) -numComments=3 +comment1.target=java.lang.String\ getAuthor() +comment1.text=\n\ Return\ value\ of\ @author\n +comment2.params= +comment2.target=java.lang.String\ getIsbn() +comment2.text=\n\ Return\ value\ of\ @isbn.\n +comment3.params=author +comment3.target=void\ setAuthor(java.lang.String) +comment3.text=\n\ Set\ value\ of\ @author.\n +comment4.params=isbn +comment4.target=void\ setIsbn(java.lang.String) +comment4.text=\n\ Set\ value\ of\ @isbn\n +comment5.params= +comment5.target=void\ printDetails() +comment5.text=\n\ Print\ to\ terminal,\ relevant\ details\ of\ current\ object.\n +comment6.params=detailScanner +comment6.target=void\ readItemData(java.util.Scanner) +comment6.text=\n\ Passed\ a\ scanner\ object,\ set\ field\ variables\ to\ corresponding\ values.\n +numComments=7 diff --git a/Semester 2/Programming 2/Project/Part 2/Book.java b/Semester 2/Programming 2/Project/Part 2/Book.java index dfa1e28..edc12a2 100644 --- a/Semester 2/Programming 2/Project/Part 2/Book.java +++ b/Semester 2/Programming 2/Project/Part 2/Book.java @@ -3,7 +3,7 @@ * Subclass of LibraryItem that emulates a Book item. * * @George Wilkinson - * @1.0 + * @2.3 */ import java.util.Scanner; @@ -15,15 +15,54 @@ public class Book extends PrintedItem /** * Constructor for objects of class Book + * Since all field variables initialise as null, nothing should happen here. */ public Book(){} + /* + * Return value of @author + */ + public String getAuthor() + { + return author; + } + + /* + * Return value of @isbn. + */ + public String getIsbn() + { + return isbn; + } + + /* + * Set value of @author. + */ + public void setAuthor( String author ) + { + this.author = author; + } + + /* + * Set value of @isbn + */ + public void setIsbn( String isbn ) + { + this.isbn = isbn; + } + + /* + * Print to terminal, relevant details of current object. + */ public void printDetails() { System.out.println( "ISBN: " + isbn + "\nAuthor: " + author ); super.printDetails(); } + /* + * Passed a scanner object, set field variables to corresponding values. + */ public void readItemData( Scanner detailScanner ){ if ( detailScanner != null ) { this.author = detailScanner.next().trim(); diff --git a/Semester 2/Programming 2/Project/Part 2/CD.class b/Semester 2/Programming 2/Project/Part 2/CD.class index bfe43d4..0f23deb 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/CD.class 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 index 90b7fc7..7e09051 100644 --- a/Semester 2/Programming 2/Project/Part 2/CD.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/CD.ctxt @@ -1,17 +1,23 @@ #BlueJ class context comment0.params= comment0.target=CD() -comment0.text=\n\ Constructor\ for\ objects\ of\ class\ CD\n +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ CD\n\ Since\ all\ field\ variables\ initialise\ as\ null,\ nothing\ should\ happen\ here.\n comment1.params= comment1.target=java.lang.String\ getArtist() +comment1.text=\n\ Return\ value\ of\ @artist.\n comment2.params= comment2.target=int\ noOfTracks() +comment2.text=\n\ Return\ value\ of\ @noOfTracks\n comment3.params=artist comment3.target=void\ setArtist(java.lang.String) +comment3.text=\n\ Set\ value\ of\ @artist.\n comment4.params=noOfTracks comment4.target=void\ setNoOfTracks(int) +comment4.text=\n\ Set\ value\ of\ @noOfTracks.\n comment5.params= comment5.target=void\ printDetails() +comment5.text=\n\ Print\ to\ terminal,\ relevant\ details\ of\ current\ object.\n comment6.params=detailScanner comment6.target=void\ readItemData(java.util.Scanner) +comment6.text=\n\ Passed\ a\ scanner,\ set\ the\ relevant\ details\ to\ their\ corresponding\ field\ variables.\n numComments=7 diff --git a/Semester 2/Programming 2/Project/Part 2/CD.java b/Semester 2/Programming 2/Project/Part 2/CD.java index 4ea6657..c06b2e8 100644 --- a/Semester 2/Programming 2/Project/Part 2/CD.java +++ b/Semester 2/Programming 2/Project/Part 2/CD.java @@ -1,9 +1,9 @@ /** - * Write a description of class CD here. + * Subclass of AudioVisual, to create objects of a CD. * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @1.0 */ import java.util.Scanner; @@ -15,35 +15,54 @@ public class CD extends AudioVisual /** * Constructor for objects of class CD + * Since all field variables initialise as null, nothing should happen here. */ public CD(){} + /* + * Return value of @artist. + */ public String getArtist() { return artist; } + /* + * Return value of @noOfTracks + */ public int noOfTracks() { return noOfTracks; } + /* + * Set value of @artist. + */ public void setArtist( String artist ) { this.artist = artist; } + /* + * Set value of @noOfTracks. + */ public void setNoOfTracks( int noOfTracks ) { this.noOfTracks = noOfTracks; } + /* + * Print to terminal, relevant details of current object. + */ public void printDetails() { System.out.println( "Artist: " + artist + "\nTrack Count: " + noOfTracks ); super.printDetails(); } + /* + * Passed a scanner, set the relevant details to their corresponding field variables. + */ public void readItemData( Scanner detailScanner ){ if ( detailScanner != null ) { this.artist = detailScanner.next().trim(); diff --git a/Semester 2/Programming 2/Project/Part 2/DVD.class b/Semester 2/Programming 2/Project/Part 2/DVD.class index fb9a4ec..b14f577 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/DVD.class 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 index 4fe780a..09b5965 100644 --- a/Semester 2/Programming 2/Project/Part 2/DVD.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/DVD.ctxt @@ -1,13 +1,17 @@ #BlueJ class context comment0.params= comment0.target=DVD() -comment0.text=\n\ Constructor\ for\ objects\ of\ class\ DVD\n +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ DVD\n\ Since\ all\ field\ variables\ initialise\ as\ null,\ nothing\ should\ happen\ here.\n comment1.params= comment1.target=java.lang.String\ getDirector() +comment1.text=\n\ Return\ value\ of\ @director.\n comment2.params=director comment2.target=void\ setDirector(java.lang.String) +comment2.text=\n\ Set\ value\ of\ @director.\n comment3.params= comment3.target=void\ printDetails() +comment3.text=\n\ Print\ relevant\ details\ of\ the\ current\ object.\n comment4.params=detailScanner comment4.target=void\ readItemData(java.util.Scanner) +comment4.text=\n\ Passed\ a\ scanner\ object,\ give\ the\ relevant\ variable\ a\ value.\n numComments=5 diff --git a/Semester 2/Programming 2/Project/Part 2/DVD.java b/Semester 2/Programming 2/Project/Part 2/DVD.java index d6a88b4..597c108 100644 --- a/Semester 2/Programming 2/Project/Part 2/DVD.java +++ b/Semester 2/Programming 2/Project/Part 2/DVD.java @@ -1,9 +1,9 @@ /** - * Write a description of class DVD here. + * Subclass of AudioVisual to create objects of DVD items. * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @1.0 */ import java.util.Scanner; @@ -11,26 +11,40 @@ import java.util.Scanner; public class DVD extends AudioVisual { private String director; + /** * Constructor for objects of class DVD + * Since all field variables initialise as null, nothing should happen here. */ public DVD(){} + /* + * Return value of @director. + */ public String getDirector() { return director; } + /* + * Set value of @director. + */ public void setDirector( String director ) { this.director = director; } + /* + * Print relevant details of the current object. + */ public void printDetails() { System.out.println( "Director: " + director ); super.printDetails(); } + /* + * Passed a scanner object, give the relevant variable a value. + */ public void readItemData( Scanner detailScanner ){ if ( detailScanner != null ) { this.director = detailScanner.next().trim(); diff --git a/Semester 2/Programming 2/Project/Part 2/Library.class b/Semester 2/Programming 2/Project/Part 2/Library.class index 2235d20..ddeb752 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 7b62a00..7e30fc6 100644 --- a/Semester 2/Programming 2/Project/Part 2/Library.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/Library.ctxt @@ -10,7 +10,7 @@ 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 +comment3.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 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 diff --git a/Semester 2/Programming 2/Project/Part 2/Library.java b/Semester 2/Programming 2/Project/Part 2/Library.java index 217b766..91112fd 100644 --- a/Semester 2/Programming 2/Project/Part 2/Library.java +++ b/Semester 2/Programming 2/Project/Part 2/Library.java @@ -3,7 +3,7 @@ * Class to create objects of a Library, which can hold and report on assets held within * * @George Wilkinson - * @2.0 + * @3.0 */ // Import all required libraries. Not using .* as it is not good practice due to potential conflicts. diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryItem.class b/Semester 2/Programming 2/Project/Part 2/LibraryItem.class index 8e6a498..37afb76 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 7b85381..9d064c0 100644 --- a/Semester 2/Programming 2/Project/Part 2/LibraryItem.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/LibraryItem.ctxt @@ -6,9 +6,10 @@ comment1.params= comment1.target=java.lang.String\ getItemCode() 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 +comment10.text=\n\ Print\ to\ terminal,\ relevant\ field\ variables\n comment11.params=detailScanner comment11.target=void\ readItemData(java.util.Scanner) +comment11.text=\n\ Passed\ a\ scanner\ object,\ assign\ values\ to\ relevant\ field\ variables\n comment2.params= comment2.target=int\ getCost() comment3.params= diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryItem.java b/Semester 2/Programming 2/Project/Part 2/LibraryItem.java index c5d0ebe..d5f7392 100644 --- a/Semester 2/Programming 2/Project/Part 2/LibraryItem.java +++ b/Semester 2/Programming 2/Project/Part 2/LibraryItem.java @@ -3,7 +3,7 @@ * Superclass of items / assets stored in a Library. * * @George Wilkinson - * @2.1 + * @3.1 */ import java.util.Scanner; @@ -12,7 +12,7 @@ import java.util.NoSuchElementException; public abstract class LibraryItem { - // instance variables - replace the example below with your own + // instance variables private String title; private String itemCode; private int cost; @@ -81,25 +81,15 @@ public abstract class LibraryItem /* * 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."); - if( onLoan ) - System.out.println( "This item is at present on loan and when new cost " + cost + " pence.\n" ); - else - System.out.println( "This item is at present not on loan and when new cost " + cost + " pence.\n" ); - } + + /* + * Print to terminal, relevant field variables */ - public void printDetails() { System.out.println("Item Code: " + itemCode + "\nTitle: " + title + - "\nCost: £" + ( ( float )( cost ) )/100 + + "\nCost: £" + ( ( float )( cost ) )/100 + // Convert cost in pence to £pounds.pence to be more readable. "\nBorrowed " + getTimesBorrowed() + " times." ); if( getOnLoan() ) System.out.println( "On Loan"); @@ -107,6 +97,9 @@ public abstract class LibraryItem System.out.println( "Available to Loan"); } + /* + * Passed a scanner object, assign values to relevant field variables + */ public void readItemData( Scanner detailScanner ) { if ( detailScanner != null ) { diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryUser.class b/Semester 2/Programming 2/Project/Part 2/LibraryUser.class index a8c37a1..743acac 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/LibraryUser.class 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 index 8c4c505..83106f2 100644 --- a/Semester 2/Programming 2/Project/Part 2/LibraryUser.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/LibraryUser.ctxt @@ -4,14 +4,18 @@ comment0.target=LibraryUser() comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser\n comment1.params= comment1.target=java.lang.String\ getUserID() +comment1.text=\n\ Accessor\ start\ -\ return\ values\ of\ corresponding\ variables.\n comment10.params=title comment10.target=void\ setTitle(java.lang.String) comment11.params=writer comment11.target=void\ writeData(java.io.PrintWriter) +comment11.text=\n\ Passed\ a\ PrintWriter,\ append\ field\ variables\ in\ a\ set\ format,\ and\ flush\ the\ buffer.\n comment12.params= comment12.target=void\ printDetails() +comment12.text=\n\ Print\ to\ terminal,\ all\ relevant\ fields.\n comment13.params=detailScanner comment13.target=void\ readData(java.util.Scanner) +comment13.text=\n\ Passed\ a\ scanner\ object,\ assign\ relevant\ values\ to\ field\ variables.\n comment2.params= comment2.target=java.lang.String\ getSurname() comment3.params= @@ -22,6 +26,7 @@ comment5.params= comment5.target=java.lang.String\ getTitle() comment6.params=userID comment6.target=void\ setUserID(java.lang.String) +comment6.text=\n\ Accessor\ End\n\ Mutator\ Start\ -\ Set\ value\ of\ corresponding\ variables\n comment7.params=surname comment7.target=void\ setSurname(java.lang.String) comment8.params=firstName diff --git a/Semester 2/Programming 2/Project/Part 2/LibraryUser.java b/Semester 2/Programming 2/Project/Part 2/LibraryUser.java index d3a85c9..251de65 100644 --- a/Semester 2/Programming 2/Project/Part 2/LibraryUser.java +++ b/Semester 2/Programming 2/Project/Part 2/LibraryUser.java @@ -1,9 +1,9 @@ /** - * Write a description of class LibraryUser here. + * Class LibraryUser to create a user of a library. * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @1.0 */ import java.util.Scanner; @@ -11,7 +11,7 @@ import java.io.PrintWriter; public class LibraryUser { - // instance variables - replace the example below with your own + // instance variables private String userID, surname, firstName, otherInitials, title; /** @@ -19,6 +19,9 @@ public class LibraryUser */ public LibraryUser(){} + /* + * Accessor start - return values of corresponding variables. + */ public String getUserID(){ return userID; } @@ -39,8 +42,11 @@ public class LibraryUser return title; } - - + /* + * Accessor End + * Mutator Start - Set value of corresponding variables + */ + public void setUserID( String userID ){ this.userID = userID; } @@ -61,18 +67,31 @@ public class LibraryUser this.title = title; } + /* + * Mutator End + */ + + /* + * Passed a PrintWriter, append field variables in a set format, and flush the buffer. + */ public void writeData( PrintWriter writer ) { writer.print(userID + ", " + surname + ", " + firstName + ", " + otherInitials + ", " + title + "\n"); writer.flush(); } + /* + * Print to terminal, all relevant fields. + */ public void printDetails() { System.out.println( "ID: " + userID + "\nName: " + title + " " + firstName + " " + otherInitials + " " + surname ); } + /* + * Passed a scanner object, assign relevant values to field variables. + */ public void readData( Scanner detailScanner ) { if ( detailScanner != null ) { diff --git a/Semester 2/Programming 2/Project/Part 2/Periodical.class b/Semester 2/Programming 2/Project/Part 2/Periodical.class index f5375b3..70f9287 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.ctxt b/Semester 2/Programming 2/Project/Part 2/Periodical.ctxt index 66ac73a..2f0574a 100644 --- a/Semester 2/Programming 2/Project/Part 2/Periodical.ctxt +++ b/Semester 2/Programming 2/Project/Part 2/Periodical.ctxt @@ -1,8 +1,17 @@ #BlueJ class context comment0.params= comment0.target=Periodical() +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Periodical\n\ Since\ all\ field\ variables\ initialise\ as\ null,\ nothing\ should\ happen\ here.\n comment1.params= -comment1.target=void\ printDetails() -comment2.params=detailScanner -comment2.target=void\ readItemData(java.util.Scanner) -numComments=3 +comment1.target=java.lang.String\ getPublicationDate() +comment1.text=\n\ Return\ value\ of\ @publicationDate\n +comment2.params=publicationDate +comment2.target=void\ setPublicationDate(java.lang.String) +comment2.text=\n\ Set\ value\ of\ @publicationDate\n +comment3.params= +comment3.target=void\ printDetails() +comment3.text=\n\ Print\ to\ terminal,\ relevant\ field\ variable's\ values.\n +comment4.params=detailScanner +comment4.target=void\ readItemData(java.util.Scanner) +comment4.text=\n\ Passed\ a\ scanner,\ assign\ relevant\ values\ to\ field\ variables.\n +numComments=5 diff --git a/Semester 2/Programming 2/Project/Part 2/Periodical.java b/Semester 2/Programming 2/Project/Part 2/Periodical.java index 1d3275b..f2a28d2 100644 --- a/Semester 2/Programming 2/Project/Part 2/Periodical.java +++ b/Semester 2/Programming 2/Project/Part 2/Periodical.java @@ -3,7 +3,7 @@ * Subclass of LibraryItem to create a periodical ( e.g. newspaper, tabloid ). * * @George Wilkinson - * @1.0 + * @2.3 */ import java.util.Scanner; @@ -12,13 +12,39 @@ public class Periodical extends PrintedItem { private String publicationDate; + /** + * Constructor for objects of class Periodical + * Since all field variables initialise as null, nothing should happen here. + */ public Periodical(){} + /* + * Return value of @publicationDate + */ + public String getPublicationDate() + { + return publicationDate; + } + + /* + * Set value of @publicationDate + */ + public void setPublicationDate( String publicationDate ) + { + this.publicationDate = publicationDate; + } + + /* + * Print to terminal, relevant field variable's values. + */ public void printDetails() { System.out.println( "Publication Date: " + publicationDate ); super.printDetails(); } + /* + * Passed a scanner, assign relevant values to field variables. + */ public void readItemData( Scanner detailScanner ){ if ( detailScanner != null ) { this.publicationDate = detailScanner.next().trim(); diff --git a/Semester 2/Programming 2/Project/Part 2/PrintedItem.class b/Semester 2/Programming 2/Project/Part 2/PrintedItem.class index a657470..219c507 100644 Binary files a/Semester 2/Programming 2/Project/Part 2/PrintedItem.class and b/Semester 2/Programming 2/Project/Part 2/PrintedItem.class differ diff --git a/Semester 2/Programming 2/Project/Part 2/PrintedItem.java b/Semester 2/Programming 2/Project/Part 2/PrintedItem.java index bfd7f5e..de8467e 100644 --- a/Semester 2/Programming 2/Project/Part 2/PrintedItem.java +++ b/Semester 2/Programming 2/Project/Part 2/PrintedItem.java @@ -1,14 +1,12 @@ /** - * Write a description of class PrintedItem here. + * Subclass of LibraryItem to create objects of printed items in a library. * - * @author (your name) - * @version (a version number or a date) + * @George Wilkinson + * @1.0 */ import java.util.Scanner; -import java.util.ArrayList; -import java.util.NoSuchElementException; public abstract class PrintedItem extends LibraryItem { diff --git a/images/Pasted image 20240305130824.png b/images/Pasted image 20240305130824.png new file mode 100644 index 0000000..393b199 Binary files /dev/null and b/images/Pasted image 20240305130824.png differ diff --git a/images/Pasted image 20240305131110.png b/images/Pasted image 20240305131110.png new file mode 100644 index 0000000..118cd68 Binary files /dev/null and b/images/Pasted image 20240305131110.png differ diff --git a/images/Pasted image 20240305134506.png b/images/Pasted image 20240305134506.png new file mode 100644 index 0000000..eb3a6bf Binary files /dev/null and b/images/Pasted image 20240305134506.png differ diff --git a/images/Pasted image 20240305134734.png b/images/Pasted image 20240305134734.png new file mode 100644 index 0000000..86ef0dd Binary files /dev/null and b/images/Pasted image 20240305134734.png differ diff --git a/images/Pasted image 20240305134835.png b/images/Pasted image 20240305134835.png new file mode 100644 index 0000000..ea76633 Binary files /dev/null and b/images/Pasted image 20240305134835.png differ diff --git a/images/Pasted image 20240305134930.png b/images/Pasted image 20240305134930.png new file mode 100644 index 0000000..ea76633 Binary files /dev/null and b/images/Pasted image 20240305134930.png differ diff --git a/images/Pasted image 20240305134944.png b/images/Pasted image 20240305134944.png new file mode 100644 index 0000000..db49f02 Binary files /dev/null and b/images/Pasted image 20240305134944.png differ diff --git a/images/Pasted image 20240305135043.png b/images/Pasted image 20240305135043.png new file mode 100644 index 0000000..9716acf Binary files /dev/null and b/images/Pasted image 20240305135043.png differ diff --git a/images/Pasted image 20240305135229.png b/images/Pasted image 20240305135229.png new file mode 100644 index 0000000..d2e1c28 Binary files /dev/null and b/images/Pasted image 20240305135229.png differ