diff --git a/Semester 2/Computer Systems Internals & Linux/Week 4/q1.sh b/Semester 2/Computer Systems Internals & Linux/Week 4/q1.sh new file mode 100644 index 0000000..e69de29 diff --git a/Semester 2/Database Systems/Week 4/Week 4 Database Systems.md b/Semester 2/Database Systems/Week 4/Week 4 Database Systems.md index 6d94e9d..7c80101 100644 --- a/Semester 2/Database Systems/Week 4/Week 4 Database Systems.md +++ b/Semester 2/Database Systems/Week 4/Week 4 Database Systems.md @@ -64,3 +64,68 @@ T1 and T2 conflict as T1's write for X is overwritten by T2's write for X before ( 2 conflicts ) T1 and T2 conflict as T1's write operation is overwritten by T2's write operation before either transaction is complete. ( 3 conflicts ) + +# Workshop + +```sql +create table chap27.car( + carId INT, + carMake VARCHAR(8), + carModel VARCHAR(12), + carPrice INT, + primary key( carId ) +); + +create table chap27.part( + partId INT, + partName VARCHAR(6), + partPrice INT, + primary key( partId ) +); + +create table chap27.carPart( + carId INT, + partId INT, + foreign key (carId) references car(carId), + foreign key (partId) references part(partId) +); + +insert into car values + (1, 'Ford', 'Focus', 18000), + (2, 'Toyota', 'Avensis', 20000), + (3, 'BMW', '640d', 60000), + (4, 'Porsche', 'Boxter 718', 42000); + +insert into part values + (1, 'part1', 54), + (2, 'part2', 664), + (3, 'part3', 224), + (4, 'part4', 11), + (5, 'part5', 187), + (6, 'part6', 22), + (7, 'part7', 998), + (8, 'part8', 115), + (9, 'part9', 23), + (10, 'part10', 55); + +insert into carpart values + (1, 3), + (1, 8), + (1, 5), + (1, 1), + (1, 7), + (2, 3), + (2, 4), + (2, 2), + (2, 8), + (3, 9), + (3, 5), + (3, 3), + (3, 1), + (4, 7), + (4, 9), + (4, 5), + (4, 6), + (4, 4), + (4, 2); +``` diff --git a/Semester 2/Programming 2/Project/Part 1/Library.class b/Semester 2/Programming 2/Project/Part 1/Library.class index ad444ef..5667e4c 100644 Binary files a/Semester 2/Programming 2/Project/Part 1/Library.class and b/Semester 2/Programming 2/Project/Part 1/Library.class differ diff --git a/Semester 2/Programming 2/Project/Part 1/Library.java b/Semester 2/Programming 2/Project/Part 1/Library.java index bd859ce..406baf5 100644 --- a/Semester 2/Programming 2/Project/Part 1/Library.java +++ b/Semester 2/Programming 2/Project/Part 1/Library.java @@ -8,10 +8,8 @@ // 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; @@ -49,32 +47,32 @@ 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() ) - { + try { + Scanner fileScanner = new Scanner( new File( fileBox.getDirectory() + fileBox.getFile() ) ); - String lineItem = fileScanner.nextLine(); - - if ( !lineItem.contains( "//" ) && !lineItem.trim().isEmpty() ) { // Ensure no comments or empty lines are included + while( fileScanner.hasNextLine() ) + { - 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 + 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." ); - } + 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." ); + } } } diff --git a/Semester 2/Programming 2/Project/Part 1/LibraryItem.class b/Semester 2/Programming 2/Project/Part 1/LibraryItem.class index 75a36ec..b2fce12 100644 Binary files a/Semester 2/Programming 2/Project/Part 1/LibraryItem.class and b/Semester 2/Programming 2/Project/Part 1/LibraryItem.class differ diff --git a/Semester 2/Programming 2/Project/Part 1/LibraryItem.java b/Semester 2/Programming 2/Project/Part 1/LibraryItem.java index 924863e..bdcba6f 100644 --- a/Semester 2/Programming 2/Project/Part 1/LibraryItem.java +++ b/Semester 2/Programming 2/Project/Part 1/LibraryItem.java @@ -8,6 +8,7 @@ import java.util.Scanner; import java.util.ArrayList; +import java.util.NoSuchElementException; public class LibraryItem { @@ -116,10 +117,13 @@ public class LibraryItem } 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() ); + + if ( detailScanner != null ) { + this.title = detailScanner.next().trim(); + this.itemCode = detailScanner.next().trim(); + this.cost = Integer.parseInt( detailScanner.next() ); + this.timesBorrowed = Integer.parseInt( detailScanner.next() ); + this.onLoan = Boolean.parseBoolean( detailScanner.next() ); + } } } diff --git a/Semester 2/Programming 2/Project/Part 1/doc/LibraryItem.html b/Semester 2/Programming 2/Project/Part 1/doc/LibraryItem.html new file mode 100644 index 0000000..d762cb0 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 1/doc/LibraryItem.html @@ -0,0 +1,369 @@ + + + +
+ + ++java.lang.Object ++LibraryItem +
public class LibraryItem
+
+Constructor Summary | +|
---|---|
LibraryItem()
+
++ |
+|
LibraryItem(java.lang.String title,
+ java.lang.String itemCode,
+ int cost,
+ int timesBorrowed,
+ boolean onLoan)
+
++ Constructor for objects of class LibraryItem |
+
+Method Summary | +|
---|---|
+ int |
+getCost()
+
++ |
+
+ java.lang.String |
+getItemCode()
+
++ |
+
+ boolean |
+getOnLoan()
+
++ |
+
+ int |
+getTimesBorrowed()
+
++ |
+
+ java.lang.String |
+getTitle()
+
++ |
+
+ void |
+printDetails()
+
++ |
+
+ void |
+readData(java.util.Scanner detailScanner)
+
++ |
+
+ void |
+setCost(int cost)
+
++ |
+
+ void |
+setItemCode(java.lang.String itemCode)
+
++ |
+
+ void |
+setOnLoan(boolean onLoan)
+
++ |
+
+ void |
+setTimesBorrowed(int timesBorrowed)
+
++ |
+
+ void |
+setTitle(java.lang.String title)
+
++ |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public LibraryItem()+
+public LibraryItem(java.lang.String title, + java.lang.String itemCode, + int cost, + int timesBorrowed, + boolean onLoan)+
+
+Method Detail | +
---|
+public int getCost()+
+public java.lang.String getItemCode()+
+public boolean getOnLoan()+
+public int getTimesBorrowed()+
+public java.lang.String getTitle()+
+public void printDetails()+
+public void readData(java.util.Scanner detailScanner)+
+public void setCost(int cost)+
+public void setItemCode(java.lang.String itemCode)+
+public void setOnLoan(boolean onLoan)+
+public void setTimesBorrowed(int timesBorrowed)+
+public void setTitle(java.lang.String title)+
LibraryItem
+ + |
+
LibraryItem
+ + |
+
+Classes
+
+ +LibraryItem |
+
+Class Summary | +|
---|---|
LibraryItem | ++ |
+