vault backup: 2024-03-05 16:01:50

This commit is contained in:
2024-03-05 16:01:50 +00:00
parent 8ce640b4ba
commit 28ea6a0a9b
36 changed files with 314 additions and 89 deletions

View File

@@ -8,12 +8,12 @@
"type": "tabs", "type": "tabs",
"children": [ "children": [
{ {
"id": "90e6fc52439b47f9", "id": "e96e468fb0a709e5",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "markdown", "type": "markdown",
"state": { "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", "mode": "source",
"source": false "source": false
} }
@@ -30,21 +30,11 @@
] ]
}, },
{ {
"id": "1177e1c9853f407d", "id": "97b758ffb617daa3",
"type": "tabs", "type": "tabs",
"children": [ "children": [
{ {
"id": "53317c245e573f8c", "id": "fdb9dea18c7f9c15",
"type": "leaf",
"state": {
"type": "pdf",
"state": {
"file": "Semester 2/Database Systems/Exercise Booklet.pdf"
}
}
},
{
"id": "e96e468fb0a709e5",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "pdf", "type": "pdf",
@@ -53,8 +43,7 @@
} }
} }
} }
], ]
"currentTab": 1
} }
], ],
"direction": "vertical" "direction": "vertical"
@@ -121,7 +110,7 @@
"state": { "state": {
"type": "backlink", "type": "backlink",
"state": { "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, "collapseAll": false,
"extraContext": false, "extraContext": false,
"sortOrder": "alphabetical", "sortOrder": "alphabetical",
@@ -138,7 +127,7 @@
"state": { "state": {
"type": "outgoing-link", "type": "outgoing-link",
"state": { "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, "linksCollapsed": false,
"unlinkedCollapsed": true "unlinkedCollapsed": true
} }
@@ -161,7 +150,7 @@
"state": { "state": {
"type": "outline", "type": "outline",
"state": { "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", "active": "e96e468fb0a709e5",
"lastOpenFiles": [ "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/Book.java#",
"Semester 2/Programming 2/Project/Part 2/Periodical.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/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#", "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 20240227171728.png",
"images/Pasted image 20240227171700.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/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/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/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/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 WS2.md",
"Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS1.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 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/Database Systems/Week 4/Week 4 Database Systems.md",
"Semester 2/HCI/Week 2/Week 2 Human Computer Interfaces.md", "Semester 2/HCI/Week 2/Week 2 Human Computer Interfaces.md",
"Semester 2/HCI/Week 3/Week 3 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 3/Week 3 Database Systems.md",
"Semester 2/Database Systems/Week 2/Week 2 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.2 - Network Components.md",
"CCNA/1 - Networking Today/1.1 - Networks Affect our Lives.md",
"Database Systems/Untitled.canvas", "Database Systems/Untitled.canvas",
"Untitled 1.canvas", "Untitled 1.canvas",
"Untitled.canvas" "Untitled.canvas"

View File

@@ -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 \<T1 start> and \<T1 commit> 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 <Ti,start> is in the log but <Ti,commit> 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 <Ti,start> and <Ti,commit> 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 \<T, start> 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)

View File

@@ -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) * @George Wilkinson
* @version (a version number or a date) * @1.0
*/ */
import java.util.Scanner; import java.util.Scanner;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public abstract class AudioVisual extends LibraryItem public abstract class AudioVisual extends LibraryItem
{ {

View File

@@ -1,9 +1,23 @@
#BlueJ class context #BlueJ class context
comment0.params= comment0.params=
comment0.target=Book() 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.params=
comment1.target=void\ printDetails() comment1.target=java.lang.String\ getAuthor()
comment2.params=detailScanner comment1.text=\n\ Return\ value\ of\ @author\n
comment2.target=void\ readItemData(java.util.Scanner) comment2.params=
numComments=3 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

View File

@@ -3,7 +3,7 @@
* Subclass of LibraryItem that emulates a Book item. * Subclass of LibraryItem that emulates a Book item.
* *
* @George Wilkinson * @George Wilkinson
* @1.0 * @2.3
*/ */
import java.util.Scanner; import java.util.Scanner;
@@ -15,15 +15,54 @@ public class Book extends PrintedItem
/** /**
* Constructor for objects of class Book * Constructor for objects of class Book
* Since all field variables initialise as null, nothing should happen here.
*/ */
public Book(){} 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() { public void printDetails() {
System.out.println( "ISBN: " + isbn + System.out.println( "ISBN: " + isbn +
"\nAuthor: " + author ); "\nAuthor: " + author );
super.printDetails(); super.printDetails();
} }
/*
* Passed a scanner object, set field variables to corresponding values.
*/
public void readItemData( Scanner detailScanner ){ public void readItemData( Scanner detailScanner ){
if ( detailScanner != null ) { if ( detailScanner != null ) {
this.author = detailScanner.next().trim(); this.author = detailScanner.next().trim();

View File

@@ -1,17 +1,23 @@
#BlueJ class context #BlueJ class context
comment0.params= comment0.params=
comment0.target=CD() 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.params=
comment1.target=java.lang.String\ getArtist() comment1.target=java.lang.String\ getArtist()
comment1.text=\n\ Return\ value\ of\ @artist.\n
comment2.params= comment2.params=
comment2.target=int\ noOfTracks() comment2.target=int\ noOfTracks()
comment2.text=\n\ Return\ value\ of\ @noOfTracks\n
comment3.params=artist comment3.params=artist
comment3.target=void\ setArtist(java.lang.String) comment3.target=void\ setArtist(java.lang.String)
comment3.text=\n\ Set\ value\ of\ @artist.\n
comment4.params=noOfTracks comment4.params=noOfTracks
comment4.target=void\ setNoOfTracks(int) comment4.target=void\ setNoOfTracks(int)
comment4.text=\n\ Set\ value\ of\ @noOfTracks.\n
comment5.params= comment5.params=
comment5.target=void\ printDetails() comment5.target=void\ printDetails()
comment5.text=\n\ Print\ to\ terminal,\ relevant\ details\ of\ current\ object.\n
comment6.params=detailScanner comment6.params=detailScanner
comment6.target=void\ readItemData(java.util.Scanner) 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 numComments=7

View File

@@ -1,9 +1,9 @@
/** /**
* Write a description of class CD here. * Subclass of AudioVisual, to create objects of a CD.
* *
* @author (your name) * @George Wilkinson
* @version (a version number or a date) * @1.0
*/ */
import java.util.Scanner; import java.util.Scanner;
@@ -15,35 +15,54 @@ public class CD extends AudioVisual
/** /**
* Constructor for objects of class CD * Constructor for objects of class CD
* Since all field variables initialise as null, nothing should happen here.
*/ */
public CD(){} public CD(){}
/*
* Return value of @artist.
*/
public String getArtist() public String getArtist()
{ {
return artist; return artist;
} }
/*
* Return value of @noOfTracks
*/
public int noOfTracks() public int noOfTracks()
{ {
return noOfTracks; return noOfTracks;
} }
/*
* Set value of @artist.
*/
public void setArtist( String artist ) public void setArtist( String artist )
{ {
this.artist = artist; this.artist = artist;
} }
/*
* Set value of @noOfTracks.
*/
public void setNoOfTracks( int noOfTracks ) public void setNoOfTracks( int noOfTracks )
{ {
this.noOfTracks = noOfTracks; this.noOfTracks = noOfTracks;
} }
/*
* Print to terminal, relevant details of current object.
*/
public void printDetails() { public void printDetails() {
System.out.println( "Artist: " + artist + System.out.println( "Artist: " + artist +
"\nTrack Count: " + noOfTracks ); "\nTrack Count: " + noOfTracks );
super.printDetails(); super.printDetails();
} }
/*
* Passed a scanner, set the relevant details to their corresponding field variables.
*/
public void readItemData( Scanner detailScanner ){ public void readItemData( Scanner detailScanner ){
if ( detailScanner != null ) { if ( detailScanner != null ) {
this.artist = detailScanner.next().trim(); this.artist = detailScanner.next().trim();

View File

@@ -1,13 +1,17 @@
#BlueJ class context #BlueJ class context
comment0.params= comment0.params=
comment0.target=DVD() 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.params=
comment1.target=java.lang.String\ getDirector() comment1.target=java.lang.String\ getDirector()
comment1.text=\n\ Return\ value\ of\ @director.\n
comment2.params=director comment2.params=director
comment2.target=void\ setDirector(java.lang.String) comment2.target=void\ setDirector(java.lang.String)
comment2.text=\n\ Set\ value\ of\ @director.\n
comment3.params= comment3.params=
comment3.target=void\ printDetails() comment3.target=void\ printDetails()
comment3.text=\n\ Print\ relevant\ details\ of\ the\ current\ object.\n
comment4.params=detailScanner comment4.params=detailScanner
comment4.target=void\ readItemData(java.util.Scanner) comment4.target=void\ readItemData(java.util.Scanner)
comment4.text=\n\ Passed\ a\ scanner\ object,\ give\ the\ relevant\ variable\ a\ value.\n
numComments=5 numComments=5

View File

@@ -1,9 +1,9 @@
/** /**
* Write a description of class DVD here. * Subclass of AudioVisual to create objects of DVD items.
* *
* @author (your name) * @George Wilkinson
* @version (a version number or a date) * @1.0
*/ */
import java.util.Scanner; import java.util.Scanner;
@@ -11,26 +11,40 @@ import java.util.Scanner;
public class DVD extends AudioVisual public class DVD extends AudioVisual
{ {
private String director; private String director;
/** /**
* Constructor for objects of class DVD * Constructor for objects of class DVD
* Since all field variables initialise as null, nothing should happen here.
*/ */
public DVD(){} public DVD(){}
/*
* Return value of @director.
*/
public String getDirector() public String getDirector()
{ {
return director; return director;
} }
/*
* Set value of @director.
*/
public void setDirector( String director ) public void setDirector( String director )
{ {
this.director = director; this.director = director;
} }
/*
* Print relevant details of the current object.
*/
public void printDetails() { public void printDetails() {
System.out.println( "Director: " + director ); System.out.println( "Director: " + director );
super.printDetails(); super.printDetails();
} }
/*
* Passed a scanner object, give the relevant variable a value.
*/
public void readItemData( Scanner detailScanner ){ public void readItemData( Scanner detailScanner ){
if ( detailScanner != null ) { if ( detailScanner != null ) {
this.director = detailScanner.next().trim(); this.director = detailScanner.next().trim();

View File

@@ -10,7 +10,7 @@ comment2.target=void\ storeUser(LibraryUser)
comment2.text=\n\ Appends\ a\ LibraryUser\ to\ the\ userList.\n comment2.text=\n\ Appends\ a\ LibraryUser\ to\ the\ userList.\n
comment3.params=prefix\ length comment3.params=prefix\ length
comment3.target=java.lang.String\ generateUserID(java.lang.String,\ int) 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.params=
comment4.target=void\ writeUserData() 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 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

View File

@@ -3,7 +3,7 @@
* Class to create objects of a Library, which can hold and report on assets held within * Class to create objects of a Library, which can hold and report on assets held within
* *
* @George Wilkinson * @George Wilkinson
* @2.0 * @3.0
*/ */
// Import all required libraries. Not using .* as it is not good practice due to potential conflicts. // Import all required libraries. Not using .* as it is not good practice due to potential conflicts.

View File

@@ -6,9 +6,10 @@ comment1.params=
comment1.target=java.lang.String\ getItemCode() comment1.target=java.lang.String\ getItemCode()
comment10.params= comment10.params=
comment10.target=void\ printDetails() 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.params=detailScanner
comment11.target=void\ readItemData(java.util.Scanner) comment11.target=void\ readItemData(java.util.Scanner)
comment11.text=\n\ Passed\ a\ scanner\ object,\ assign\ values\ to\ relevant\ field\ variables\n
comment2.params= comment2.params=
comment2.target=int\ getCost() comment2.target=int\ getCost()
comment3.params= comment3.params=

View File

@@ -3,7 +3,7 @@
* Superclass of items / assets stored in a Library. * Superclass of items / assets stored in a Library.
* *
* @George Wilkinson * @George Wilkinson
* @2.1 * @3.1
*/ */
import java.util.Scanner; import java.util.Scanner;
@@ -12,7 +12,7 @@ import java.util.NoSuchElementException;
public abstract class LibraryItem public abstract class LibraryItem
{ {
// instance variables - replace the example below with your own // instance variables
private String title; private String title;
private String itemCode; private String itemCode;
private int cost; private int cost;
@@ -82,24 +82,14 @@ public abstract class LibraryItem
* Field Mutator End * Field Mutator End
*/ */
// Output to console the details of the fields in a human-readable format. /*
* Print to terminal, relevant field variables
/*
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" );
}
*/ */
public void printDetails() public void printDetails()
{ {
System.out.println("Item Code: " + itemCode + System.out.println("Item Code: " + itemCode +
"\nTitle: " + title + "\nTitle: " + title +
"\nCost: £" + ( ( float )( cost ) )/100 + "\nCost: £" + ( ( float )( cost ) )/100 + // Convert cost in pence to £pounds.pence to be more readable.
"\nBorrowed " + getTimesBorrowed() + " times." ); "\nBorrowed " + getTimesBorrowed() + " times." );
if( getOnLoan() ) if( getOnLoan() )
System.out.println( "On Loan"); System.out.println( "On Loan");
@@ -107,6 +97,9 @@ public abstract class LibraryItem
System.out.println( "Available to Loan"); System.out.println( "Available to Loan");
} }
/*
* Passed a scanner object, assign values to relevant field variables
*/
public void readItemData( Scanner detailScanner ) { public void readItemData( Scanner detailScanner ) {
if ( detailScanner != null ) { if ( detailScanner != null ) {

View File

@@ -4,14 +4,18 @@ comment0.target=LibraryUser()
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser\n comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser\n
comment1.params= comment1.params=
comment1.target=java.lang.String\ getUserID() comment1.target=java.lang.String\ getUserID()
comment1.text=\n\ Accessor\ start\ -\ return\ values\ of\ corresponding\ variables.\n
comment10.params=title comment10.params=title
comment10.target=void\ setTitle(java.lang.String) comment10.target=void\ setTitle(java.lang.String)
comment11.params=writer comment11.params=writer
comment11.target=void\ writeData(java.io.PrintWriter) 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.params=
comment12.target=void\ printDetails() comment12.target=void\ printDetails()
comment12.text=\n\ Print\ to\ terminal,\ all\ relevant\ fields.\n
comment13.params=detailScanner comment13.params=detailScanner
comment13.target=void\ readData(java.util.Scanner) comment13.target=void\ readData(java.util.Scanner)
comment13.text=\n\ Passed\ a\ scanner\ object,\ assign\ relevant\ values\ to\ field\ variables.\n
comment2.params= comment2.params=
comment2.target=java.lang.String\ getSurname() comment2.target=java.lang.String\ getSurname()
comment3.params= comment3.params=
@@ -22,6 +26,7 @@ comment5.params=
comment5.target=java.lang.String\ getTitle() comment5.target=java.lang.String\ getTitle()
comment6.params=userID comment6.params=userID
comment6.target=void\ setUserID(java.lang.String) 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.params=surname
comment7.target=void\ setSurname(java.lang.String) comment7.target=void\ setSurname(java.lang.String)
comment8.params=firstName comment8.params=firstName

View File

@@ -1,9 +1,9 @@
/** /**
* Write a description of class LibraryUser here. * Class LibraryUser to create a user of a library.
* *
* @author (your name) * @George Wilkinson
* @version (a version number or a date) * @1.0
*/ */
import java.util.Scanner; import java.util.Scanner;
@@ -11,7 +11,7 @@ import java.io.PrintWriter;
public class LibraryUser public class LibraryUser
{ {
// instance variables - replace the example below with your own // instance variables
private String userID, surname, firstName, otherInitials, title; private String userID, surname, firstName, otherInitials, title;
/** /**
@@ -19,6 +19,9 @@ public class LibraryUser
*/ */
public LibraryUser(){} public LibraryUser(){}
/*
* Accessor start - return values of corresponding variables.
*/
public String getUserID(){ public String getUserID(){
return userID; return userID;
} }
@@ -39,7 +42,10 @@ public class LibraryUser
return title; return title;
} }
/*
* Accessor End
* Mutator Start - Set value of corresponding variables
*/
public void setUserID( String userID ){ public void setUserID( String userID ){
this.userID = userID; this.userID = userID;
@@ -61,18 +67,31 @@ public class LibraryUser
this.title = title; this.title = title;
} }
/*
* Mutator End
*/
/*
* Passed a PrintWriter, append field variables in a set format, and flush the buffer.
*/
public void writeData( PrintWriter writer ) public void writeData( PrintWriter writer )
{ {
writer.print(userID + ", " + surname + ", " + firstName + ", " + otherInitials + ", " + title + "\n"); writer.print(userID + ", " + surname + ", " + firstName + ", " + otherInitials + ", " + title + "\n");
writer.flush(); writer.flush();
} }
/*
* Print to terminal, all relevant fields.
*/
public void printDetails() public void printDetails()
{ {
System.out.println( "ID: " + userID + System.out.println( "ID: " + userID +
"\nName: " + title + " " + firstName + " " + otherInitials + " " + surname ); "\nName: " + title + " " + firstName + " " + otherInitials + " " + surname );
} }
/*
* Passed a scanner object, assign relevant values to field variables.
*/
public void readData( Scanner detailScanner ) public void readData( Scanner detailScanner )
{ {
if ( detailScanner != null ) { if ( detailScanner != null ) {

View File

@@ -1,8 +1,17 @@
#BlueJ class context #BlueJ class context
comment0.params= comment0.params=
comment0.target=Periodical() 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.params=
comment1.target=void\ printDetails() comment1.target=java.lang.String\ getPublicationDate()
comment2.params=detailScanner comment1.text=\n\ Return\ value\ of\ @publicationDate\n
comment2.target=void\ readItemData(java.util.Scanner) comment2.params=publicationDate
numComments=3 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

View File

@@ -3,7 +3,7 @@
* Subclass of LibraryItem to create a periodical ( e.g. newspaper, tabloid ). * Subclass of LibraryItem to create a periodical ( e.g. newspaper, tabloid ).
* *
* @George Wilkinson * @George Wilkinson
* @1.0 * @2.3
*/ */
import java.util.Scanner; import java.util.Scanner;
@@ -12,13 +12,39 @@ public class Periodical extends PrintedItem
{ {
private String publicationDate; private String publicationDate;
/**
* Constructor for objects of class Periodical
* Since all field variables initialise as null, nothing should happen here.
*/
public Periodical(){} 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() { public void printDetails() {
System.out.println( "Publication Date: " + publicationDate ); System.out.println( "Publication Date: " + publicationDate );
super.printDetails(); super.printDetails();
} }
/*
* Passed a scanner, assign relevant values to field variables.
*/
public void readItemData( Scanner detailScanner ){ public void readItemData( Scanner detailScanner ){
if ( detailScanner != null ) { if ( detailScanner != null ) {
this.publicationDate = detailScanner.next().trim(); this.publicationDate = detailScanner.next().trim();

View File

@@ -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) * @George Wilkinson
* @version (a version number or a date) * @1.0
*/ */
import java.util.Scanner; import java.util.Scanner;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public abstract class PrintedItem extends LibraryItem public abstract class PrintedItem extends LibraryItem
{ {

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB