vault backup: 2024-03-05 16:01:50
This commit is contained in:
@@ -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
|
||||
|
||||

|
||||
Failure in different places:
|
||||

|
||||
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
|
||||
|
||||

|
||||
|
||||
# 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.
|
||||
|
||||

|
||||
|
||||
### 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.
|
||||
- 
|
||||
### 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
|
||||
- 
|
||||
### 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.
|
||||
- 
|
||||
# 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 )
|
||||

|
Binary file not shown.
@@ -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
|
||||
{
|
||||
|
Binary file not shown.
@@ -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
|
||||
|
@@ -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();
|
||||
|
Binary file not shown.
@@ -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
|
||||
|
@@ -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();
|
||||
|
Binary file not shown.
@@ -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
|
||||
|
@@ -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();
|
||||
|
Binary file not shown.
@@ -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
|
||||
|
@@ -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.
|
||||
|
Binary file not shown.
@@ -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=
|
||||
|
@@ -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 ) {
|
||||
|
Binary file not shown.
@@ -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
|
||||
|
@@ -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 ) {
|
||||
|
Binary file not shown.
@@ -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
|
||||
|
@@ -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();
|
||||
|
Binary file not shown.
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user