vault backup: 2024-02-06 13:09:16

This commit is contained in:
2024-02-06 13:09:16 +00:00
parent 2b33fac04c
commit 36191e891d
11 changed files with 179 additions and 47 deletions

View File

@@ -11,10 +11,11 @@
"id": "505b4bbc8a7e15f6",
"type": "leaf",
"state": {
"type": "diff-view",
"type": "markdown",
"state": {
"file": ".obsidian/workspace.json",
"staged": false
"file": "Semester 2/Database Systems/Week 4/Week 4 Database Systems.md",
"mode": "source",
"source": false
}
}
}
@@ -85,6 +86,7 @@
"state": {
"type": "backlink",
"state": {
"file": "Semester 2/Database Systems/Week 4/Week 4 Database Systems.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
@@ -101,6 +103,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "Semester 2/Database Systems/Week 4/Week 4 Database Systems.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
@@ -122,7 +125,9 @@
"type": "leaf",
"state": {
"type": "outline",
"state": {}
"state": {
"file": "Semester 2/Database Systems/Week 4/Week 4 Database Systems.md"
}
}
},
{
@@ -163,10 +168,19 @@
},
"active": "505b4bbc8a7e15f6",
"lastOpenFiles": [
"Semester 2/Database Systems/Week 4/Week 4 Database Systems.md",
"Semester 2/Database Systems/Week 4",
"Semester 2/Programming 2/Project/Part 1/__SHELL78.class",
"Semester 2/Programming 2/Project/Part 1/__SHELL78.java",
"Semester 2/Programming 2/Project/Part 1/__SHELL75.class",
"Semester 2/Programming 2/Project/Part 1/__SHELL75.java",
"Semester 2/Programming 2/Project/Part 1/__SHELL74.class",
"Semester 2/Programming 2/Project/Part 1/__SHELL74.java",
"Semester 2/Programming 2/Project/Part 1/item_data_1.txt",
"Semester 2/Programming 2/Project/Part 1/Library.java#",
"Semester 2/Programming 2/Project/Part 1/LibraryItem.java#",
"Semester 2/HCI/Week 2/Week 2 Human Computer Interfaces.md",
"Semester 2/HCI/Week 3/Week 3 Human Computer Interfaces.md",
"Semester 1/Database Systems/Exercise Booklet.pdf",
"Semester 2/HCI/Week 3",
"Semester 1/Database Systems/Week 10/Week 10 Database Systems.md",
"Semester 1/Database Systems/Week 11/Week 11 Database Systems.md",
"Semester 1/Database Systems/Week 5/Week 5 Database Systems.md",
@@ -178,11 +192,7 @@
"Semester 1/Database Systems/Week 4/Week 4 Database Systems - Data Description Language.md",
"Semester 1/Database Systems/Week 6/Week 6 Database Systems.md",
"Semester 2/Database Systems/Week 3/Week 3 Database Systems.md",
"Semester 2/Computer Systems Internals & Linux/Week 3/q1.sh",
"Semester 2/Computer Systems Internals & Linux/Week 3",
"Semester 2/Database Systems/Exercise Booklet.pdf",
"Semester 2/Database Systems/Week 2/Week 2 Database Systems.md",
"Semester 2/Database Systems/Week 3",
"images/Pasted image 20240126103004.png",
"images/Pasted image 20240126102902.png",
"images/Pasted image 20240126101454.png",
@@ -192,11 +202,7 @@
"CCNA/1 - Networking Today/1.2 - Network Components.md",
"images/Pasted image 20240125163704.png",
"CCNA/1 - Networking Today/1.1 - Networks Affect our Lives.md",
"CCNA/1 - Networking Today",
"CCNA/Module Information.md",
"CCNA",
"Semester 2/Computer Systems Internals & Linux/Week 2/media/geese_honk_on_public_farm_with_people_in_background_uk.mp3",
"Semester 2/Computer Systems Internals & Linux/Week 2/media/freethunderstormtimelapse.mov",
"Semester 2/Computer Systems Internals & Linux/Week 2/media/freeimage-7063371.jpg",
"Semester 2/Computer Systems Internals & Linux/Week 2/media/freeimage-5931627.jpg",
"Semester 2/Computer Systems Internals & Linux/Week 2/media/freeimage-216999.jpg",

View File

@@ -0,0 +1 @@
#

View File

@@ -4,6 +4,10 @@ comment0.target=Library()
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Library\n
comment1.params=item
comment1.target=void\ storeItem(LibraryItem)
comment1.text=\n\ Appends\ a\ LibraryItem\ to\ the\ itemList.\n
comment2.params=
comment2.target=void\ printAllItems()
numComments=3
comment2.text=\n\ Prints\ to\ the\ terminal\ all\ items\ in\ the\ itemList\n
comment3.params=
comment3.target=void\ readItemData()
numComments=4

View File

@@ -6,13 +6,21 @@
* @version (a version number or a date)
*/
// Import all required libraries. Not using .* as it is not good practice due to potential conflicts.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.IOException;
import java.awt.FileDialog;
import java.awt.Frame;
public class Library
{
private ArrayList<LibraryItem> itemList;
private ArrayList<LibraryItem> itemList; // Initialise an ArrayList of name itemList to store LibraryItems
/**
/*
* Constructor for objects of class Library
*/
public Library()
@@ -20,11 +28,17 @@ public class Library
itemList = new ArrayList<LibraryItem>();
}
/*
* Appends a LibraryItem to the itemList.
*/
public void storeItem( LibraryItem item )
{
itemList.add( item );
}
/*
* Prints to the terminal all items in the itemList
*/
public void printAllItems()
{
for( LibraryItem item : itemList )
@@ -33,4 +47,34 @@ public class Library
}
}
public void readItemData() //throws IOException
{
try {
Frame frame = null; // Initialise a null frame
FileDialog fileBox = new FileDialog( frame, "Open", FileDialog.LOAD ); // Initialise filebox with the null frame pointer
fileBox.setVisible( true ); // Open a file selection dialog to the user.
Scanner fileScanner = new Scanner( new File( fileBox.getDirectory() + fileBox.getFile() ) );
while( fileScanner.hasNextLine() )
{
String lineItem = fileScanner.nextLine();
if ( !lineItem.contains( "//" ) && !lineItem.trim().isEmpty() ) { // Ensure no comments or empty lines are included
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list
LibraryItem libraryItem = new LibraryItem();
libraryItem.readData( detailScanner );
storeItem( libraryItem ); // Store the new LibraryItem in the itemList
}
}
}
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
}
}
}

View File

@@ -3,28 +3,33 @@ comment0.params=title\ itemCode\ cost\ timesBorrowed\ onLoan
comment0.target=LibraryItem(java.lang.String,\ java.lang.String,\ int,\ int,\ boolean)
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryItem\n
comment1.params=
comment1.target=java.lang.String\ getTitle()
comment1.text=\n\ Field\ Accessor\ Start\n
comment10.params=onLoan
comment10.target=void\ setOnLoan(boolean)
comment11.params=
comment11.target=void\ printDetails()
comment11.text=\n\ Field\ Mutator\ End\n
comment1.target=LibraryItem()
comment1.text=\n\ Default\ constructor\ for\ object\ of\ class\ LibraryItem\n
comment10.params=timesBorrowed
comment10.target=void\ setTimesBorrowed(int)
comment11.params=onLoan
comment11.target=void\ setOnLoan(boolean)
comment12.params=
comment12.target=void\ printDetails()
comment12.text=\n\ Field\ Mutator\ End\n
comment13.params=detailScanner
comment13.target=void\ readData(java.util.Scanner)
comment2.params=
comment2.target=java.lang.String\ getItemCode()
comment2.target=java.lang.String\ getTitle()
comment2.text=\n\ Field\ Accessor\ Start\n
comment3.params=
comment3.target=int\ getCost()
comment3.target=java.lang.String\ getItemCode()
comment4.params=
comment4.target=int\ getTimesBorrowed()
comment4.target=int\ getCost()
comment5.params=
comment5.target=boolean\ getOnLoan()
comment6.params=title
comment6.target=void\ setTitle(java.lang.String)
comment6.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n
comment7.params=itemCode
comment7.target=void\ setItemCode(java.lang.String)
comment8.params=cost
comment8.target=void\ setCost(int)
comment9.params=timesBorrowed
comment9.target=void\ setTimesBorrowed(int)
numComments=12
comment5.target=int\ getTimesBorrowed()
comment6.params=
comment6.target=boolean\ getOnLoan()
comment7.params=title
comment7.target=void\ setTitle(java.lang.String)
comment7.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n
comment8.params=itemCode
comment8.target=void\ setItemCode(java.lang.String)
comment9.params=cost
comment9.target=void\ setCost(int)
numComments=14

View File

@@ -5,6 +5,10 @@
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Scanner;
import java.util.ArrayList;
public class LibraryItem
{
// instance variables - replace the example below with your own
@@ -26,6 +30,18 @@ public class LibraryItem
this.onLoan = onLoan;
}
/*
* Default constructor for object of class LibraryItem
*/
public LibraryItem()
{
title = "";
itemCode = "";
cost = 0;
timesBorrowed = 0;
onLoan = false;
}
/*
* Field Accessor Start
*/
@@ -94,10 +110,16 @@ public class LibraryItem
{
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." );
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." );
System.out.println( "This item is at present not on loan and when new cost " + cost + " pence.\n" );
}
public void readData( Scanner detailScanner ) {
this.title = detailScanner.next();
this.itemCode = detailScanner.next();
this.cost = Integer.parseInt( detailScanner.next() );
this.timesBorrowed = Integer.parseInt( detailScanner.next() );
this.onLoan = Boolean.parseBoolean( detailScanner.next() );
}
}

View File

@@ -0,0 +1,12 @@
// this is a comment, any lines that start with //
// (and blank lines) should be ignored
// data is title, itemCode, cost, timesBorrowed, onLoan
Objects First with Java, LM002411,3989,781,true
Compilers: Principles Techniques and Tools, LM002711,599,0,FALSE
C# How to Program, LM002876,4599,45,TRUE
Unix Made Easy: The Basics and Beyond (Made Easy), LM002468,6395,0,TRUE
Galerkin Finite Element Methods for Parabolic Problems, LM002153,4554,0,FALSE

View File

@@ -1,3 +1,41 @@
#BlueJ package file
#Fri Feb 02 12:26:48 GMT 2024
dependency1.from=Library
dependency1.to=LibraryItem
dependency1.type=UsesDependency
objectbench.height=76
objectbench.width=1900
package.editor.height=874
package.editor.width=1774
package.editor.x=0
package.editor.y=31
package.numDependencies=1
package.numTargets=2
package.showExtends=true
package.showUses=true
project.charset=UTF-8
target1.editor.height=1049
target1.editor.width=960
target1.editor.x=0
target1.editor.y=31
target1.height=50
target1.name=LibraryItem
target1.naviview.expanded=true
target1.showInterface=false
target1.type=ClassTarget
target1.typeParameters=
target1.width=100
target1.x=70
target1.y=10
target2.editor.height=1049
target2.editor.width=960
target2.editor.x=960
target2.editor.y=31
target2.height=50
target2.name=Library
target2.naviview.expanded=true
target2.showInterface=false
target2.type=ClassTarget
target2.typeParameters=
target2.width=80
target2.x=170
target2.y=60

View File

@@ -6,11 +6,11 @@ dependency2.from=ZooApp
dependency2.to=Zoo
dependency2.type=UsesDependency
objectbench.height=76
objectbench.width=686
package.editor.height=400
package.editor.width=560
package.editor.x=774
package.editor.y=277
objectbench.width=1900
package.editor.height=874
package.editor.width=1774
package.editor.x=0
package.editor.y=31
package.numDependencies=2
package.numTargets=3
package.showExtends=true