diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326 - Assignment 1.pdf b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326 - Assignment 1.pdf new file mode 100644 index 00000000..eced3c33 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326 - Assignment 1.pdf differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/encodings.xml b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/encodings.xml new file mode 100644 index 00000000..aa00ffab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/misc.xml b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/misc.xml new file mode 100644 index 00000000..c3f3b0ab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/uiDesigner.xml b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/Test Results.png b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/Test Results.png new file mode 100644 index 00000000..0a2abde4 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/Test Results.png differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/pom.xml b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/pom.xml new file mode 100644 index 00000000..c55ddb2f --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + org.example + CT326-Assignment01 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/DateInPastException.java b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/DateInPastException.java new file mode 100644 index 00000000..3e692549 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/DateInPastException.java @@ -0,0 +1,6 @@ +// Andrew Hayes, ID: 21321503 +public class DateInPastException extends RuntimeException { + public DateInPastException(String s) { + super(s); + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/NCTBooking.java b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/NCTBooking.java new file mode 100644 index 00000000..e0dd6d9f --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/NCTBooking.java @@ -0,0 +1,62 @@ +// Andrew Hayes, ID: 21321503 +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.concurrent.atomic.AtomicLong; + +public class NCTBooking { + private static final AtomicLong NEXT_ID = new AtomicLong(0); + + private String vehicleRegistrationNumber; + private TestCentre testCentre; + private LocalDateTime datetime; + private final long bookingID = NEXT_ID.getAndIncrement(); + + public NCTBooking(String vehicleRegistrationNumber, TestCentre testCentre, LocalDateTime datetime) throws DateInPastException { + // if datetime is in the future, initialising NCTBooking, otherwise throwing DateInPastException + if (datetime.isAfter(LocalDateTime.now())) { + this.vehicleRegistrationNumber = vehicleRegistrationNumber; + this.testCentre = testCentre; + this.datetime = datetime; + } + else { + throw new DateInPastException("Passed datetime is in the past!"); + } + } + + public NCTBooking(String vehicleRegistrationNumber, TestCentre testCentre) { + this.vehicleRegistrationNumber = vehicleRegistrationNumber; + this.testCentre = testCentre; + } + + public TestCentre getTestCentre() { return testCentre; } + + public String getVehicleRegistrationNumber() { return vehicleRegistrationNumber; } + + public void setVehicleRegistrationNumber(String vehicleRegistrationNumber) { this.vehicleRegistrationNumber = vehicleRegistrationNumber; } + + public long getBookingID() { return bookingID; } + + @Override + public String toString() { + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("EEEE, d MMMM yyyy"); + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + + return "Booking ID Number: " + bookingID + "\n" + + "Registration Number: " + vehicleRegistrationNumber + "\n" + + "Centre: " + testCentre.getName() + "\n" + + "Address: " + testCentre.getAddress() + "\n" + + "Date & Time: On " + datetime.format(dateFormatter) + " at " + datetime.format(timeFormatter); + } + + public void setDatetime(LocalDateTime datetime) throws DateInPastException { + // if datetime is in the future, setting datetime, otherwise throwing exception + if (datetime.isAfter(LocalDateTime.now())) { + this.datetime = datetime; + } + else { + throw new DateInPastException(datetime.toString() + "is in the past!"); + } + } + + public LocalDateTime getDatetime() { return datetime; } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/NCTBookingSlotWebservice.java b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/NCTBookingSlotWebservice.java new file mode 100644 index 00000000..3cdf993b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/NCTBookingSlotWebservice.java @@ -0,0 +1,6 @@ +// Andrew Hayes, ID: 21321503 +import java.time.LocalDateTime; + +public interface NCTBookingSlotWebservice { + public LocalDateTime getBookingDateTime(TestCentre testCentre); +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/TestCentre.java b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/TestCentre.java new file mode 100644 index 00000000..1d623170 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/main/java/TestCentre.java @@ -0,0 +1,13 @@ +// Andrew Hayes, ID: 21321503 +public class TestCentre { + private String name; + private String address; + + public TestCentre(String name, String address) { + this.name = name; + this.address = address; + } + + public String getName() { return name; } + public String getAddress() { return address; } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/test/java/NCTBookingTest.java b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/test/java/NCTBookingTest.java new file mode 100644 index 00000000..6079b7f9 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/test/java/NCTBookingTest.java @@ -0,0 +1,165 @@ +// Andrew Hayes, ID: 21321503 +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.*; +import java.time.LocalDateTime; + +class NCTBookingTest { + // tests ability to instantiate an NCTBooking + @Test + void testCreateNCTBooking() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking("221-RN-1234", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0)); + assertNotNull(booking); + } + + // tests ability to query the test centre of a booking + @Test + void testGetTestCentre() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking("221-RN-1234", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0)); + + // value returned by getTestCentre() should be the value set when the booking was created + assertEquals(testCentre, booking.getTestCentre()); + } + + // tests ability to query the vehicle registration for a booking + @Test + void testGetVehicleRegistrationNumber() { + String vehicleRegistrationNumber = "221-RN-1234"; + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking(vehicleRegistrationNumber, testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0)); + + // value returned by getVehicleRegistrationNumber() should be the value that was set when the booking was created (in this case) + assertEquals(vehicleRegistrationNumber, booking.getVehicleRegistrationNumber()); + } + + // tests ability to edit the vehicle registration number of a booking + @Test + void testSetVehicleRegistrationNumber() { + String vehicleRegistrationNumber = "221-RN-1234"; + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking(vehicleRegistrationNumber, testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0)); + + // changing the value of vehicleRegistrationNumber and testing that the value returned by getVehicleRegistrationNumber is equal to the updated value + String newVehicleRegistrationNumber = "00-D-4321"; + booking.setVehicleRegistrationNumber(newVehicleRegistrationNumber); + + // value returned by getVehicleRegistrationNumber() should be the value that was set in the last edit + assertEquals(newVehicleRegistrationNumber, booking.getVehicleRegistrationNumber()); + } + + // tests ability to instantiate an NCTBooking without specifying a date + @Test + void testCreateNCTBookingWithoutDate() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking("221-RN-123", testCentre); + assertNotNull(booking); + } + + // tests ability to query the date and time of a booking + @Test + void testGetDatetime() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + LocalDateTime datetime = LocalDateTime.of(2024, 1, 1, 9, 0, 0); + NCTBooking booking = new NCTBooking("221-RN-1234", testCentre, datetime); + + // queried datetime should be equal to the datetime set on initialisation + assertEquals(datetime, booking.getDatetime()); + } + + // tests ability to set the date and time of a booking via an external API + @Test + void testSetDatetime() { + // stub implementation of the NCTBookingSlotWebservice for testing purposes + NCTBookingSlotWebservice testService = new NCTBookingSlotWebservice() { + @Override + public LocalDateTime getBookingDateTime(TestCentre testCentre) { + return LocalDateTime.of(2024, 1, 1, 9, 0, 0); + } + }; + + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking("221-RN-123", testCentre); + LocalDateTime datetime = testService.getBookingDateTime(testCentre); + booking.setDatetime(datetime); + + assertEquals(datetime, booking.getDatetime()); + } + + // tests that bookings with a date and time in the past throw a user-defined exception + @Test + void testCreateNCTBookingWithDataInThePast() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + assertThrows( + DateInPastException.class, + () -> new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(1970, 1, 1, 9, 0, 0)) + ); + } + + // tests that attempting to set the datetime of a booking to a time in the past throws a user-defined exception + @Test + void testSetDatetimeInPast() { + // stub implementation of the NCTBookingSlotWebservice for testing purposes + NCTBookingSlotWebservice testService = new NCTBookingSlotWebservice() { + @Override + public LocalDateTime getBookingDateTime(TestCentre testCentre) { + return LocalDateTime.of(1970, 1, 1, 9, 0, 0); + } + }; + + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking("221-RN-123", testCentre); + LocalDateTime datetime = testService.getBookingDateTime(testCentre); + + assertThrows( + DateInPastException.class, + () -> booking.setDatetime(datetime) + ); + + } + + // tests that bookings have a unique booking ID number generated when they're created + @Test + void testUniqueIDGenerated() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0)); + assertNotNull(booking.getBookingID()); + } + + // attempts to test if booking IDs are not unique by comparing 10,000 of them (note that this does not prove uniqueness, just will disprove it in certain situations) + @Test + void testBookingIDsUnique() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + + NCTBooking[] bookings = new NCTBooking[10_000]; + for (int i = 0; i < 10_000; i ++) { + bookings[i] = new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0)); + } + + // looping over the bookings and comparing each one to every other one + for (int i = 0; i < 10_000; i ++) { + for (int j = 0; j < 10_000; j ++) { + if (i != j) { + assertNotEquals(bookings[i].getBookingID(), bookings[j].getBookingID()); + } + } + } + } + + // tests that output from toString() method matches a regex for the expected output + @Test + void testToString() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + NCTBooking booking = new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0)); + + // the only "regular-expressiony" part of the below regex is "[0-9]+" which just matches one or more decimal digits + assertTrue(booking.toString().matches( + """ + Booking ID Number: [0-9]+ + Registration Number: 221-RN-123 + Centre: Test Centre 1 + Address: 10 Downing Street + Date & Time: On Monday, 1 January 2024 at 09:00""" + )); + } +} \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/test/java/TestCentreTest.java b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/test/java/TestCentreTest.java new file mode 100644 index 00000000..ee3a7766 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment1/CT326-Assignment01/src/test/java/TestCentreTest.java @@ -0,0 +1,27 @@ +// Andrew Hayes, ID: 21321503 +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.*; +import java.time.LocalDateTime; + +class TestCentreTest { + // tests ability to instantiate a TestCentre + @Test + void testCreateTestCentre() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + assertNotNull(testCentre); + } + + // tests the getter for "name" in TestCentre class + @Test + void testGetName() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + assertEquals("Test Centre 1", testCentre.getName()); + } + + // tests the getter for "address" in TestCentre class + @Test + void testGetAddress() { + TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street"); + assertEquals("10 Downing Street", testCentre.getAddress()); + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment1/assignment1_Andrew_Hayes.zip b/third/semester1/CT326_Programming_III/assignments/assignment1/assignment1_Andrew_Hayes.zip new file mode 100644 index 00000000..4f1ebfca Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment1/assignment1_Andrew_Hayes.zip differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/CT326 - Assignment 2.pdf b/third/semester1/CT326_Programming_III/assignments/assignment2/CT326 - Assignment 2.pdf new file mode 100644 index 00000000..aa2b76b9 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment2/CT326 - Assignment 2.pdf differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/.name b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/.name new file mode 100644 index 00000000..cadd1315 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/.name @@ -0,0 +1 @@ +assignment2 \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/encodings.xml b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/encodings.xml new file mode 100644 index 00000000..aa00ffab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/misc.xml b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/misc.xml new file mode 100644 index 00000000..c3f3b0ab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/Console Output.png b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/Console Output.png new file mode 100644 index 00000000..12c5e48b Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/Console Output.png differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/lib/joda-money-1.0.3.jar b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/lib/joda-money-1.0.3.jar new file mode 100644 index 00000000..23941144 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/lib/joda-money-1.0.3.jar differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/pom.xml b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/pom.xml new file mode 100644 index 00000000..75055300 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + assignment2 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/Expense.java b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/Expense.java new file mode 100644 index 00000000..2fdede9c --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/Expense.java @@ -0,0 +1,138 @@ +// Name: Andrew Hayes +// ID Number: 21321503 +import java.time.LocalDate; + +import org.joda.money.CurrencyUnit; +import org.joda.money.Money; + +public class Expense { + private LocalDate date; + private String description; + private ExpenseCategory category; + private Money amount; + private boolean approved; // defaults to false + + /** + * constructor that does not take the boolean "approved" - this should be set later + * @param date + * @param description + * @param category + * @param amount + */ + public Expense(LocalDate date, String description, ExpenseCategory category, Money amount) { + this.date = date; + this.description = description; + this.category = category; + this.amount = amount; + } + + /** + * constructor that takes the boolean "approved" in case you want to override it defaulting to false + * @param date + * @param description + * @param category + * @param amount + * @param approved + */ + public Expense(LocalDate date, String description, ExpenseCategory category, Money amount, boolean approved) { + this.date = date; + this.description = description; + this.category = category; + this.amount = amount; + this.approved = approved; + } + + /** + * + * @return date + */ + public LocalDate getDate() { + return date; + } + + /** + * + * @param date + */ + public void setDate(LocalDate date) { + this.date = date; + } + + /** + * + * @return description + */ + public String getDescription() { + return description; + } + + /** + * + * @param description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * + * @return category + */ + public ExpenseCategory getCategory() { + return category; + } + + /** + * + * @param category + */ + public void setCategory(ExpenseCategory category) { + this.category = category; + } + + /** + * + * @return amount + */ + public Money getAmount() { + return amount; + } + + /** + * + * @param amount + */ + public void setAmount(Money amount) { + this.amount = amount; + } + + + /** + * method to return the currency unit of the amount + * @return the CurrencyUnit of the amount + */ + public CurrencyUnit getAmountCurrency() { return amount.getCurrencyUnit(); } + + /** + * + * @return isApproved + */ + public boolean isApproved() { + return approved; + } + + /** + * + * @param approved + */ + public void setApproved(boolean approved) { + this.approved = approved; + } + + @Override + public String toString() { + return String.format( + "%s: %s - %s - %s %.2f", date.toString(), description, category, amount.getCurrencyUnit(), amount.getAmount().doubleValue() + ); + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpenseCategory.java b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpenseCategory.java new file mode 100644 index 00000000..eb1674e0 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpenseCategory.java @@ -0,0 +1,9 @@ +// Name: Andrew Hayes +// ID Number: 21321503 +public enum ExpenseCategory { + TRAVEL_AND_SUBSISTENCE, + SUPPLIES, + ENTERTAINMENT, + EQUIPMENT, + OTHER +} \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpensePrinter.java b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpensePrinter.java new file mode 100644 index 00000000..1d4a7adf --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpensePrinter.java @@ -0,0 +1,12 @@ +// Name: Andrew Hayes +// ID Number: 21321503 +import java.util.ArrayList; + +public interface ExpensePrinter { + + /** + * method to print the expenses + * @param expenses + */ + public void print(ArrayList expenses); +} \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpensesPortal.java b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpensesPortal.java new file mode 100644 index 00000000..e3bdf5e6 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/ExpensesPortal.java @@ -0,0 +1,99 @@ +// Name: Andrew Hayes +// ID Number: 21321503 +import org.joda.money.CurrencyUnit; +import org.joda.money.IllegalCurrencyException; +import org.joda.money.Money; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.util.ArrayList; + +public class ExpensesPortal { + private ArrayList expenses = new ArrayList(); + + /** + * main method + * @param args + */ + public static void main(String[] args) { + ExpensesPortal ep = new ExpensesPortal(); + + // create sample expenses + ep.addExpense(new Expense(LocalDate.of(2022, 9, 23), "FLight to Glasgow", ExpenseCategory.TRAVEL_AND_SUBSISTENCE, Money.parse("EUR 270.59"))); + ep.addExpense(new Expense(LocalDate.of(2022, 9, 23), "FLight to Dublin", ExpenseCategory.TRAVEL_AND_SUBSISTENCE, Money.parse("EUR 271.59"))); + ep.addExpense(new Expense(LocalDate.of(2022, 9, 20), "Dell 17-inch monitor", ExpenseCategory.EQUIPMENT, Money.parse("USD 540.00"))); + ep.addExpense(new Expense(LocalDate.of(2022, 9, 20), "Logitech Mouse", ExpenseCategory.EQUIPMENT, Money.parse("USD 40.00"))); + ep.addExpense(new Expense(LocalDate.of(2022, 9, 21), "Java for Dummies", ExpenseCategory.OTHER, Money.parse("EUR 17.99"))); + ep.addExpense(new Expense(LocalDate.of(2022, 9, 21), "Dinner", ExpenseCategory.OTHER, Money.parse("EUR 20.99"))); + ep.addExpense(new Expense(LocalDate.of(2022, 9, 21), "Whiteboard Marker", ExpenseCategory.SUPPLIES, Money.parse("EUR 4.99"))); + + // call the printExpenses method using a lambda expression to implement the ExpensePrinter parameter + ep.printExpenses(expenses -> { + for (Expense expense : expenses) { + System.out.println(expense); + } + }); + System.out.printf("%n"); + + // call the printExpenses method using an anonymous inner class to implement the ExpensePrinter parameter + ep.printExpenses(new ExpensePrinter() { + /** + * method to print a summary of the expenses + * @param expenses + */ + @Override + public void print(ArrayList expenses) { + System.out.println("There are " + expenses.toArray().length + " expenses in the system totalling to a value of " + sumExpenses(expenses)); + } + }); + System.out.printf("%n"); + + // call the printExpense method using a PrinterByLabel instance as a parameter + ep.printExpenses(new PrinterByLabel()); + } + + /** + * method to submit a new expense + * @param expense + */ + public void addExpense(Expense expense) { + expenses.add(expense); + } + + /** + * method to print expenses + * @param printer + */ + public void printExpenses(ExpensePrinter printer) { + printer.print(expenses); + } + + + /** + * method for summing the expenses that supports both EUR & USD + * @param expenses + * @return + * @throws IllegalCurrencyException + */ + public static Money sumExpenses(ArrayList expenses) throws IllegalCurrencyException { + Money total = Money.parse("EUR 0"); + BigDecimal USDToEURConversionRate = BigDecimal.valueOf(0.95); // hardcoded conversion rate as of 2023-10-04 - clearly not ideal, but as a proof of concept + + for (Expense expense : expenses) { + // if currency is usd, converting to euro and adding to total + if (expense.getAmountCurrency().equals(CurrencyUnit.of("USD"))) { + total = total.plus(expense.getAmount().convertedTo(CurrencyUnit.EUR, USDToEURConversionRate, RoundingMode.HALF_UP)); + } + // checking that the currency is of type euro before adding to total + else if (expense.getAmountCurrency().equals(CurrencyUnit.of("EUR"))) { + total = total.plus(expense.getAmount()); + } + else { + throw new IllegalCurrencyException("CurrencyUnity " + expense.getAmountCurrency() + " is not supported! USD or EUR only"); + } + } + + return total; + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/PrinterByLabel.java b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/PrinterByLabel.java new file mode 100644 index 00000000..56ecf7ff --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2/src/main/java/PrinterByLabel.java @@ -0,0 +1,48 @@ +// Name: Andrew Hayes +// ID Number: 21321503 +import java.util.ArrayList; +//import java.util.Collections; // for use in commented out algorithm -- see below +//import java.util.Comparator; + +public class PrinterByLabel implements ExpensePrinter { + /** + * method to print all the expenses, grouped by category + * @param expenses + */ + @Override + public void print(ArrayList expenses) { + ExpenseCategory[] categories = ExpenseCategory.values(); + + for (ExpenseCategory category : categories) { + System.out.println(category + ":"); + + for (Expense expense : expenses) { + // printing out expense only if it's in the current category + if (expense.getCategory().equals(category)) { + System.out.println(expense); + } + } + System.out.printf("%n"); + } + + // below is a commented-out alternative to the above algorithm that doesn't match the output in the design spec + // it doesn't print out every expense category as a title, just the ones that have an existing expense in the system + // this allows the sorting to be done nicely using the enum, and allows the enum to be expanded or contracted without changing other code + // this allows for slightly nicer sorting and does not print out categories which do not have extant expenses in them, which may or may not be desirable + +// // sorting the ArrayList by category +// Collections.sort(expenses, Comparator.comparing(Expense::getCategory)); +// +// // variable to keep track of what category the last printed expense was so that a heading can be printed once and only once for each category +// ExpenseCategory lastCategory = null; +// +// for (Expense expense : expenses) { +// // if the current expense's category is different to the last, print it out as a heading +// if (expense.getCategory() != lastCategory) { +// System.out.println(expense.getCategory()); +// lastCategory = expense.getCategory(); +// } +// System.out.println(expense); +// } + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2_Andrew_Hayes.zip b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2_Andrew_Hayes.zip new file mode 100644 index 00000000..7d8fc4a6 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment2/assignment2_Andrew_Hayes.zip differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326 - Assignment 3.pdf b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326 - Assignment 3.pdf new file mode 100644 index 00000000..3809d008 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326 - Assignment 3.pdf differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/encodings.xml b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/encodings.xml new file mode 100644 index 00000000..aa00ffab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/misc.xml b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/misc.xml new file mode 100644 index 00000000..82dbec8a --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/uiDesigner.xml b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/players.ser b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/players.ser new file mode 100644 index 00000000..c9de9bab Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/players.ser differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/pom.xml b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/pom.xml new file mode 100644 index 00000000..fc95f9db --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + org.example + CT326-Assignment3 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.junit.jupiter + junit-jupiter + 5.10.0 + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Achievement.java b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Achievement.java new file mode 100644 index 00000000..98944216 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Achievement.java @@ -0,0 +1,81 @@ +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.time.LocalDate; + +/** + * class representing a player's achievement + */ +public class Achievement { + private String achievementName; + private String description; + private LocalDate dateOfAward; + + /** + * constructor for the Achievement class + * @param achievementName a String representation of the name of the Achievement + * @param description a String describing the Achievement + * @param dateOfAward a LocalDate representing the date that the Achievement was awarded + */ + public Achievement(String achievementName, String description, LocalDate dateOfAward) { + this.achievementName = achievementName; + this.description = description; + this.dateOfAward = dateOfAward; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Achievement) { + Achievement toCompare = (Achievement) obj; + + if (!achievementName.equals(toCompare.achievementName)) { + return false; + } + if (!description.equals(toCompare.description)) { + return false; + } + if (!dateOfAward.equals(toCompare.dateOfAward)) { + return false; + } + + return true; + } + else { return false; } + } + + /** + * getter method for the achievementName field + * @return a String representation of the name of the Achievement + */ + public String getAchievementName() { return achievementName; } + + /** + * setter method for the achievementName field + * @param achievementName a String representation of the name of the Achievement + */ + public void setAchievementName(String achievementName) { this.achievementName = achievementName; } + + /** + * getter method for the description field + * @return a String describing the Achievement + */ + public String getDescription() { return description; } + + /** + * setter method for the description field + * @param description a String describing the Achievement + */ + public void setDescription(String description) { this.description = description; } + + /** + * getter method for the dateOfAward field + * @return a LocalDate representing the date that the Achievement was awarded + */ + public LocalDate getDateOfAward() { return dateOfAward; } + + /** + * setter method for the dateOfAward field + * @param dateOfAward a LocalDate representing the date that the Achievement was awarded + */ + public void setDateOfAward(LocalDate dateOfAward) { this.dateOfAward = dateOfAward; } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Country.java b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Country.java new file mode 100644 index 00000000..3660b127 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Country.java @@ -0,0 +1,260 @@ +/** + * enum for each ISO 3166 Alpha-2 country Code + */ +public enum Country { + // Explanation of how this data was sourced: + // the following ISO 3166 Alpha-2 Codes were taken from the CSV file found here: https://pkgstore.datahub.io/core/country-list/data_csv/data/d7c9d7cfb42cb69f4422dec222dbbaa8/data_csv.csv + // the CSV file was cleaned to have UNIX line endings (as it had Windows line endings, and I am on GNU/Linux) with the command `tr -d '\r' < data_csv.csv > clean_data.csv ` + // they were then parsed & read into this Java source file with the Vim / GNU AWK command `:read !awk -F',' '{gsub(/\"/, ""); print $NF ",\t// " $1}' clean_data.csv` + // finally, the block was indented in Vim and a `;` appended to the last value + + AF, // Afghanistan + AX, // Åland Islands + AL, // Albania + DZ, // Algeria + AS, // American Samoa + AD, // Andorra + AO, // Angola + AI, // Anguilla + AQ, // Antarctica + AG, // Antigua and Barbuda + AR, // Argentina + AM, // Armenia + AW, // Aruba + AU, // Australia + AT, // Austria + AZ, // Azerbaijan + BS, // Bahamas + BH, // Bahrain + BD, // Bangladesh + BB, // Barbados + BY, // Belarus + BE, // Belgium + BZ, // Belize + BJ, // Benin + BM, // Bermuda + BT, // Bhutan + BO, // Bolivia + BQ, // Bonaire + BA, // Bosnia and Herzegovina + BW, // Botswana + BV, // Bouvet Island + BR, // Brazil + IO, // British Indian Ocean Territory + BN, // Brunei Darussalam + BG, // Bulgaria + BF, // Burkina Faso + BI, // Burundi + KH, // Cambodia + CM, // Cameroon + CA, // Canada + CV, // Cape Verde + KY, // Cayman Islands + CF, // Central African Republic + TD, // Chad + CL, // Chile + CN, // China + CX, // Christmas Island + CC, // Cocos (Keeling) Islands + CO, // Colombia + KM, // Comoros + CG, // Congo + CD, // Congo + CK, // Cook Islands + CR, // Costa Rica + CI, // Côte d'Ivoire + HR, // Croatia + CU, // Cuba + CW, // Curaçao + CY, // Cyprus + CZ, // Czech Republic + DK, // Denmark + DJ, // Djibouti + DM, // Dominica + DO, // Dominican Republic + EC, // Ecuador + EG, // Egypt + SV, // El Salvador + GQ, // Equatorial Guinea + ER, // Eritrea + EE, // Estonia + ET, // Ethiopia + FK, // Falkland Islands (Malvinas) + FO, // Faroe Islands + FJ, // Fiji + FI, // Finland + FR, // France + GF, // French Guiana + PF, // French Polynesia + TF, // French Southern Territories + GA, // Gabon + GM, // Gambia + GE, // Georgia + DE, // Germany + GH, // Ghana + GI, // Gibraltar + GR, // Greece + GL, // Greenland + GD, // Grenada + GP, // Guadeloupe + GU, // Guam + GT, // Guatemala + GG, // Guernsey + GN, // Guinea + GW, // Guinea-Bissau + GY, // Guyana + HT, // Haiti + HM, // Heard Island and McDonald Islands + VA, // Holy See (Vatican City State) + HN, // Honduras + HK, // Hong Kong + HU, // Hungary + IS, // Iceland + IN, // India + ID, // Indonesia + IR, // Iran + IQ, // Iraq + IE, // Ireland + IM, // Isle of Man + IL, // Israel + IT, // Italy + JM, // Jamaica + JP, // Japan + JE, // Jersey + JO, // Jordan + KZ, // Kazakhstan + KE, // Kenya + KI, // Kiribati + KP, // Korea + KR, // Korea + KW, // Kuwait + KG, // Kyrgyzstan + LA, // Lao People's Democratic Republic + LV, // Latvia + LB, // Lebanon + LS, // Lesotho + LR, // Liberia + LY, // Libya + LI, // Liechtenstein + LT, // Lithuania + LU, // Luxembourg + MO, // Macao + MK, // Macedonia + MG, // Madagascar + MW, // Malawi + MY, // Malaysia + MV, // Maldives + ML, // Mali + MT, // Malta + MH, // Marshall Islands + MQ, // Martinique + MR, // Mauritania + MU, // Mauritius + YT, // Mayotte + MX, // Mexico + FM, // Micronesia + MD, // Moldova + MC, // Monaco + MN, // Mongolia + ME, // Montenegro + MS, // Montserrat + MA, // Morocco + MZ, // Mozambique + MM, // Myanmar + NA, // Namibia + NR, // Nauru + NP, // Nepal + NL, // Netherlands + NC, // New Caledonia + NZ, // New Zealand + NI, // Nicaragua + NE, // Niger + NG, // Nigeria + NU, // Niue + NF, // Norfolk Island + MP, // Northern Mariana Islands + NO, // Norway + OM, // Oman + PK, // Pakistan + PW, // Palau + PS, // Palestine + PA, // Panama + PG, // Papua New Guinea + PY, // Paraguay + PE, // Peru + PH, // Philippines + PN, // Pitcairn + PL, // Poland + PT, // Portugal + PR, // Puerto Rico + QA, // Qatar + RE, // Réunion + RO, // Romania + RU, // Russian Federation + RW, // Rwanda + BL, // Saint Barthélemy + SH, // Saint Helena + KN, // Saint Kitts and Nevis + LC, // Saint Lucia + MF, // Saint Martin (French part) + PM, // Saint Pierre and Miquelon + VC, // Saint Vincent and the Grenadines + WS, // Samoa + SM, // San Marino + ST, // Sao Tome and Principe + SA, // Saudi Arabia + SN, // Senegal + RS, // Serbia + SC, // Seychelles + SL, // Sierra Leone + SG, // Singapore + SX, // Sint Maarten (Dutch part) + SK, // Slovakia + SI, // Slovenia + SB, // Solomon Islands + SO, // Somalia + ZA, // South Africa + GS, // South Georgia and the South Sandwich Islands + SS, // South Sudan + ES, // Spain + LK, // Sri Lanka + SD, // Sudan + SR, // Suriname + SJ, // Svalbard and Jan Mayen + SZ, // Swaziland + SE, // Sweden + CH, // Switzerland + SY, // Syrian Arab Republic + TW, // Taiwan + TJ, // Tajikistan + TZ, // Tanzania + TH, // Thailand + TL, // Timor-Leste + TG, // Togo + TK, // Tokelau + TO, // Tonga + TT, // Trinidad and Tobago + TN, // Tunisia + TR, // Turkey + TM, // Turkmenistan + TC, // Turks and Caicos Islands + TV, // Tuvalu + UG, // Uganda + UA, // Ukraine + AE, // United Arab Emirates + GB, // United Kingdom + US, // United States + UM, // United States Minor Outlying Islands + UY, // Uruguay + UZ, // Uzbekistan + VU, // Vanuatu + VE, // Venezuela + VN, // Viet Nam + VG, // Virgin Islands + VI, // Virgin Islands + WF, // Wallis and Futuna + EH, // Western Sahara + YE, // Yemen + ZM, // Zambia + ZW; // Zimbabwe +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Player.java b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Player.java new file mode 100644 index 00000000..e734d5ca --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/main/java/Player.java @@ -0,0 +1,184 @@ +import java.io.*; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * class to represent a player + */ +public class Player implements Serializable { + private String id; + private String username; + private Country country; + private LocalDate joinDate; + private List achievements; + private static final String serializeAchievementsTo = "achievements.csv"; + + /** + * constructor for the Player class + * @param id a String representing the player's ID + * @param username a String representing the player's username + * @param country a Country object representing the country to which the player belongs + * @param joinDate a LocalDate object representing the date that the player joined the team + * @param achievements a List of Achievement objects awarded to the player + */ + public Player(String id, String username, Country country, LocalDate joinDate, List achievements) { + this.id = id; + this.username = username; + this.country = country; + this.joinDate = joinDate; + this.achievements = achievements; + } + + /** + * overridden method to compare two objects for equality + * @param obj the object to be compared + * @return boolean - true if the objects have all the same fields equals, false otherwise + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof Player) { + Player toCompare = (Player) obj; + + if (!id.equals(toCompare.id)) { + return false; + } + if (!username.equals(toCompare.username)) { + return false; + } + if (!country.equals(toCompare.country)) { + return false; + } + if (!joinDate.equals(toCompare.joinDate)) { + return false; + } + if (!achievements.equals(toCompare.achievements)) { + return false; + } // note that if the lists are in different orders, this will return false + + return true; + } + else { return false; } + } + + /** + * method to deserialize the Player object and to read in its achievements from a CSV file + * @param out ObjectOutputStream + * @throws IOException + */ + @Serial + private void writeObject(ObjectOutputStream out) throws IOException { + // would be inappropriate to catch IOExceptions here - should be caught in the code attempting to serialize the object + out.writeObject(id); + out.writeObject(username); + out.writeObject(country); + out.writeObject(joinDate); + + // deliberate design choice here to not use the writeObject method of the Achievement class + // serializing Achievements in the context of a Player's list of Achievements should be treated differently to serializing, say, a single, isolated Achievement + // there may be times when we want to serialize an Achievement without reference to a Player, without a CSV file + + // writing out Achievements to CSV file + FileWriter writer = new FileWriter(serializeAchievementsTo, true); // append set to true + for (Achievement achievement : achievements) { + writer.write(id + "," + achievement.getAchievementName() + "," + achievement.getDescription() + "," + achievement.getDateOfAward().toString() + "\n"); + } + writer.close(); + } + + /** + * method to serialize the Player object and to write out its achievements to a CSV file + * @param in ObjectInputStream + * @throws IOException + * @throws ClassNotFoundException + */ + @Serial + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + // would be inappropriate to catch exceptions here - should be caught in the code attempting to de-serialize the object + id = (String) in.readObject(); + username = (String) in.readObject(); + country = (Country) in.readObject(); + joinDate = (LocalDate) in.readObject(); + + achievements = new ArrayList<>(); + + FileReader fileReader = new FileReader(serializeAchievementsTo); + BufferedReader bufferedReader = new BufferedReader(fileReader); + + String line; + while ((line = bufferedReader.readLine()) != null) { + String[] cols = line.split(","); + + // only adding to list of achievements if the player ids match + if (cols[0].equals(id)) { + achievements.add(new Achievement(cols[1], cols[2], LocalDate.parse(cols[3], DateTimeFormatter.ofPattern("yyyy-MM-dd")))); + } + } + bufferedReader.close(); + + } + + + /** + * getter method for the ID field + * @return a String representing the player's ID + */ + public String getId() { return id; } + + /** + * setter method for the id field + * @param id String representing the player's ID + */ + public void setId(String id) { this.id = id; } + + + /** + * getter method for the username field + * @return a String representing the player's username + */ + public String getUsername() { return username; } + + /** + * setter method for the username field + * @param username String representing the player's username + */ + public void setUsername(String username) { this.username = username; } + + /** + * getter method for the country field + * @return a Country object + */ + public Country getCountry() { return country; } + + /** + * setter method for the country field + * @param country a Country object + */ + public void setCountry(Country country) { this.country = country; } + + /** + * getter method for the joinDate field + * @return a LocalDate representing the date when the player joined the team + */ + public LocalDate getJoinDate() { return joinDate; } + + /** + * setter method for the joinDate field + * @param joinDate LocalDate representing the date when the player joined the team + */ + public void setJoinDate(LocalDate joinDate) { this.joinDate = joinDate; } + + /** + * getter method for the achievements field + * @return a list of Achievement objects + */ + public List getAchievements() { return achievements; } + + /** + * setter method for the achievements field + * @param achievements a list of Achievement objects + */ + public void setAchievements(List achievements) { this.achievements = achievements; } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/test/java/TestSerialization.java b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/test/java/TestSerialization.java new file mode 100644 index 00000000..86d446a5 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/CT326-Assignment3/src/test/java/TestSerialization.java @@ -0,0 +1,155 @@ +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.*; +import java.io.*; +import java.time.LocalDate; +import java.util.ArrayList; + +/** + * JUnit tests to test the serialization ability of the Player class + */ +public class TestSerialization { + // assuming that the instruction "Use a test-driven development approach to implement the serialization of Player objects" only applies to the serialization, and not the other functionality + + /** + * method that runs after each test and deletes the achievements.csv and players.ser files + */ + @AfterEach + void deleteFiles() { + File achievementsFile = new File("achievements.csv"); + achievementsFile.delete(); + + File playersFile = new File("player.ser"); + playersFile.delete(); + } + + + /** + * test that creates 5 player objects, serializes them, and compares them to the deserialized objects + * @throws IOException + * @throws ClassNotFoundException + */ + @Test + void serializeFivePlayers() throws IOException, ClassNotFoundException { + // deliberately not catching potential IOExceptions - we want the tests to fail if these are thrown + FileOutputStream players_file = new FileOutputStream("players.ser"); + ObjectOutputStream players_out = new ObjectOutputStream(players_file); + ObjectInputStream players_in = new ObjectInputStream(new FileInputStream("players.ser")); + + ArrayList players = new ArrayList<>(); // array of players to be serialized + + // creating some unique players + // player 0 + players.add(new Player("0", "player0", Country.IE, LocalDate.now(), + new ArrayList<>() {{ + add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); + }} + )); + + // player 1 + players.add(new Player("1", "player1", Country.JP, LocalDate.now(), + new ArrayList<>() {{ + add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); + add(new Achievement("Another Award", "An award for something else", LocalDate.of(1996, 7, 6))); + }} + )); + + // player 2 + players.add(new Player("2", "player2", Country.UA, LocalDate.now(), + new ArrayList<>() {{ + add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); + add(new Achievement("Another Award", "An award for something else", LocalDate.of(1996, 7, 6))); + add(new Achievement("Yet Another Award", "An award for something else entirely", LocalDate.of(2023, 8, 6))); + }} + )); + + // player 3 + players.add(new Player("3", "player3", Country.AD, LocalDate.now(), + new ArrayList<>() {{ + add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); + add(new Achievement("Another Award", "An award for something else", LocalDate.of(1996, 7, 6))); + add(new Achievement("Yet Another Award", "An award for something else entirely", LocalDate.of(2023, 8, 6))); + add(new Achievement("A fourth award", "An award that comes after three previous awards", LocalDate.of(2022, 8, 3))); + }} + )); + + // player 4 + players.add(new Player("4", "player4", Country.DE, LocalDate.now(), + new ArrayList<>() {{ + add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); + add(new Achievement("Another Award", "An award for something else", LocalDate.of(1996, 7, 6))); + add(new Achievement("Yet Another Award", "An award for something else entirely", LocalDate.of(2023, 8, 6))); + add(new Achievement("A fourth award", "An award that comes after three previous awards", LocalDate.of(2022, 8, 3))); + add(new Achievement("The final award", "The last award anyone will ever get", LocalDate.of(2030, 12, 25))); + }} + )); + + for (Player player : players) { + players_out.writeObject(player); + } + + // looping over each player and comparing it to the de-serialized player + // doing this in a separate loop to separate writing and reading + for (Player player : players) { + // deliberately not catching exceptions here - we want the test to fail if exceptions are thrown + Player dplayer = (Player) players_in.readObject(); + assertEquals(player, dplayer); + } + + players_out.close(); + players_file.close(); + } + + /** + * test the equals() method of the Player class + */ + @Test + void testPlayerDotEquals() { + // creating two identical players + Player player1 = new Player("0", "player0", Country.IE, LocalDate.now(), + new ArrayList<>(){{ add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); }} + ); + Player player2 = new Player("0", "player0", Country.IE, LocalDate.now(), + new ArrayList<>(){{ add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); }} + ); + + // assertEquals uses the objects equals() method, so it suffices for this test + assertEquals(player1, player2); + } + + /** + * test the equals() method of the Achievement class + */ + @Test + void testAchievementDotEquals() { + Achievement achievement1 = new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6)); + Achievement achievement2 = new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6)); + + assertEquals(achievement1, achievement2); + } + + /** + * test serializing & de-serializing just one player + * @throws IOException + * @throws ClassNotFoundException + */ + @Test + void testSerializePlayer() throws IOException, ClassNotFoundException { + // deliberately not catching potential IOExceptions - we want the tests to fail if these are thrown + FileOutputStream players_file = new FileOutputStream("players.ser"); + ObjectOutputStream players_out = new ObjectOutputStream(players_file); + ObjectInputStream players_in = new ObjectInputStream(new FileInputStream("players.ser")); + + Player player = new Player("0", "player0", Country.IE, LocalDate.now(), + new ArrayList<>(){{ add(new Achievement("Something Award", "An award for something that was especially something", LocalDate.of(2004, 7, 6))); }} + ); + + // serializing player object, de-serializing it, and comparing them + players_out.writeObject(player); + Player dplayer = (Player) players_in.readObject(); + players_out.close(); + players_file.close(); + + assertEquals(player, dplayer); + } +} + diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/assignment3_Andrew_Hayes.zip b/third/semester1/CT326_Programming_III/assignments/assignment3/assignment3_Andrew_Hayes.zip new file mode 100644 index 00000000..e40d79fb Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment3/assignment3_Andrew_Hayes.zip differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/clean_data.csv b/third/semester1/CT326_Programming_III/assignments/assignment3/clean_data.csv new file mode 100644 index 00000000..47881c60 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/clean_data.csv @@ -0,0 +1,250 @@ +Name,Code +Afghanistan,AF +Åland Islands,AX +Albania,AL +Algeria,DZ +American Samoa,AS +Andorra,AD +Angola,AO +Anguilla,AI +Antarctica,AQ +Antigua and Barbuda,AG +Argentina,AR +Armenia,AM +Aruba,AW +Australia,AU +Austria,AT +Azerbaijan,AZ +Bahamas,BS +Bahrain,BH +Bangladesh,BD +Barbados,BB +Belarus,BY +Belgium,BE +Belize,BZ +Benin,BJ +Bermuda,BM +Bhutan,BT +"Bolivia, Plurinational State of",BO +"Bonaire, Sint Eustatius and Saba",BQ +Bosnia and Herzegovina,BA +Botswana,BW +Bouvet Island,BV +Brazil,BR +British Indian Ocean Territory,IO +Brunei Darussalam,BN +Bulgaria,BG +Burkina Faso,BF +Burundi,BI +Cambodia,KH +Cameroon,CM +Canada,CA +Cape Verde,CV +Cayman Islands,KY +Central African Republic,CF +Chad,TD +Chile,CL +China,CN +Christmas Island,CX +Cocos (Keeling) Islands,CC +Colombia,CO +Comoros,KM +Congo,CG +"Congo, the Democratic Republic of the",CD +Cook Islands,CK +Costa Rica,CR +Côte d'Ivoire,CI +Croatia,HR +Cuba,CU +Curaçao,CW +Cyprus,CY +Czech Republic,CZ +Denmark,DK +Djibouti,DJ +Dominica,DM +Dominican Republic,DO +Ecuador,EC +Egypt,EG +El Salvador,SV +Equatorial Guinea,GQ +Eritrea,ER +Estonia,EE +Ethiopia,ET +Falkland Islands (Malvinas),FK +Faroe Islands,FO +Fiji,FJ +Finland,FI +France,FR +French Guiana,GF +French Polynesia,PF +French Southern Territories,TF +Gabon,GA +Gambia,GM +Georgia,GE +Germany,DE +Ghana,GH +Gibraltar,GI +Greece,GR +Greenland,GL +Grenada,GD +Guadeloupe,GP +Guam,GU +Guatemala,GT +Guernsey,GG +Guinea,GN +Guinea-Bissau,GW +Guyana,GY +Haiti,HT +Heard Island and McDonald Islands,HM +Holy See (Vatican City State),VA +Honduras,HN +Hong Kong,HK +Hungary,HU +Iceland,IS +India,IN +Indonesia,ID +"Iran, Islamic Republic of",IR +Iraq,IQ +Ireland,IE +Isle of Man,IM +Israel,IL +Italy,IT +Jamaica,JM +Japan,JP +Jersey,JE +Jordan,JO +Kazakhstan,KZ +Kenya,KE +Kiribati,KI +"Korea, Democratic People's Republic of",KP +"Korea, Republic of",KR +Kuwait,KW +Kyrgyzstan,KG +Lao People's Democratic Republic,LA +Latvia,LV +Lebanon,LB +Lesotho,LS +Liberia,LR +Libya,LY +Liechtenstein,LI +Lithuania,LT +Luxembourg,LU +Macao,MO +"Macedonia, the Former Yugoslav Republic of",MK +Madagascar,MG +Malawi,MW +Malaysia,MY +Maldives,MV +Mali,ML +Malta,MT +Marshall Islands,MH +Martinique,MQ +Mauritania,MR +Mauritius,MU +Mayotte,YT +Mexico,MX +"Micronesia, Federated States of",FM +"Moldova, Republic of",MD +Monaco,MC +Mongolia,MN +Montenegro,ME +Montserrat,MS +Morocco,MA +Mozambique,MZ +Myanmar,MM +Namibia,NA +Nauru,NR +Nepal,NP +Netherlands,NL +New Caledonia,NC +New Zealand,NZ +Nicaragua,NI +Niger,NE +Nigeria,NG +Niue,NU +Norfolk Island,NF +Northern Mariana Islands,MP +Norway,NO +Oman,OM +Pakistan,PK +Palau,PW +"Palestine, State of",PS +Panama,PA +Papua New Guinea,PG +Paraguay,PY +Peru,PE +Philippines,PH +Pitcairn,PN +Poland,PL +Portugal,PT +Puerto Rico,PR +Qatar,QA +Réunion,RE +Romania,RO +Russian Federation,RU +Rwanda,RW +Saint Barthélemy,BL +"Saint Helena, Ascension and Tristan da Cunha",SH +Saint Kitts and Nevis,KN +Saint Lucia,LC +Saint Martin (French part),MF +Saint Pierre and Miquelon,PM +Saint Vincent and the Grenadines,VC +Samoa,WS +San Marino,SM +Sao Tome and Principe,ST +Saudi Arabia,SA +Senegal,SN +Serbia,RS +Seychelles,SC +Sierra Leone,SL +Singapore,SG +Sint Maarten (Dutch part),SX +Slovakia,SK +Slovenia,SI +Solomon Islands,SB +Somalia,SO +South Africa,ZA +South Georgia and the South Sandwich Islands,GS +South Sudan,SS +Spain,ES +Sri Lanka,LK +Sudan,SD +Suriname,SR +Svalbard and Jan Mayen,SJ +Swaziland,SZ +Sweden,SE +Switzerland,CH +Syrian Arab Republic,SY +"Taiwan, Province of China",TW +Tajikistan,TJ +"Tanzania, United Republic of",TZ +Thailand,TH +Timor-Leste,TL +Togo,TG +Tokelau,TK +Tonga,TO +Trinidad and Tobago,TT +Tunisia,TN +Turkey,TR +Turkmenistan,TM +Turks and Caicos Islands,TC +Tuvalu,TV +Uganda,UG +Ukraine,UA +United Arab Emirates,AE +United Kingdom,GB +United States,US +United States Minor Outlying Islands,UM +Uruguay,UY +Uzbekistan,UZ +Vanuatu,VU +"Venezuela, Bolivarian Republic of",VE +Viet Nam,VN +"Virgin Islands, British",VG +"Virgin Islands, U.S.",VI +Wallis and Futuna,WF +Western Sahara,EH +Yemen,YE +Zambia,ZM +Zimbabwe,ZW diff --git a/third/semester1/CT326_Programming_III/assignments/assignment3/data_csv.csv b/third/semester1/CT326_Programming_III/assignments/assignment3/data_csv.csv new file mode 100644 index 00000000..16c718a3 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment3/data_csv.csv @@ -0,0 +1,250 @@ +Name,Code +Afghanistan,AF +Åland Islands,AX +Albania,AL +Algeria,DZ +American Samoa,AS +Andorra,AD +Angola,AO +Anguilla,AI +Antarctica,AQ +Antigua and Barbuda,AG +Argentina,AR +Armenia,AM +Aruba,AW +Australia,AU +Austria,AT +Azerbaijan,AZ +Bahamas,BS +Bahrain,BH +Bangladesh,BD +Barbados,BB +Belarus,BY +Belgium,BE +Belize,BZ +Benin,BJ +Bermuda,BM +Bhutan,BT +"Bolivia, Plurinational State of",BO +"Bonaire, Sint Eustatius and Saba",BQ +Bosnia and Herzegovina,BA +Botswana,BW +Bouvet Island,BV +Brazil,BR +British Indian Ocean Territory,IO +Brunei Darussalam,BN +Bulgaria,BG +Burkina Faso,BF +Burundi,BI +Cambodia,KH +Cameroon,CM +Canada,CA +Cape Verde,CV +Cayman Islands,KY +Central African Republic,CF +Chad,TD +Chile,CL +China,CN +Christmas Island,CX +Cocos (Keeling) Islands,CC +Colombia,CO +Comoros,KM +Congo,CG +"Congo, the Democratic Republic of the",CD +Cook Islands,CK +Costa Rica,CR +Côte d'Ivoire,CI +Croatia,HR +Cuba,CU +Curaçao,CW +Cyprus,CY +Czech Republic,CZ +Denmark,DK +Djibouti,DJ +Dominica,DM +Dominican Republic,DO +Ecuador,EC +Egypt,EG +El Salvador,SV +Equatorial Guinea,GQ +Eritrea,ER +Estonia,EE +Ethiopia,ET +Falkland Islands (Malvinas),FK +Faroe Islands,FO +Fiji,FJ +Finland,FI +France,FR +French Guiana,GF +French Polynesia,PF +French Southern Territories,TF +Gabon,GA +Gambia,GM +Georgia,GE +Germany,DE +Ghana,GH +Gibraltar,GI +Greece,GR +Greenland,GL +Grenada,GD +Guadeloupe,GP +Guam,GU +Guatemala,GT +Guernsey,GG +Guinea,GN +Guinea-Bissau,GW +Guyana,GY +Haiti,HT +Heard Island and McDonald Islands,HM +Holy See (Vatican City State),VA +Honduras,HN +Hong Kong,HK +Hungary,HU +Iceland,IS +India,IN +Indonesia,ID +"Iran, Islamic Republic of",IR +Iraq,IQ +Ireland,IE +Isle of Man,IM +Israel,IL +Italy,IT +Jamaica,JM +Japan,JP +Jersey,JE +Jordan,JO +Kazakhstan,KZ +Kenya,KE +Kiribati,KI +"Korea, Democratic People's Republic of",KP +"Korea, Republic of",KR +Kuwait,KW +Kyrgyzstan,KG +Lao People's Democratic Republic,LA +Latvia,LV +Lebanon,LB +Lesotho,LS +Liberia,LR +Libya,LY +Liechtenstein,LI +Lithuania,LT +Luxembourg,LU +Macao,MO +"Macedonia, the Former Yugoslav Republic of",MK +Madagascar,MG +Malawi,MW +Malaysia,MY +Maldives,MV +Mali,ML +Malta,MT +Marshall Islands,MH +Martinique,MQ +Mauritania,MR +Mauritius,MU +Mayotte,YT +Mexico,MX +"Micronesia, Federated States of",FM +"Moldova, Republic of",MD +Monaco,MC +Mongolia,MN +Montenegro,ME +Montserrat,MS +Morocco,MA +Mozambique,MZ +Myanmar,MM +Namibia,NA +Nauru,NR +Nepal,NP +Netherlands,NL +New Caledonia,NC +New Zealand,NZ +Nicaragua,NI +Niger,NE +Nigeria,NG +Niue,NU +Norfolk Island,NF +Northern Mariana Islands,MP +Norway,NO +Oman,OM +Pakistan,PK +Palau,PW +"Palestine, State of",PS +Panama,PA +Papua New Guinea,PG +Paraguay,PY +Peru,PE +Philippines,PH +Pitcairn,PN +Poland,PL +Portugal,PT +Puerto Rico,PR +Qatar,QA +Réunion,RE +Romania,RO +Russian Federation,RU +Rwanda,RW +Saint Barthélemy,BL +"Saint Helena, Ascension and Tristan da Cunha",SH +Saint Kitts and Nevis,KN +Saint Lucia,LC +Saint Martin (French part),MF +Saint Pierre and Miquelon,PM +Saint Vincent and the Grenadines,VC +Samoa,WS +San Marino,SM +Sao Tome and Principe,ST +Saudi Arabia,SA +Senegal,SN +Serbia,RS +Seychelles,SC +Sierra Leone,SL +Singapore,SG +Sint Maarten (Dutch part),SX +Slovakia,SK +Slovenia,SI +Solomon Islands,SB +Somalia,SO +South Africa,ZA +South Georgia and the South Sandwich Islands,GS +South Sudan,SS +Spain,ES +Sri Lanka,LK +Sudan,SD +Suriname,SR +Svalbard and Jan Mayen,SJ +Swaziland,SZ +Sweden,SE +Switzerland,CH +Syrian Arab Republic,SY +"Taiwan, Province of China",TW +Tajikistan,TJ +"Tanzania, United Republic of",TZ +Thailand,TH +Timor-Leste,TL +Togo,TG +Tokelau,TK +Tonga,TO +Trinidad and Tobago,TT +Tunisia,TN +Turkey,TR +Turkmenistan,TM +Turks and Caicos Islands,TC +Tuvalu,TV +Uganda,UG +Ukraine,UA +United Arab Emirates,AE +United Kingdom,GB +United States,US +United States Minor Outlying Islands,UM +Uruguay,UY +Uzbekistan,UZ +Vanuatu,VU +"Venezuela, Bolivarian Republic of",VE +Viet Nam,VN +"Virgin Islands, British",VG +"Virgin Islands, U.S.",VI +Wallis and Futuna,WF +Western Sahara,EH +Yemen,YE +Zambia,ZM +Zimbabwe,ZW diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/CT326 - Assignment 4-1.pdf b/third/semester1/CT326_Programming_III/assignments/assignment4/CT326 - Assignment 4-1.pdf new file mode 100644 index 00000000..0bce2e09 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/CT326 - Assignment 4-1.pdf differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/encodings.xml b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/encodings.xml new file mode 100644 index 00000000..aa00ffab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/misc.xml b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/misc.xml new file mode 100644 index 00000000..82dbec8a --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/library_view_screenshot.png b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/library_view_screenshot.png new file mode 100644 index 00000000..a69b6d1f Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/library_view_screenshot.png differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/pom.xml b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/pom.xml new file mode 100644 index 00000000..b720bd8b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + assignment4 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Beatles_-_Abbey_Road.jpg b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Beatles_-_Abbey_Road.jpg new file mode 100644 index 00000000..1b066450 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Beatles_-_Abbey_Road.jpg differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Damien_Dempsey_-_Seize_the_Day.jpg b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Damien_Dempsey_-_Seize_the_Day.jpg new file mode 100644 index 00000000..49b611c8 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Damien_Dempsey_-_Seize_the_Day.jpg differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Katebushneverforever.png b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Katebushneverforever.png new file mode 100644 index 00000000..19f2d535 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Katebushneverforever.png differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Razorblade_suitcase.jpg b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Razorblade_suitcase.jpg new file mode 100644 index 00000000..643e93f6 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/Razorblade_suitcase.jpg differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/polyphia_new_levels_new_devils.jpeg b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/polyphia_new_levels_new_devils.jpeg new file mode 100644 index 00000000..812e2a2c Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/covers/polyphia_new_levels_new_devils.jpeg differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/bush_razorblade_suitcase.txt b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/bush_razorblade_suitcase.txt new file mode 100644 index 00000000..47e31219 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/bush_razorblade_suitcase.txt @@ -0,0 +1,13 @@ +1., "Personal Holloway", 3:23 +2., "Greedy Fly", 4:30 +3., "Swallowed", 4:51 +4., "Insect Kin", 4:27 +5., "Cold Contagious", 6:00 +6., "A Tendency to Start Fires", 4:04 +7., "Mouth", 5:45 +8., "Straight No Chaser", 4:02 +9., "History", 4:17 +10., "Synapse", 4:52 +11., "Communicator", 4:25 +12., "Bonedriven", 4:32 +13., "Distant Voices", 6:39 \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/damien_dempsey_seize_the_day.txt b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/damien_dempsey_seize_the_day.txt new file mode 100644 index 00000000..d442d9db --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/damien_dempsey_seize_the_day.txt @@ -0,0 +1,11 @@ +1., "Negative Vibes", 4:44 +2., "Ghosts of Overdoses", 4:41 +3., "It's All Good", 4:21 +4., "Factories", 5:17 +5., "Jar Song", 5:03 +6., "Celtic Tiger", 5:13 +7., "Apple of My Eye", 3:43 +8., "Industrial School", 5:27 +9., "Great Gaels of Ireland", 5:21 +10., "Marching Season Siege", 3:24 +11., "Seize the Day" (hidden track), 4:12 diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/kate_bush_never_for_ever.txt b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/kate_bush_never_for_ever.txt new file mode 100644 index 00000000..8e543f85 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/kate_bush_never_for_ever.txt @@ -0,0 +1,11 @@ +1., "Babooshka", 3:20 +2., "Delius (Song of Summer)", 2:51 +3., "Blow Away (For Bill)", 3:33 +4., "All We Ever Look For", 3:47 +5., "Egypt", 4:10 +6., "The Wedding List", 4:15 +7., "Violin", 3:15 +8., "The Infant Kiss", 2:50 +9., "Night Scented Stock", 0:51 +10., "Army Dreamers", 2:55 +11., "Breathing", 5:29 diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/new_levels_new_devils.txt b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/new_levels_new_devils.txt new file mode 100644 index 00000000..94d8c6c3 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/new_levels_new_devils.txt @@ -0,0 +1,10 @@ +1, Nasty, 4:40 +2, O.D., 3:22 +3, Death Note, 3:40 +4, Bad, 3:55 +5, Drown, 3:54 +6, Saucy, 3:04 +7, Yas, 3:22 +8, So Strange, 4:00 +9, Rich Kids, 3:21 +10, G.O.A.T., 3:35 \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/the_beatles_abbey_road.txt b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/the_beatles_abbey_road.txt new file mode 100644 index 00000000..ec4bf7d9 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/library/the_beatles_abbey_road.txt @@ -0,0 +1,11 @@ +1., "Here Comes the Sun", 3:05 +2., "Because", 2:45 +3., "You Never Give Me Your Money", 4:03 +4., "Sun King", 2:26 +5., "Mean Mr. Mustard", 1:06 +6., "Polythene Pam", 1:13 +7., "She Came In Through the Bathroom Window", 1:58 +8., "Golden Slumbers", 1:31 +9., "Carry That Weight", 1:36 +10., "The End", 2:05 +11., "Her Majesty", 0:23 \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/music_library.txt b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/music_library.txt new file mode 100644 index 00000000..12387aff --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/resources/music_library.txt @@ -0,0 +1,5 @@ +Bush, Razorblade Suitcase, covers/Razorblade_suitcase.jpg, library/bush_razorblade_suitcase.txt +Kate Bush, Never for Ever, covers/Katebushneverforever.png, library/kate_bush_never_for_ever.txt +Damien Dempsey, Seize the Day, covers/Damien_Dempsey_-_Seize_the_Day.jpg, library/damien_dempsey_seize_the_day.txt +Beatles, Abbey Road, covers/Beatles_-_Abbey_Road.jpg, library/the_beatles_abbey_road.txt +Polyphia, New Levels New Devils, covers/polyphia_new_levels_new_devils.jpeg, library/new_levels_new_devils.txt \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/Album.java b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/Album.java new file mode 100644 index 00000000..7d49eead --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/Album.java @@ -0,0 +1,120 @@ +// Name: Andrew Hayes +// Student ID: 21321503 + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +/** + * class to represent an Album object and its tracks + */ +public class Album { + private String artist; // the name of the artist + private String title; // the title of the album + private String pathToCover; // the path to the cover image of the album + private String pathToTrackList; // the path to the track list text file for the album + private ArrayList tracks = new ArrayList<>(); // arraylist of all the tracks on the album + + /** + * constructor for Album objects + * @param artist String of the artist's name + * @param title String of the title of the album + * @param pathToCover String of the filepath to the cover image + * @param pathToTrackList String of the filepath to the list of tracks on the album + */ + public Album(String artist, String title, String pathToCover, String pathToTrackList) throws IOException { + this.artist = artist; + this.title = title; + this.pathToCover = pathToCover; + this.pathToTrackList = pathToTrackList; + + // reading the trackList file and adding a Track object to the ArrayList for each line in the file + BufferedReader reader = new BufferedReader(new FileReader(pathToTrackList)); // not catching FileNotFoundException as entire method should fail if the trackList file is not accessible + String line; + while ((line = reader.readLine()) != null) { + String[] columns = line.split(","); + tracks.add(new Track(columns[0].strip(), columns[1].strip(), columns[2].strip())); // trimming whitespace from the ends of each column read in + } + } + + /** + * getter for the artist's name + * @return String artist + */ + public String getArtist() { + return artist; + } + + /** + * setter for the artist's name + * @param artist String of the artist's name + */ + public void setArtist(String artist) { + this.artist = artist; + } + + /** + * getter for the title + * @return String title of the album + */ + public String getTitle() { + return title; + } + + /** + * setter for the title + * @param title String title of the album + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * getter for pathToCover + * @return String path to the cover image + */ + public String getPathToCover() { + return pathToCover; + } + + /** + * setter for pathToCover + * @param pathToCover String of the filepath to the cover image + */ + public void setPathToCover(String pathToCover) { + this.pathToCover = pathToCover; + } + + /** + * getter for trackList + * @return String of the filepath to the trackList + */ + public String getPathToTrackList() { + return pathToTrackList; + } + + /** + * setter for trackList + * @param pathToTrackList String of the filepath to the trackLists + */ + public void setPathToTrackList(String pathToTrackList) { + this.pathToTrackList = pathToTrackList; + } + + /** + * getter for tracks + * @return Array of Track objects + */ + public ArrayList getTracks() { + return tracks; + } + + /** + * setter for tracks + * @param tracks array of Track objects + */ + public void setTracks(ArrayList tracks) { + this.tracks = tracks; + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/MusicLibrary.java b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/MusicLibrary.java new file mode 100644 index 00000000..bf7dbadc --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/MusicLibrary.java @@ -0,0 +1,181 @@ +// Name: Andrew Hayes +// Student ID: 21321503 + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.util.ArrayList; + +/** + * Application class for the Music Library application + */ +public class MusicLibrary extends JFrame { + private String libraryDirectory = "resources/"; // directory that the library files are in + private String libraryFileName = "music_library.txt"; // name of the music libary file + private ArrayList albums = new ArrayList<>(); + private ActionListener actionListener; // action listener for the buttons in this application + + /** + * constructor for the Music Library application + */ + public MusicLibrary() { + super("Music Library"); // set window title + + // make JFrame fill the screen + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + setSize(screenSize.width, screenSize.height); + + // using border layout to position JPanels easily + Container container = getContentPane(); + container.setLayout(new BorderLayout()); + + // panel to show the list of albums + JPanel albumPanel = new JPanel(); + + // action listener to handle what happens when buttons are clicked + actionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent event) { + // if the actionCommand was to show the albumPanel (i.e., "back" button was pressed on the trackPanel) + if (event.getActionCommand().equals("showAlbumPanel")) { + // removing everything from the container + container.removeAll(); + + // cleaning screen + container.revalidate(); + container.repaint(); + + // adding albumPanel to container + container.add(albumPanel, BorderLayout.CENTER); + } + // else if the actionCommand was anything other than showAlbumPanel, i.e. it was an album being clicked, hide it and display the tracklist of the selected album + else { + // hiding the albumPanel + container.remove(albumPanel); + + // cleaning screen + container.revalidate(); + container.repaint(); + + // displaying album contents (trackPanel) + container.add(generateTrackPanel(albums.get(Integer.parseInt(event.getActionCommand()))), BorderLayout.CENTER); + } + } + }; + + // loading the albums into the arraylist + try { + albums = loadAlbums(libraryDirectory + libraryFileName); + } + // display error message if the music library file could not be read successfully + catch (IOException e) { + albumPanel.add(new JLabel("The music library file could not be read successfully!!!")); + } + + // iterating over each album and adding it to the GUI interface as a button + for (int i = 0; i < albums.size(); i++) { // using iteration instead of for-each so that we can set the actionCommand of the button to the value of i + Album album = albums.get(i); + + // attempting to create a button with the album cover as the icon + try { + // reading in image, scaling it, turning it into an icond, and adding it to the album button + Image coverImage = ImageIO.read(new File(libraryDirectory + album.getPathToCover())).getScaledInstance(200, 200, Image.SCALE_SMOOTH); + ImageIcon icon = new ImageIcon(coverImage); + JButton button = new JButton(album.getTitle(), icon); // including album title in button to make it easier to use + // JButton button = new JButton(icon); // would give same appearancec as in assignment spec + + // make clicking the button use an action command that references the album's position in the arraylist + button.setActionCommand(String.valueOf(i)); + button.addActionListener(actionListener); + + albumPanel.add(button); + } + // if the album cover cannot be found, just put a text button in its place + catch (IOException e) { + JButton button = new JButton(album.getTitle()); + + // make clicking the button use an action command that references the album's position in the arraylist + button.setActionCommand(String.valueOf(i)); + button.addActionListener(actionListener); + + albumPanel.add(button); + } + } + + // display the album panel + container.add(albumPanel, BorderLayout.CENTER); + setVisible(true); + } + + /** + * method to load all the Albums into memory as an ArrayList of Albums + * @param libraryPath String representing the file path to the music_library.txt file + * @throws IOException if reading the albums in from the library file and/or instantiating them fails + */ + public ArrayList loadAlbums(String libraryPath) throws IOException { + // it's not really necessary that libraryPath be passed to this method from a design perspective, as they are both members of the MusicLibrary object class + // however, this makes the method more re-usable if we ever want to load albums from outside of this class + + ArrayList albums = new ArrayList<>(); // ArrayList of Album objects to be returned + + // instantiating an Album object for each line in the library file + BufferedReader reader = new BufferedReader(new FileReader(libraryPath)); // not catching FileNotFoundException as entire method should fail if the library file is not accessible + String line; + while ((line = reader.readLine()) != null) { + String[] columns = line.split(","); + + // creating the album object and adding it to the ArrayList + albums.add(new Album(columns[0].trim(), columns[1].trim(), columns[2].trim(), libraryDirectory + columns[3].trim())); // trimming whitespace from the ends of each column read in + } + + return albums; + } + + /** + * method to generate a JPanel containing a JTable of all the tracks for a given Album + * @param album the Album for which we are generating a JTable of tracks + * @return a JPanel containing a JTable of all the tracks for a given Album + */ + public JPanel generateTrackPanel(Album album) { + JPanel trackPanel = new JPanel(new BorderLayout()); // using border layout so the table can be easily aligned above the "back" button + + ArrayList tracks = album.getTracks(); + + // columns to be displayed in JTable + String[][] data = new String[tracks.size()][3]; + + // filling up columns to be displayed in JTable + for (int i = 0; i < tracks.size(); i++) { + // track number, track title, and track duration + data[i] = new String[]{tracks.get(i).getTrackNumber(), tracks.get(i).getTitle(), tracks.get(i).getDuration()}; + } + + // adding the JTable of tracks to the center of the panel + String[] columnNames = {"No.", "Track Title", "Length"}; + JTable table = new JTable(data, columnNames); + table.setEnabled(false); // disable user interaction with the table so they can't edit it + trackPanel.add(new JScrollPane(table), BorderLayout.CENTER); + + JButton button = new JButton("Back"); + + // make clicking the button use an action command that references the album's position in the arraylist + button.addActionListener(actionListener); + button.setActionCommand("showAlbumPanel"); + + // adding the back button to the bottom of the panel, underneath the table + trackPanel.add(button, BorderLayout.SOUTH); + + return trackPanel; + } + + /** + * main method + * @param args (none) + */ + public static void main(String[] args) { + MusicLibrary application = new MusicLibrary(); + application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/Track.java b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/Track.java new file mode 100644 index 00000000..d6372018 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/src/main/java/Track.java @@ -0,0 +1,72 @@ +// Name: Andrew Hayes +// Student ID: 21321503 + +/** + * class to represent a Track on an Album + * not really necessary for this assignmenet, could've just stored tracks as Strings or something, but i feel that this is a more "correct" OOP-like approach + */ +public class Track { + private String trackNumber; // storing as String as we never manipulate it arithmetically, and allows non-integer numberings such as A1 and B1 for A-sides and B-sides + private String title; // title of track + private String duration; // duration can also be stored as String as we never manipulate it. if manipulation was being done, java.time.Duration would be a better choice + + /** + * constructor for Track objects + * @param trackNumber the number of the track as a String + * @param title the name of the track/song + * @param duration the length of the song as a String + */ + public Track(String trackNumber, String title, String duration) { + this.trackNumber = trackNumber; + this.title = title; + this.duration = duration; + } + + /** + * getter method for the number of the track + * @return the number of the track as a String + */ + public String getTrackNumber() { + return trackNumber; + } + + /** + * setter method for the number of the track + * @param trackNumber a String representing the number of the track + */ + public void setTrackNumber(String trackNumber) { + this.trackNumber = trackNumber; + } + + /** + * getter method for the title of the track + * @return the name of the track, as a String + */ + public String getTitle() { + return title; + } + + /** + * setter method for the title of the track + * @param title a String object representing the name of the track + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * getter method for the duration of the track + * @return the duration of the track, as a String object + */ + public String getDuration() { + return duration; + } + + /** + * setter method for the duration of the track + * @param duration a String object representing the duration of the track + */ + public void setDuration(String duration) { + this.duration = duration; + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/track_listing_view_screenshot.png b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/track_listing_view_screenshot.png new file mode 100644 index 00000000..7e7d3062 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4/track_listing_view_screenshot.png differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4_Andrew_Hayes.zip b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4_Andrew_Hayes.zip new file mode 100644 index 00000000..ca9f9b06 Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment4/assignment4_Andrew_Hayes.zip differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326 - Assignment 5.pdf b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326 - Assignment 5.pdf new file mode 100644 index 00000000..99a881bd Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326 - Assignment 5.pdf differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/.gitignore b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/encodings.xml b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/encodings.xml new file mode 100644 index 00000000..aa00ffab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/misc.xml b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/misc.xml new file mode 100644 index 00000000..c3f3b0ab --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/output_screenshot.png b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/output_screenshot.png new file mode 100644 index 00000000..5e0f1a2f Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/output_screenshot.png differ diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/pom.xml b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/pom.xml new file mode 100644 index 00000000..e40213ec --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + org.example + CT326-Assignment-5 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.joda + joda-money + 1.0.3 + + + + \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Account.java b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Account.java new file mode 100644 index 00000000..41d29a9b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Account.java @@ -0,0 +1,117 @@ +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.time.LocalDateTime; + +import org.joda.money.CurrencyUnit; +import org.joda.money.Money; + +/** + * Account class for CT326 Assignment 5 (23/24) + * @author Adrian Clear + */ +public class Account implements Serializable { + + // Define serialVersionUID which is used during object deserialization to verify that the sender and receiver of a serialized + // object have loaded classes for that object that are compatible - will throw InvalidClassException if not compatible + // IDEs will often auto generate this value for you when creating new Java classes + + private static final long serialVersionUID = 202010191519L; + + private int accnum; + private Money balance; + + // Date and Time account object was first created or loaded from storage + private LocalDateTime activated; + + /** + * Creates an account with a given account number and balance. + * @param accnum the account number + * @param balance the initial balance of the account + * @throws NegativeBalanceException if the initial balance is negative + */ + public Account (int accnum, Money balance) throws NegativeBalanceException { + setBalance(balance); + this.accnum = accnum; + activated = LocalDateTime.now(); + } + + /** + * Make a deposit to the account of the given amount + * @param amount the amount to deposit + */ + public synchronized void makeDeposit(Money amount) throws NegativeBalanceException { // should never throw this Exception, only attempt to setBalance if amount is greater than 0 + if(amount.isGreaterThan(Money.of(CurrencyUnit.EUR, 0)) ) { + setBalance(balance.plus(amount)); + } + } + + /** + * Make a withdrawal from the account of the given amount + * @param amount the amount to withdraw + * @throws InsufficientFundsException if the amount to withdraw is greater than the current balance + */ + public synchronized void makeWithdrawal(Money amount) throws InsufficientFundsException { + try { + setBalance(balance.minus(amount)); + } catch (NegativeBalanceException e) { + throw new InsufficientFundsException(); + } + } + + /** + * Set the balance of the account to the given amount. + * @param balance the new balance of the account + * @throws NegativeBalanceException if the balance is negative + */ + private synchronized void setBalance(Money balance) throws NegativeBalanceException { + if (balance.isLessThan(Money.of(CurrencyUnit.EUR, 0))) throw new NegativeBalanceException("Negative Balance Not Allowed!"); + this.balance = balance; + } + + /** + * Get the balance of the account + * @return the balance of the account + */ + public Money getBalance() { + return balance; + } + + /** + * Get the account number of the account + * @return the account number of the account + */ + public int getAccountNumber() { + return accnum; + } + + /** + * Get the activation date of the account + * @return the activation date of the account + */ + public LocalDateTime getActivated() { + return activated; + } + + // This method is called when we are deserializing an instance of an Account object + private void readObject(ObjectInputStream aInputStream) throws ClassNotFoundException,IOException { + balance = (Money) aInputStream.readObject(); + accnum = aInputStream.readInt(); + // Reinitialise value for the LocalDateTime activated variable + activated = LocalDateTime.now(); + } + + // This method is called when we serialize an instance of an Account object + private void writeObject(ObjectOutputStream aOutputStream) throws IOException { + aOutputStream.writeObject(balance); + aOutputStream.writeInt(accnum); + // We don't write value for the LocalDateTime activated variable as we will reinitialise this when reloading the object + } + + @Override + public String toString() { + return String.format("Account %d has a balance of %s.", accnum, balance); + } + +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Bank.java b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Bank.java new file mode 100644 index 00000000..720f9f51 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Bank.java @@ -0,0 +1,116 @@ +// Name: Andrew Hayes +// ID: 21321503 +import org.joda.money.*; +import java.util.*; +import java.util.concurrent.*; + +/** + * Class to represent a Bank and its Accounts + * @author andrew + */ +public class Bank { + private static Map accounts = new HashMap<>(); // key is the account's number + private LinkedBlockingQueue transactions = new LinkedBlockingQueue<>(); + + /** + * method to add an Account to the Bank + * @param account the Account object to be added to the Bank + */ + public void addAccount(Account account) { + accounts.put(account.getAccountNumber(), account); + } + + /** + * method to return the Account identified by the supplied account number + * @param accountNumber the number of the account to be returned + * @return the account with the supplied accountNumber + */ + public Account getAccountByNumber(int accountNumber) { + return accounts.get(accountNumber); + } + + /** + * method to submit a Transaction to the queue to be processed + * @param transaction the Transaction to be submitted to the queue + */ + public void submitTransaction(Transaction transaction) { + try { + transactions.put(transaction); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // restore interrupted status + e.printStackTrace(); // if a transaction fails to be submitted, fail gracefully so that the transaction can be tried again later + } + } + + /** + * method to get the next Transaction from the queue for processing + * @return the next Transaction in the queue + */ + public Transaction getNextTransaction() throws InterruptedException { + // retrieve the head of the queue, waiting up to 5 seconds for an element to become available, otherwise returning null + return transactions.poll(5, TimeUnit.SECONDS); // not catching InterruptedExceptions here, should be caught in the calling method + } + + /** + * method to print out the details of each account in the bank (account number and balance) + */ + public static void printAccountsDetails() { + for (Account account : accounts.values()) { + System.out.println(account); // using given toString() method of the Account class + } + } + + /** + * method to return a collection of all the Account numbers in the Bank + * @return a Set of all the Integer account numbers in the Bank + */ + public ArrayList getAccountNumbers() { + return new ArrayList<>(accounts.keySet()); + } + + + /** + * main method of the Bank class + * @param args No arguments used + */ + public static void main(String[] args) throws NegativeBalanceException { + // declare and instantiate a bank object + Bank bank = new Bank(); + + // create and add three account instances to the bank with different starting balances + bank.addAccount(new Account(1, Money.of(CurrencyUnit.EUR, 20_000.00))); + bank.addAccount(new Account(2, Money.of(CurrencyUnit.EUR, 25_000.00))); + bank.addAccount(new Account(3, Money.of(CurrencyUnit.EUR, 33_333.33))); + + // declare and instantiate two TransactionProcessors + TransactionProcessor TP1 = new TransactionProcessor("TP1", bank); + TransactionProcessor TP2 = new TransactionProcessor("TP2", bank); + + // declare and instantiate one RandomTransactionGenerator + RandomTransactionGenerator rtg = new RandomTransactionGenerator(bank); + + // execute the threads using a thread pool + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4); + executorService.execute(rtg); + executorService.execute(TP1); + executorService.execute(TP2); + + // shut down the transaction generator after 10 seconds + executorService.schedule( + () -> { + rtg.stopGenerating(); + executorService.shutdown(); + }, 10, TimeUnit.SECONDS + ); + + // waiting until all threads have finished to print account details + try { + if (executorService.awaitTermination(10, TimeUnit.MINUTES)) { // giving some arbitrarily long timeout to wait for threads to finish + printAccountsDetails(); + } + } catch (InterruptedException e) { + // just printing stacktrace if exception thrown, no handling to be done + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/InsufficientFundsException.java b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/InsufficientFundsException.java new file mode 100644 index 00000000..be338a3a --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/InsufficientFundsException.java @@ -0,0 +1,8 @@ +/** + * An exception representing the fact that an account has insufficient funds + * for a given transaction. + * @author Adrian Clear + */ +public class InsufficientFundsException extends Exception { + +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/NegativeBalanceException.java b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/NegativeBalanceException.java new file mode 100644 index 00000000..2ba10139 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/NegativeBalanceException.java @@ -0,0 +1,9 @@ +/** + * An exception representing an instance where a negative balance is set to an account + * @author Adrian Clear + */ +public class NegativeBalanceException extends Exception { + public NegativeBalanceException(String message) { + super(message); + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/RandomTransactionGenerator.java b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/RandomTransactionGenerator.java new file mode 100644 index 00000000..d6a5b01b --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/RandomTransactionGenerator.java @@ -0,0 +1,58 @@ +// Name: Andrew Hayes +// ID: 21321503 +import java.util.ArrayList; + +/** + * Thread to randomly generate deposit and withdrawal transactions for random accounts + * @author andrew + */ +public class RandomTransactionGenerator extends Thread { + private Bank bank; + private ArrayList accountNumbers; + public static final Transaction poisonPill = new Transaction(-1, 0); + private boolean keepGenerating = true; // flag used to stop the thread + + /** + * Constructor for RandomTransactionGenerator objects + * @param bank the Bank object with which the RandomTransactionGenerator is associated + */ + public RandomTransactionGenerator(Bank bank) { + this.bank = bank; + accountNumbers = bank.getAccountNumbers(); + } + + /** + * Thread's run() method + */ + @Override + public void run() { + // loop until stopped + while (keepGenerating) { + // sleep for a random amount of time between 0 and 1 seconds + try { + sleep((long) (Math.random() * 1000)); + } catch (InterruptedException e) { + // if thread is interrupted, just break out of loop + break; + } + + // pick account and transaction amount randomly + int accountNumber = accountNumbers.get((int) (Math.random() * accountNumbers.size())); + float amount = (float) ((Math.random() * 20_000) - 10_000); + + // submit random transaction + bank.submitTransaction(new Transaction(accountNumber, amount)); + } + + // submit poison pill before exiting + bank.submitTransaction(poisonPill); + System.out.println("Transaction generator terminated"); + } + + /** + * method to stop the thread + */ + public void stopGenerating() { + keepGenerating = false; + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Transaction.java b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Transaction.java new file mode 100644 index 00000000..244a0c11 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/Transaction.java @@ -0,0 +1,42 @@ +/** + * A class representing an account transaction for the CT326 Assignment 5 (23/24) + * @author Adrian Clear + */ +public class Transaction { + private float amount; + private int accountNumber; + + /** + * Create a transaction for the Account with the given account number, of the given amount. + * @param accNumber the account number of the transaction account + * @param amount the amount to withdraw/deposit. A positive value represents a deposit, a negative value represents a withdrawal + */ + public Transaction(int accNumber, float amount) { + this.accountNumber = accNumber; + this.amount = amount; + } + + /** + * Get the amount of this transaction + * @return the amount of the transaction + */ + public float getAmount() { + return amount; + } + + /** + * Get the account number of the transaction + * @return the account number of the transaction + */ + public int getAccountNumber() { + return accountNumber; + } + + @Override + public String toString() { + if(amount >= 0) + return String.format("a deposit of %f to %d", amount, accountNumber); + else + return String.format("a withdrawal of %f from %d", amount, accountNumber); + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/TransactionProcessor.java b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/TransactionProcessor.java new file mode 100644 index 00000000..b2f18ff4 --- /dev/null +++ b/third/semester1/CT326_Programming_III/assignments/assignment5/CT326-Assignment-5/src/main/java/TransactionProcessor.java @@ -0,0 +1,83 @@ +// Name: Andrew Hayes +// ID: 21321503 +import org.joda.money.Money; + +/** + * Thread class to process Transactions of a Bank + * @author andrew + */ +public class TransactionProcessor extends Thread { + private String name; + private Bank bank; + + // explicitly setting these values to 0 for readability, although they would default to 0 regardless + // variables to keep a tally of how many withdrawals and deposits the object has made + private int numWithdrawals = 0; + private int numDeposits = 0; + + /** + * TransactionProcessor Constructor + * @param name + * @param bank + */ + public TransactionProcessor(String name, Bank bank) { + this.name = name; + this.bank = bank; + } + + /** + * Thread's run() method + */ + public void run() { + // loop infinitely + while (!Thread.currentThread().isInterrupted()) { + try { + // sleep for a random amount of time between 0 and 1 seconds before processing the next transaction + sleep((long) (Math.random() * 1000)); + + // get transaction to process + Transaction transaction = bank.getNextTransaction(); + + // finish executing if the thread has been closed (poison pill received) or 5 seconds has elapsed without a new transaction being received + // if the transaction is `null` this is because bank.getNextTransaction() waited for 5 seconds without receiving a new transaction + if (transaction == null || transaction.equals(RandomTransactionGenerator.poisonPill)) { + break; + } + // otherwise, process the transaction + else { + Account account = bank.getAccountByNumber(transaction.getAccountNumber()); + float amount = transaction.getAmount(); + + // if the amount is positive, then it is a deposit + // made the design choice to treat a transaction of amount 0 as a deposit because it still needs to be processed and 0 is a positive number + if (amount >= 0) { + System.out.printf("%s is processing a deposit of EUR %.2f to %d\n", name, amount, transaction.getAccountNumber()); + // only dealing in euros as specified + account.makeDeposit(Money.parse(String.format("EUR %.2f", amount))); // ignoring decimals after the second place + numDeposits++; + } + // if the amount is negative, then it is a deposit + else { + try { + System.out.printf("%s is processing a withdrawal of EUR %.2f from %d\n", name, amount, transaction.getAccountNumber()); + account.makeWithdrawal(Money.parse(String.format("EUR %.2f", -amount))); + + // if the above line fails due to an exception, the control flow will jump to the catch block and the following line will not be executed, and the failed withdrawal will not be counted + numWithdrawals++; + } + catch (InsufficientFundsException e) { // abort transaction if funds are insufficient + System.out.println("Transaction could not be processed due to insufficient funds"); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + // if the thread has been interrupted, just exit loop and return + break; + } + } + + // print the TransactionProcessor's name and number of deposits and withdrawals processed + System.out.printf("%s finished processing %d transactions, including %d deposits, and %d withdrawals\n", name, numWithdrawals + numDeposits, numDeposits, numWithdrawals); + } +} diff --git a/third/semester1/CT326_Programming_III/assignments/assignment5/assignment5_Andrew_Hayes.zip b/third/semester1/CT326_Programming_III/assignments/assignment5/assignment5_Andrew_Hayes.zip new file mode 100644 index 00000000..6f63c67c Binary files /dev/null and b/third/semester1/CT326_Programming_III/assignments/assignment5/assignment5_Andrew_Hayes.zip differ diff --git a/third/semester1/CT326_Programming_III/exam_notes.txt b/third/semester1/CT326_Programming_III/exam_notes.txt new file mode 100644 index 00000000..2c04e95c --- /dev/null +++ b/third/semester1/CT326_Programming_III/exam_notes.txt @@ -0,0 +1,45 @@ +- most code for gui questions +- not expected to include @Override annotations in code +- static imports are necessary +- imports are not necessary +- unless asked to use floats, just use ints even for stuff like Salaries because it's simpler +- talked a lot about comparators + + + +Intbuffer question answer: + +public class IntBufferImp { + private int values; + private boolean available = false; + + public int consume() { + if (!available) { + try { + wait(); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + available = false; + notifyAll(); + return value; + } + + public void produce(int i) { + if (available) { + try { + wait(); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + value = i; + notifyAll(); + available = true; + } +} diff --git a/third/semester1/CT326_Programming_III/notes/CT326-Notes.pdf b/third/semester1/CT326_Programming_III/notes/CT326-Notes.pdf new file mode 100644 index 00000000..bde1a71a Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/CT326-Notes.pdf differ diff --git a/third/semester1/CT326_Programming_III/notes/CT326-Notes.tex b/third/semester1/CT326_Programming_III/notes/CT326-Notes.tex new file mode 100644 index 00000000..3e99d121 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/CT326-Notes.tex @@ -0,0 +1,1344 @@ +%! TeX program = lualatex +\documentclass[a4paper,11pt]{article} +% packages +\usepackage{fontspec} +\setmainfont{EB Garamond} +% for tironian et fallback +% % \directlua{luaotfload.add_fallback +% % ("emojifallback", +% % {"Noto Serif:mode=harf"} +% % )} +% % \setmainfont{EB Garamond}[RawFeature={fallback=emojifallback}] + +\setmonofont[Scale=MatchLowercase]{Deja Vu Sans Mono} +\usepackage[a4paper,left=2cm,right=2cm,top=\dimexpr15mm+1.5\baselineskip,bottom=2cm]{geometry} +\setlength{\parindent}{0pt} + +\usepackage{fancyhdr} % Headers and footers +\fancyhead[R]{\normalfont \leftmark} +\fancyhead[L]{} +\pagestyle{fancy} + +\usepackage{microtype} % Slightly tweak font spacing for aesthetics +\usepackage[english]{babel} % Language hyphenation and typographical rules +\usepackage[final, colorlinks = true, urlcolor = blue, linkcolor = black]{hyperref} +\usepackage{changepage} % adjust margins on the fly + +\usepackage{minted} +\usemintedstyle{algol_nu} +\usepackage{xcolor} + +\usepackage{pgfplots} +\pgfplotsset{width=\textwidth,compat=1.9} + +\usepackage{caption} +\newenvironment{code}{\captionsetup{type=listing}}{} +\captionsetup[listing]{skip=0pt} +\setlength{\abovecaptionskip}{5pt} +\setlength{\belowcaptionskip}{5pt} + +\usepackage[yyyymmdd]{datetime} +\renewcommand{\dateseparator}{-} + +\usepackage{titlesec} + +\begin{document} +\begin{titlepage} + \begin{center} + \hrule + \vspace*{0.6cm} + \huge \textbf{CT326} + \vspace*{0.6cm} + \hrule + \LARGE + \vspace{0.5cm} + PROGRAMMING III + \vspace{0.5cm} + \hrule + + \vfill + \includegraphics[width=\textwidth]{images/java-logo.png} + \vfill + + \Large + \vspace{0.5cm} + \hrule + \vspace{0.5cm} + \textbf{Andreas Ó hAoḋa} + % \vspace{0.5cm} + % \hrule + % \vspace{0.5cm} + + \normalsize + University of Galway + + \today + + \vspace{0.5cm} + \hrule + \end{center} +\end{titlepage} + +\pagenumbering{roman} +\newpage +\tableofcontents +\newpage +\setcounter{page}{1} +\pagenumbering{arabic} + +\section{Introduction} +\subsection{Lecturer Contact Information} +\begin{itemize} + \item Dr. Adrian Clear (\texttt{\href{mailto://adrian.clear@universityofgalway.ie}{adrian.clear@universityofgalway.ie}}). + \item Office IT408. +\end{itemize} + +\subsection{Assessment} +Continuous assessment consisting of five assignments will constitute 30\% of the overall mark. +The exam will constitute the remaining 70\% of the overall mark. +The exam will be a written exam on pen \& paper. +The marking will reflect this (small mistakes, e.g. missing semicolons, will not be penalised). +Practising with past exam papers is highly recommended. + +\subsection{Textbook} +The textbook for this course is \emph{Java - How to Program by Deitel \& Deitel}, which is available in the University +Bookshop. +It is not necessary to buy this book for this module. + +\section{Overloading Constructors, Abstract Methods, \& Polymorphism} +\subsection{Revision} +An \textbf{object} is something upon which your program performs different operations. +Java uses a \textbf{class} to represent objects. +Each class has a unique name. +To create an instance of a class variable, you must use the \verb|new| operator. +A class contains members. +These may be: +\begin{enumerate} + \item Information (or data), often called class variables. + \item Functions (methods) that operate on the data. +\end{enumerate} + +\subsection{Overloaded Constructors} +Methods in the same class may have the same name, so long as they have different \textbf{parameter lists}. +An overloaded constructor is creating by declaring more than one constructor for one class, each with distinct parameter lists. + +\subsection{Class Inheritance} +When your programs use inheritance, you use a \textbf{superclass} to derive a new class. +The new class inherits the superclass's members. +To initialise class members for an extended class (called a \textbf{sub-class}), the application invokes the super class and +sub-class constructors. +The \verb|this| \& \verb|super| keywords are used to refer to the current class \& the superclass, respectively. +\\\\ +There are three types of members: \textbf{public}, \textbf{private}, \& \textbf{protected}. +\begin{figure}[H] + \centering + \includegraphics[width=0.8\textwidth]{./images/access_level_specifiers.png} + \caption{Access Level Specifiers} +\end{figure} + +The keyword \verb|final| is used to indicate that a class member cannot be overridden or modified. + + +\subsection{Abstract Classes} +An \textbf{abstract} class is one that cannot be instantiated. +They are declared with the keyword \verb|abstract|, e.g.: + +\mintinline{Java}{public abstract class Employee}. +Abstract classes can have instance data and non-abstract (concrete) methods for sub-classes. +Abstract classes can have constructors for sub-classes to initialise inherited data. +Sub-classes of an abstract class must be also be abstract, and declared with the keyword \verb|abstract|. + +\section{Command-Line Programming} +\subsection{Solving Common Coding Problems} +\begin{itemize} + \item Problem: The compiler complains that it can't find a class + \begin{itemize} + \item Make sure that you've imported the class or its package. + \item Unset the \verb|CLASSPATH| environment variable, if it's set. + \item Make sure that you're spelling the class name exactly the same as it's declared. + \item Also, some programmers use different names for the class name from the \verb|.java| filename. + Make sure that you're using the class name and not the filename. + \end{itemize} + + \item Problem: The interpreter says that it can't find one of my classes. + \begin{itemize} + \item Make sure that you specified the class name, not the class file name, to the interpreter. + \item Unset the \verb|CLASSPATH| environment variable, if it's set. + \item If your classes are in packages, make sure that they appear in the correct sub-directory. + \item Make sure that you're invoking the interpreter from the directory in which the \verb|.class| file is + located. + \end{itemize} + + \item Generally, don't compare floating-point numbers using \verb|==|. + Remember that floats are only approximations of the real thing, so therefore, the greater than \& less than + operators (\verb|>| \& \verb|<|) are often more appropriate when conditional logic is performed on floating-point + numbers. + \item Don't overuse the negation operator \verb|!| as it can be confusing \& error-prone. +\end{itemize} + +\section{Testing} +\textbf{Testing} is the systematic process of analysing a system or system component to detect the differences between +specified (required) behaviour \& observed (existing) behaviour. +Testing attempts to show that the implementation of a system is inconsistent with the desired functionality. +The goal is to design tests that exercise defects in the system and to reveal problems. +We cannot test everything in a large system, so there are always trade-offs required with budget \& time constraints. + +\subsection{Levels of Testing} +\begin{itemize} + \item \textbf{Unit testing} involves testing individual classes \& mechanisms. + \item \textbf{Integration testing} involves testing groups of classes or components and the interfaces between them. + \item \textbf{System testing} involves integration testing the system as a whole to check it meets the requirements. +\end{itemize} + +\subsection{Test-Driven Development (TDD)} +\textbf{Test-Driven Development (TDD)} is a software development process that relies on the repetition of a very short +development cycle. +The general rationale behind this methodology is ``first write the test, then the code'' such that the tests \emph{drive} the +development of your code. +TDD tries to find faults in participating objects and/or sub-systems with respect to the use cases from the use case model. +\begin{figure}[H] + \centering + \includegraphics[width=0.6\textwidth]{./images/tdd_cycle.png} + \caption{The TDD Cycle} +\end{figure} + +Any test will initially fail; We then write the minimum amount of code to make our test pass. +We refactor our application and test the code before moving onto the next test. +We build a test suite as our implementation progresses. + +\subsubsection{Test Cases} +A \textbf{test component} is a part of the system that can be isolated for testing. +This could be an object, a group of objects, or one or more subsystems. +\textbf{Unit testing} finds differences between a specification of an object and its realisation as a component. +\textbf{JUnit} is a unit testing framework for test-driven development in Java, which is available in Eclipse out-of-the-box. +\\\\ +A \textbf{test case} is a set of inputs \& expected results that exercises a test component with the purpose of causing +failures \& detecting faults. +\textbf{Black box tests} focus on the input/output behaviour of the component, i.e. the functionality, not the internal aspects. +\textbf{White box tests} focus on the internal structure \& dynamics of the component. +\begin{figure}[H] + \centering + \includegraphics[width=0.6\textwidth]{./images/tdd_cycle_oo.png} + \caption{The TDD Cycle in Object-Oriented Development} +\end{figure} + +\subsubsection{Assert Methods} +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +assertTrue(boolean test) +assertTrue(String message, boolean test) + +assertFalse(boolean test) +assertFalse(String message, boolean test) + +assertEquals(Object expected, Object actual) +assertEquals(String message, Object expected, Object actual) + +assertSame(Object expected, Object actual) +assertSame(String message, Object expected, Object actual) + +assertNotSame(Object expected, Object actual) +assertNotSame(String message, Object expected, Object actual) + +assertNull(Object object) +assertNull(String message, Object object) + +assertNotNull(Object object) +assertNotNull(String message, Object object) + +fail() +fail(String message) +\end{minted} +\end{code} + +\section{Throwing \& Handling Exceptions} +Alternatives to exception handling include using no error handling or just exiting the application on error. + +\subsection{Basics of Java Exception Handling} +Code that could generate errors are put in \verb|try| blocks, and the code for handling the error are enclosed in a +subsequent \verb|catch| block. +The \verb|finally| block always executes with or without an error. +The \verb|throws| keyword is used to specify the exceptions which a method might throw if a problem occurs. +An exception is thrown when a method detects an error, the exception handler processes the error. +The error is thus considered \textbf{caught} \& \textbf{handled} in this model. +Control moves from the \verb|try| blocks to the \verb|catch| block(s). + +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +try { + // statements that may throw an exception +} +catch (ExceptionType exceptionReference) { + // statemetns to process the exception +} +// a `try` is followed by any number of `catch` blocks +catch (ExceptionType exceptionReference) { + // statemetns to process the exception +} +\end{minted} +\caption{\texttt{try} Blocks} +\end{code} + +\subsection{Throwing \& Catching Exceptions} +The \verb|throw| statement is used to indicate that an exception has occurred. +The operand of the \verb|throw| statement is any class that is derived from the class \verb|Throwable|. +The sub-classes of \verb|Throwable| are \verb|Exception| (used for problems that should be caught) \& \verb|Error| +(used for serious problems that should not be caught). +\\\\ +An exception is caught by a \textbf{handler}. +The program will terminate if there is no appropriate handler for an exception. +A single \verb|catch| statement can handle multiple exceptions. +\\\\ +The \verb|throws| clause lists the exceptions thrown by a method. +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +int functionName (paremeterList) throws ExceptionType1, ExceptionType2 { + // method body +} +\end{minted} +\caption{\texttt{throws} Clause} +\end{code} + +\verb|RunTimeExceptions| occur during the execution of a program, e.g. \verb|ArrayIndexOutOfBoundsException| \& \\ +\verb|NullPointerException|. + +\subsection{Checked \& Unchecked Exceptions} +\textbf{Unchecked Exceptions} (or runtime exceptions) represent unrecoverable errors that occur during the execution of a +program. +These include sub-classes of \verb|RuntimeException| such as \verb|NullPointerException|. +(A full list of runtime exceptions can be found here: \url{https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html}) +It is not necessary to add the \verb|throws| declaration for this type of exceptions and it is not necessary to handle +them. +\\\\ +\textbf{Checked Exceptions} are caught at compile time. +All exceptions other than sub-classes of \verb|RuntimeException| are checked exceptions. +An example of a checked exception is \verb|FileNotFoundException|. +Checked exceptions are predictable \& recoverable. +They must be handled in the method body, either with a \verb|try|/\verb|catch| statement or by re-throwing. +It is necessary to add the \verb|throws| declaration for this type of exceptions + +\subsection{Finalizers} +We can throw an exception if a constructor causes an error. +The \verb|finalize| method is called the first time that garbage collection is attempted on an object. +It will be called a maximum of one times (regardless of whether or not the garbage collection was successful), but +won't necessarily ever be called. +However, since this won't necessarily be called, it's better not to use it when a resource needs to be released. +Instead, one should use the \verb|finally| statement after a \verb|try|/\verb|catch| block. +This always executes, and can be used to release resources. + +\subsection{Exception Methods} +The \verb|printStackTrace()| method of an exception is used to print the method call stack. +The \verb|getMessage()| method retrieves the \verb|informationString| from an exception. + +\section{Unit Testing in Java} +We should test single units of functionality in isolation. +Unit tests are not integration tests. +There should be multiple tests for a single piece of logic, one for each scenario. +Each test will cover a single scenario and a single piece of logic. + +\subsection{Unit Testing Techniques} +\subsubsection{Equivalence Testing} +In \textbf{equivalence testing}, possible inputs are partitioned into equivalence classes and a test case is selected for +each class. +This minimises the number of test cases. +Systems usually behave in similar ways for all members of a class. + +\subsubsection{Boundary Testing} +\textbf{Boundary testing} is a special case of equivalence testing that focuses on the conditions at the boundary of the +equivalence classes. +Instead of selecting any element in the equivalence class, boundary testing requires that the elements be selected from the +``edges'' of the equivalence class. +The assumption is that developers often overlook special cases at the boundary of the equivalence classes. + +\subsubsection{Path Testing} +\textbf{Path testing} exercises all the possible paths through the code at least once, which should cause most faults to +trigger failures. +This requires knowledge of the source code \& data structures. +\\\\ +\textbf{Code coverage} is a measure of how many lines of your code are executed by automated tests. +It is impractical to achieve 100\% code coverage for large projects. + +\subsection{Testing Code with Dependencies} +Often, the application logic that we want to test will have some dependencies on external services or components. +In Unit Testing, we want to isolate our component under test from any dependencies (otherwise, we would be doing +\textbf{integration testing}). +This is problematic as our application logic won't work without its dependencies. +The solution to this problem is to create a \textbf{stub} to simulate the functionality of this external component. + +\subsection{TDD Guidelines} +\begin{itemize} + \item Test the expected outcomes of an example. + \item Think about examples \& outcomes, not code or how it should work in detail. + \item Don't pre-judge design -- let your tests drive it. + \item Write the minimum code to get your tests to pass. + \item Each test should validate one single piece of logic. +\end{itemize} + +\section{Strings} +Strings allow us to store alphanumeric characters within a variable. +In Java, you do not use the \verb|'\0'| (null) character to indicate the end of a \verb|String| object, as you would in C or +C++. +The \verb|String| object itself keeps track of the number of characters it contains. +The \verb|String| \verb|length()| method is the number of characters that a \verb|String| object contains. +\begin{itemize} + \item \verb|int length()| returns the length of the \verb|String|. + \item \verb|char charAt(int index)| returns the \verb|char| value at the specified index. + \item \verb|boolean isBlank()| returns \verb|true| if the \verb|String| is empty or contains only whitespace codepoints, + otherwise it returns \verb|false|. + \item \verb|boolean startsWith(String prefix)| tests if the \verb|String| starts with the specified prefix. + \item \verb|boolean matches(string regex)| tells whether or not the \verb|String| matches the given regular expression. +\end{itemize} + +\subsection{Creating Strings} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +String myString = "Hello world!"; +String myString = new String(); +char [] ct326Array = { ‘C', ‘T', ‘3', ‘2', ‘6' }; +String ct326String = new String(ct326Array); + +String fs = tring.format("The value of the float variable is %f, while the value of the integer variable is %d, and the string is %s", floatVar, intVar, stringVar); +\end{minted} + +\subsection{Concatenating Strings} +The \verb|+| operator lets your program concatenate one String's contents onto another. +When you concatenate a numeric value, e.g. of type \verb|int| or \verb|float|, Java automatically calls a method called +\verb|toString()| on the numeric value to convert the value into a character String. +To simplify the output of class-member variables, you can write a \verb|toString()| method for the classes you create; +In the same way as for built-in types, the \verb|toString| method will be called automatically for your class. +The \mintinline{Java}{String concat(String str)} method of the \verb|String| class concatenates the specified String to the +end of this String. + +\subsection{Comparing Strings} +The \mintinline{Java}{int compareTo(String anotherString)} \verb|String| method compares two \verb|String|s lexicographically. + +The \mintinline{Java}{boolean equalsIgnoreCase(String anotherString)} \verb|String| method compares this \verb|String| to +another \verb|String|, ignoring letter case. + +\subsection{Manipulating Strings} +\begin{itemize} + \item \mintinline{Java}{String substring(int beginIndex, int endIndex)} returns a \verb|String| that is a sub-String + of the \verb|String| on which the method was called. + \item \mintinline{Java}{String [] split(String regex)} splits the \verb|String| around matches of the given + regular expression + \item \mintinline{Java}{String strip()} returns this \verb|String| but with all leading \& trailing whitespace removed. + \item \mintinline{Java}{String replace(char oldChar, char newChar)} returns a \verb|String| resulting from replacing all + of \verb|oldChar| in this \verb|String| with \verb|newChar|. +\end{itemize} + +\subsection{String Handling} +\verb|String| objects are \textbf{immutable} -- They cannot be changed once they've been created. +The \verb|java.lang| package provides a different class, \verb|StringBuffer|, which you can use to create \& manipulate +character data on the fly. + +\section{Nested Classes} +In Java, it is possible to define a class as a member of another class. +Such a class is called a \textbf{nested class} and is of the following form: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +class EnclosingClass { + ... + class ANestedClass { + ... + } +} +\end{minted} + +Nested classes are used to reflect \& to enforce the relationship between two classes. +You should define a class within another class when the nested class makes sense only in the context of its enclosing +class or when it relies on the enclosing class for its function. +For example, a text cursor might only make sense in the context of a text component. +\\\\ +As a member of its enclosing class, a nested class has a special privilege: it has unlimited access to its enclosing +class's members, even if they are declared \verb|private|. + +\subsection{Static \& Inner Classes} +Like other class members, a nested class can be declared \verb|static|: +\begin{itemize} + \item A static nested class is simply called a \textbf{static nested class}. + \item A non-static nested class is just called an \textbf{inner class} +\end{itemize} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +class EnclosingClass { + ... + static class StaticNestedClass { + ... + } + class InnerClass { + ... + } +} +\end{minted} + +As with static methods \& variables (which we call class methods \& variables), a static nested class is associated with +its enclosing class. +Like class methods, a static nested class cannot refer directly to instance variables or methods defined in its +enclosing class; It can only use them through an object reference. +As with instance methods \& variables, an inner class is associated with an instance of its enclosing class and has +direct access to that object's instance variables \& methods. +\\\\ +The interesting feature of the relationship between the inner class \& the enclosing class is \emph{not} that the inner +class is syntactically defined within the enclosing class. +Rather, it's that an instance of the inner class can only exist within an instance of the enclosing class, and that it +has direct access to the instance variables \& methods of its enclosing instance. +You may encounter nested classes of both static \& inner types in the Java platform API and be required to use them. +However, most nested classes that you write will probably be \textbf{inner classes}. + +\subsection{Using Anonymous Inner Classes} +Using a Tokenizer, partition a \verb|String| into individual sub-strings using a \textbf{delimiter}. +To do this, Java offers \\ \verb|java.util.StringTokenizer| + +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +// Fig. 10.20: TokenTest.java +// Testing the StringTokenizer class of the java.util package + +// Java core packages +import java.util.*; +import java.awt.*; +import java.awt.event.*; + +// Java extension packages +import javax.swing.*; + +public class TokenTest extends JFrame { + private JLabel promptLabel; + private JTextField inputField; + private JTextArea outputArea; + + // set up GUI and event handling + public TokenTest() + { + super( "Testing Class StringTokenizer" ); + + Container container = getContentPane(); + container.setLayout( new FlowLayout() ); + + promptLabel = new JLabel( "Enter a sentence and press Enter" ); + container.add( promptLabel ); + + inputField = new JTextField( 20 ); // inputField contains String to be parsed by StringTokenizer + + inputField.addActionListener( + // anonymous inner class + new ActionListener() { + // handle text field event + public coid actionPerformed(ActionEvent event) + { + String stringToTokenize = event.getActionCommand(); + StringTokenizer tokens = new StringTokenizer( stringToTokenize ); // Use StringTokenizer to parse String stringToTokenize with default delimiters "{\textbackslash}n{\textbackslash}t{\textbackslash}r" + + outputArea.setText( "Number of elements: " + tokens.countTokens() + "\nThe tokens are:\n" ); // count number of tokens + + // apend next token to outputArea as long as tokens exist + while ( tokens.hasMoreTokens() ) + outputArea.append( tokens.nextToken() + "\n" ); + } + } // end anonymous inner class + ); // end call to addActionListener + + container.add( inputField ); + + outputArea = new JTextArea( 10, 20 ); + outputArea.setEditable( false ); + container.add( new JScrollPane( outputArea ) ); + + setSize( 275, 260 ); // set the window size + show(); // show the window + } + + // execute application + public static void main( String args[] ) + { + TokenTest application = new TokenTest(); + application.addWindowListener( + // anonymous inner class + new WindowAdapter() { + // handle event when user closes window + public void windowClosing( WindowEvent windowEvent ) + { + System.exit( 0 ); + } + } // end anonymous inner class + ); // end call to addWindowListener + } // end method main +} // end class TokenTest +\end{minted} +\caption{\texttt{TokenTest.java}} +\end{code} + +\section{Enums} +An \textbf{enumerated type} is a type whose legal values consist of a fixed set of constraints. +Common examples include the cardinal directions, the days of the week, etc. +In Java, you define an enumerated type by using the \verb|enum| keyword. +For example, you would specify a days-of-the-week enumerated type as: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }; +\end{minted} +Note that by convention, the names of an enumerated type's values are spelled in all uppercase letters.] +Enumerated types should be used any time that you need to represent a fixed set of constraints. +\\\\ +Enumerated types in Java are much more powerful than their counterparts in other languages, such as C, which are just +glorified integers. +In Java, the \verb|enum| declaration defines a class called an \textbf{enum type}. +These are the most important properties of enum types: +\begin{itemize} + \item Printed values are informative. + \item They are type-safe and exist in their own namespace. + \item You can \verb|switch| on an enumeration constant. + \item They have a static \verb|values()| method that returns an array containing all of the values of the enum type + in the order they are declared. + This method is commonly used in combination with the for-each construct to iterate over the values of an + enumerated type. + \item You can provide methods \& fields, implement interfaces, and more. +\end{itemize} + +Note that the constructor for an \verb|enum| type is implicitly private. +If you attempt to create a public constructor for an enum type, the compiler displays an error message. + +\subsection{Example} +In the following example, \verb|Planet| is an enumerated type that represents the planets in our solar system. +A \verb|Planet| has constant mass \& radius properties. +Each enum constant is declared with values for the mass \& radius parameters that are passed to the constructor when it is +created. +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +public enum Planet { + MERCURY (3.303e+23, 2.4397e6), + VENUS (4.869e+24, 6.0518e6), + EARTH (5.976e+24, 6.37814e6), + MARS (6.421e+23, 3.3972e6), + JUPITER (1.9e+27, 7.1492e7), + SATURN (5.688e+26, 6.0268e7), + URANUS (8.686e+25, 2.5559e7), + NEPTUNE (1.024e+26, 2.4746e7), + PLUTO (1.27e+22, 1.137e6); + + private final double mass; //in kilograms + private final double radius; //in meters + + Planet(double mass, double radius) { + this.mass = mass; + this.radius = radius; + } + + public double mass() { return mass; } + public double radius() { return radius; } + public static final double G = 6.67300E-11; //universal gravitational constant (m3 kg-1 s-2) + + public double surfaceGravity() { + return G * mass / (radius * radius); + } + + public double surfaceWeight(double otherMass) { + return otherMass * surfaceGravity(); + } +} +\end{minted} +\caption{\texttt{Planet} Enumerated Type Example} +\end{code} + +In addition to its properties, \verb|Planet| has methods that allow you to retrieve the surface gravity \& weight of an +object on each planet. +Here is a sample program that takes you weight on Earth in any unit and calculates \& prints your weight on all of the +planets in the same unit. +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{Java} +public static void main(String[] args) { + double earthWeight = Double.parseDouble(args[0]); + double mass = earthWeight/EARTH.surfaceGravity(); + + for (Planet p : Planet.values()) { + System.out.printf("Your weight on %s is %f%n", p, p.surfaceWeight(mass)); + } +\end{minted} +\caption{Sample Program Using the \texttt{Planet} Enumerated Type} +\end{code} + +The output is as follows: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{text} +$ java Planet 175 + Your weight on MERCURY is 66.107583 + Your weight on VENUS is 158.374842 + Your weight on EARTH is 175.000000 + Your weight on MARS is 66.279007 + Your weight on JUPITER is 442.847567 + Your weight on SATURN is 186.552719 + Your weight on URANUS is 158.397260 + Your weight on NEPTUNE is 199.207413 + Your weight on PLUTO is 11.703031 +\end{minted} + +The limitation of \verb|enum| types is that, although \verb|enum| types are classes, you cannot define a hierarchy of enums. +In other words, it's not possible for one enum type to extend another enum type. + +\section{Packages} +A \textbf{package} is a collection of related types (such as classes, interfaces, enums, \& annotations) providing access +protection \& namespace management. +Programmers bundle groups of related types into packages to make them easier to find \& use, to avoid naming +conflicts, and to control access. +The types that are part of the Java platform are members of various packages that bundle classes by function, such as +fundamental classes in \verb|java.lang|, classes for reading \& writing in \verb|java.io|, etc. +Related types should be bundled into a package for several reasons: +\begin{itemize} + \item Packages allow programmers to easily determine that the types which they contain are related. + \item The names of the types in the package won't conflict with the names of types in other packages because the + package creates a new namespace. + \item One can allow types within the package to have unrestricted access to one another yet still restrict access for + types outside the package (package private access). +\end{itemize} + +\subsection{Creating Packages} +To create a package, you simply put a type (such as a class, interface, enum, or annotation) in a directory corresponding +to the name of the package that you want to create and put a \textbf{package statement} at the top of the source file in +which the type is defined. +You must include a package statement at the top of every source file that defines a class or an interface that is to be the +member of your package, and the name of the package must correspond to that of the directory. + +\subsection{Package Scope} +The copse of the package statement is the entire source file, including all the classes, interface, enums, \& annotations +defined in the file. +If there are multiple classes in a single source file, only one may be public, and it must share the name of the source +file's base name. +Only public package members are accessible from outside the package. +If you do not use a package statement, your type will be treated as part of the \textbf{default package} which is a package +that has no name. + +\subsection{Naming Packages} +With programmers all over the world defining types in Java, it is not unlikely that two programmers will use the same name +for two different types, but conflicts can be circumvented via the use of packages. +If the types are in different packages, no conflict will occur, as the fully-qualified name of each type includes the +package name. +This generally works fine, unless two independent programmers use the same name for their packages. +This problem is prevented by convention: companies will, by convention, use to their reversed Internet domain name in their +package names, e.g. \verb|com.company.package|. +Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including +the region or the project name after the company name, e.g. \verb|com.company.region.package|. + +\subsection{Static Imports} +The \textbf{static import} feature, implemented as \verb|import static | enables you to refer to the static constants +from a class without needing to inherit from it. + +\section{Useful Java Features} +\subsection{For-Each Loops} +The \verb|Iterator| class provides a mechanism to navigate sequentially through a Collection; it is used heavily by the +Collections API. +The \textbf{For-Each loop} can replace the Iterator when simply traversing though a Collection -- the compiler +generates the looping code required with generic types so that no additional casting is required. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +ArrayList list = new ArrayList(); + +// looping though an ArrayList using the Iterator class +for (Iterator i = list.iterator(); i.hasNext();) { + Integer value = (Integer) i.next(); + // do some stuff +} + +// looping though an ArrayList using a For-Each loop +for (Integer i : list) { + // do some stuff +} +\end{minted} + +\subsection{Formatted Input \& Output} +Developers have the option of using \verb|printf|-type functionality to generate formatted output. +Most of the common C \verb|printf| formatters are available, and some classes like \verb|Data| \& \verb|BigInteger| also +have formatting rules. +Although the standard UNIX newline \verb|'\n'| character is accepted, the Java \verb|%n| is recommended for cross-platform +support. +See the \verb|java.util.Formatter| class for more information. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +System.out.printf("name count%\n"); +System.out.printf("%s %5d%\n", user, total); +\end{minted} + +The Scanner API provides basic input functionality for reading data from the system console or any data stream. +If you need to process more complex input, then there are also pattern-matching algorithms available from the +\verb|java.util.Formatter| class. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +Scanner s = new Scanner(System.in); +String param = s.next(); +int value = s.nextInt(); +s.close(); +\end{minted} + +\subsection{Varargs} +\textbf{Varargs} can be used to indicate that a flexible number of arguments is required for a given method, which allows +us to pass an unspecified number of arguments to the method. The built-in \verb|printf()| function makes use of varargs. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +void argtest(Object... args) { + for (int i = 0; i < args.length; i++) { + + } +} + +argtest("test", "data"); +\end{minted} + +% not in lecture slides, but there should be a javadoc explanation + +\section{Lambda Expressions} +A \textbf{lambda expression} is a short block of code that takes parameters and returns a value; they are similar to methods +but lambda expressions do not require a name. +Lambda expressions can be implemented in the body of a method. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +parameter -> expression +(parameter1, parameter2) -> expression +\end{minted} + +For example, to print out all the elements of an Iterable data structure: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +elements.forEach(e -> System.out.println(e)); +\end{minted} + +\section{IO Streams} +To take in information, a program opens a \textbf{stream} on an information source (such as a file, memory, or a +socket) and reads the information \textbf{serially}. +No matter where the information is coming from or going to and what type of data is being read or written, the +algorithms for reading \& writing data are usually the same: +\begin{itemize} + \item \textbf{Reading:} + \begin{enumerate} + \item Open a stream. + \item While there is more information: read information. + \item Close the stream. + \end{enumerate} + \item \textbf{Writing} + \begin{enumerate} + \item Open a stream. + \item While there is more information: write information. + \item Close the stream. + \end{enumerate} +\end{itemize} + +The \verb|java.io| package contains a collection of stream classes that support reading \& writing streams. +The stream classes are divided into two class hierarchies based off their data: \textbf{character streams} or +\textbf{byte streams}. +However, it is often more convenient to group the classes by their purpose rather than the type of data that they +handle, so we often cross-group the streams by whether they read data from \& write data to \textbf{data sinks} or +process the information as it's being read or written. + +\subsection{Data Sink Streams} +\textbf{Data sink streams} read from or write to specialised \textbf{data sinks} such as Strings, files, or pipes. +Typically, for each reader or input stream intended to read from a specific kind of input source, \verb|java.io| +contains a parallel writer or output stream that can create it. +Note that both the character stream group and the byte stream group contain parallel pairs of classes that +operate on the same data sinks. + +\subsection{Processing Streams} +\textbf{Processing streams} perform some kind of operations such as buffering or data conversion as they read \& +write. +Like the data sink streams, \verb|java.io| often contains pairs of streams: one that performs a particular +operation during reading and one that performs the same operation or reverses it during writing. +Note that in many cases, \verb|java.io| contains character streams \& byte streams that perform the same +processing but for different data types. + +\subsection{Byte Streams} +Programs should use \textbf{byte streams}, descendants of \verb|InputStream| \& \verb|OutputStream| to read \& +write 8-bit bytes. +\verb|InputStream| \& \verb|OutputStream| provide the API and some implementation for input streams (streams that +read 8-bit bytes and output streams (streams that write 8-bit bytes). +These streams are typically used to read \& write binary data such as images and sounds. +\\\\ +Subclasses of \verb|InputStream| \& \verb|OutputStream| provide specialised I/O. +Those that read from or write to data sinks are shown in grey in the following figures, while those that +perform some sort of processing are shown in white: +\begin{figure}[H] + \centering + \includegraphics[width=0.7\textwidth]{./images/InputStream.png} + \caption{Data Sink \& Processing Subclasses of \texttt{InputStream}} +\end{figure} +\begin{figure}[H] + \centering + \includegraphics[width=0.7\textwidth]{./images/OutputStream.png} + \caption{Data Sink \& Processing Subclasses of \texttt{OutputStream}} +\end{figure} + +\subsection{Character Streams} +\verb|Reader| \& \verb|Writer| are the abstract superclasses for character streams in \verb|java.io.*|. +\verb|Reader| provides the API \& partial implementation for readers, i.e. streams that read 16-bit Unicode +characters and \verb|Writer| provides the API \& partial implementation for writers, i.e. streams that write +16-bit characters. +Subclasses of \verb|Reader| \& \verb|Writer| implement specialised streams. +\\\\ +The following figures show the readers or writers that read/write to/from data sinks in grey, and those that +performs some sort of processing are shown in white: +\begin{figure}[H] + \centering + \includegraphics[width=0.7\textwidth]{./images/Reader.png} + \caption{Data Sink \& Processing Subclasses of \texttt{Reader}} +\end{figure} +\begin{figure}[H] + \centering + \includegraphics[width=0.7\textwidth]{./images/Writer.png} + \caption{Data Sink \& Processing Subclasses of \texttt{Writer}} +\end{figure} + +Most programs should use readers \& writers to read \& write information because they can handle any character +in the Unicode character set whereas byte streams are limited to ISO-Latin-1 8-bit bytes. + +\subsection{\texttt{Scanner}} +The \textbf{\texttt{Scanner}} class is in the \verb|java.util| package but can be passed an \verb|InputStream| as a +constructor parameter. +Scanners are often used for reading from the console, i.e. the \verb|System.in| InputStream. +They are used for working with inputs of formatted data consisting of primitive types \& Strings. +Scanners translate the input to tokens based on their data type and using a delimiter pattern. +They also have a collection of \verb|next()| methods for different data types. + +\subsection{Formatting} +\verb|PrintWriter| is a processing character stream that includes common methods for formatting such as +\verb|print|, \verb|println|, \& \verb|format|. +The \verb|format| method formats multiple arguments based on a \textbf{format String} that includes format specifiers, +which can be used similar to tokens in Scanners. +See the \verb|java.util.Formatter| class for documentation on format String syntax. + +\section{Object Serialization} +The streams \verb|java.io.ObjectInputStream| \& \verb|java.io.ObjectOutputStream| are special in that they can +read and write actual objects. +The key to writing an object is to represent its state in a serialized form sufficient to reconstruct the object +as it is read. +Thus reading \& writing objects is a process called \textbf{object serialization}. +Object serialization can be useful in a lot of application domains. +\\\\ +Uses of serialization include: +\begin{itemize} + \item \textbf{Remote Method Invocation (RMI)}: communication between objects via sockets, e.g. to pass + various objects back \& forth between the client \& server. + \item \textbf{Lightweight persistence}: the archival of an object for use in a later invocation of the same + program +\end{itemize} + +Reconstructing an object from a stream requires that the object first be written to a stream; writing objects to +a stream is a straightforward process. +The following code sample gets the current time in milliseconds by constructing a \verb|Date| object and then +serializes the object. +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +FileOutputStream out = new FileOutputStream("theTime"); +ObjectOutputStream s = new ObjectOutputStream(out); +s.writeObject("Today"); +s.writeObject(new Date()); +s.flush(); +\end{minted} +\caption{Object Serialization Example} +\end{code} + +The above code constructs an \verb|ObjectOutputStream| on a \verb|FileOutputStream|, thereby serializing the +object to a file named \verb|theTime|. +Next, the String \verb|Today| \& a \verb|Date| object are written to the stream with the \verb|writeObject| +method of \verb|ObjectOutputStream|. + +\subsection{Object Serialization with Related Objects} +if an object refers to other objects, then all of the objects that are reachable from the first must be written +at the same time so as to maintain the relationships between them. +Thus, the \verb|writeObject| method serializes the specified object, traverses its references to other objects +recursively, and writes them all. +The \verb|writeObject| method throws a \verb|NotSerializableException| if it's given an object that is not +serializable. +An object is serializable only if its class implements the \verb|Serializable| interface. + +\subsection{Reconstructing Serialized Objects} +Once you've written objects \& primitive data types to a stream, you'll likely want to read them out again and +reconstruct the objects. +The below code reads in the \verb|String| \& the \verb|Date| object that was written to the file named +\verb|theTime| in the previous example: +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +FileInputStream in = new FileInputStream("theTime"); +ObjectInputStream s = new ObjectInputStream(in); +String today = (String) s.readObject(); +Date date = (Date) s.readObject(); +\end{minted} +\caption{Object Reconstruction Example} +\end{code} + +Note that there is no standard file extension for files that store serialized objects. +\\\\ +Like \verb|ObjectOutputStream|, \verb|ObjectInputStream| must be constructed on another stream. +In this example, the objects were archived in a file, so the code constructs an \verb|ObjectInputStream| on a +\verb|FileInputStream|. +Next, the code uses the \verb|readObject| of the \verb|ObjectInputStream| method to read the \verb|String| \& +\verb|Date| objects from the file. +The objects must be read from the stream in the same order in which they were written. +Note that the return value from \verb|readObject| is an object that is cast to and assigned to a specific type. +The \verb|readObject| method deserializes the next object in the stream and traverses its references to other +objects recursively to deserialize all objects that are reachable from it. +In this way, it maintains the relationships between objects. +The methods in \verb|DataInput| parallel those defined in \verb|DataOutput| for writing primitive data types. + +\subsection{Serializing Classes} +AN object is serializable only its class implements the \verb|Serializable| interface. +Thus, if you want to serialize an instance of one of your classes, the class must implement the +\verb|Serializable| interface, i.e. it must have the \mintinline{java}{implements Serializable} clause. +\verb|Serializable| is an empty interface, i.e. it does not contain any method declarations; its purpose is +simply to identify classes whose objects are serializable. +Its complete definition is as follows: +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +package java.io; + +public interface Serializable { + // there's nothing in here! +}; +\end{minted} +\caption{Definition of the \texttt{Serializable} Interface} +\end{code} + +You don't have to write any methods to make a class serializable. +The serialization of instances of a serializable class are (by default) handled by the \verb|defaultWriteObject| +method of the \verb|ObjectOutputStream|. +\\\\ +All instance variables of a class must be serialized for it to be serializable, including referenced objects +\& those within referenced data structures +In Java, all primitive type variables are serializable by default. +We can ignore instance variables in the process by declaring them as \verb|transient| + +\subsection{The \texttt{defaultWriteObject} Method} +The \verb|defaultWriteObject| method automatically writes out everything required to reconstruct an instance +of the class, including the class of the object, the class signature, and values of non-transient \& non-static +members, including members that refer to other objects. +For many classes, the default behaviour is fine. +However, default serialization can be slow, and a class might want more explicit control over the serialization. + +\subsection{Customising Serialization} +You can customise serialization for your classes by providing two methods: \verb|writeObject| \& +\verb|readObject|. +The \verb|writeObject| method controls what information is saved and is typically used to append additional +information to the stream. +The \verb|readObject| method either reads the information written by the corresponding \verb|writeObject| +method or can be used to update the state of the object after it has been restored. +\\\\ +The \verb|writeObject| method must be declared exactly as follows. +Note that it should call the stream's \verb|defaultWriteObject| as the first thing it does to perform +default serialization (any special arrangements can be handled afterwards): +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +ptivate void writeObject(ObjectOutputStream s) throws IOException { + s.defaultWriteObject(); + // customised serialization code +} +\end{minted} +\caption{Declaration of the \texttt{writeObject} Method} +\end{code} + +The \verb|readObject| method must read in everything written by \verb|writeObject| in the same order in which +it was written. +The following \verb|readObject| method corresponds to the above \verb|writeObject| method: +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +private void readObject(ObjectInputStream s) throws IOException { + s.defaultReadObject(); + // customised deserialization code + // followed by code to update the object if necessary +} +\end{minted} +\caption{Declaration of the \texttt{readObject} Method} +\end{code} + +The \verb|readObject| method can also perform calculations or update the state of the object in some way. +The \verb|writeObject| \& \verb|readObject| methods are responsible for serializing only the immediate class. +Any serialization required for the superclasses is handled automatically. +However, a class that needs to explicitly co-ordinate with its superclasses to serialize itself can do so by +implementing the \verb|Externalizable| interface. + +\subsubsection{The \texttt{Externalizable} Interface} +For complete, explicit control over the serialization process, a class must implement the +\verb|Externalizable| interface. +For \verb|Externalizable| objects, only the identify of the object's class is automatically saved by the +stream. +The class is responsible for reading \& writing its contents, and it must co-ordinate with its superclasses +to do so + +\section{Random File Access} +The input \& output streams that we have been dealing with so far have been \textbf{sequential access streams}, +i.e. streams whose contents must be read or written sequentially. +Sequential access files are a hangover from sequential media such as magnetic tape, but are still very useful +today. +\textbf{Random access files} permit non-sequential (or random) access to the contents of a file. + +\subsection{Random File Access Example Use Case} +Consider the ``zip'' archive format. +Zip archives contain files and are typically compressed to save space. +Zip archives also contain a \verb|dir-entry| at the end of the file that indicates where the various files +contained within the zip archive begin: +\begin{figure}[H] + \centering + \includegraphics[width=0.7\textwidth]{./images/dir-entry.png} + \caption{Zip Archive Format} +\end{figure} + +Suppose that you want to extract a specific file from a zip archive. +If you use a sequential access stream, you have to do the following: +\begin{enumerate} + \item Open the zip archive. + \item Search through the zip archive until you have located the file that you want to extract. + \item Extract the file. + \item Close the zip archive. +\end{enumerate} + +Using this algorithm, you'd have to read half the zip archive on average before finding the file that you +want to extract. +You can extract the same file from the zip archive more efficiently using the \textbf{seek} feature of a +random access file: +\begin{enumerate} + \item Open the zip archive. + \item Seek to the \verb|dir-entry| and locate the entry for the file you want to extract from the zip + archive. + \item Seek backwards within the zip archive to the position of the file to extract. + \item Extract the file + \item Close the zip archive. +\end{enumerate} + +This algorithm is more efficient because you only read the \verb|dir-entry| and the file that you want to +extract. + +\subsection{The \texttt{RandomAccessFile} Class} +The \verb|RandomAccessFile| class in the \verb|java.io| package implements a random access file. +Unlike the input \& output stream classes in \verb|java.io|, \verb|RandomAccessFile| is used for both +reading \& writing files; it implements both the \verb|DataInput| \& \verb|DataOutput| interfaces and therefore +can be used for both reading \& writing. +\\\\ +We create \verb|RandomAccessFile| objects with different arguments depending on whether you intend to read or +write. +\verb|RandomAccessFile| is similar to \verb|FileInputStream| \& \verb|FileOutputStream| in that you specify +a file on the native file system to open, either with a filename or a \verb|File| object. +When you create \verb|RandomAccessFile|, you must indicate whether you will be reading the file or also +writing to it. +The following code snippet creates a \verb|RandomAccessFile| to read the file named \verb|farrago.txt|: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +new RandomAccessFile("farrago.txt", "r"); +\end{minted} + +The following code snippet opens the same file for both reading \& writing: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +new RandomAccessFile("farrago.txt", "rw"); +\end{minted} + +After the file has been opened, you can use the common read \& write method to perform I/O on the file. +The \verb|RandomAccessFile| class supports the notion of a file pointer, which indicates the current location +in the file. +When the file is first created, the file pointer is \verb|0|, indicating the start of the file. +Calls to the read \& write methods adjust the file pointer by the number of bytes read or written. +\\\\ +In addition to the normal file I/O methods that implicitly move the file pointer when the operation occurs, +\verb|RandomAccessFile| also contains three methods for explicitly manipulating the file pointer: +\begin{itemize} + \item \verb|skipBytes()|: moves the file pointer forward the specified number of bytes. + \item \verb|seek()|: positions the file pointer just before the specified byte. + \item \verb|getFilePointer()|: returns the current byte location of the file pointer. +\end{itemize} + +\verb|RandomAccessFile| is somewhat disconnected from the input \& output streams in \verb|java.io|: it +doesn't inherit from either \verb|InputStream| or \verb|OutputStream|. +This has some disadvantages in that you can't apply the same filters to \verb|RandomAccessFile|s that you can +However, \verb|RandomAccessFile| does implement the \verb|DataInput| \& \verb|DataOutput| interfaces: +if you design a filter that works for either \verb|DataInput| or \verb|DataOutput|, it will work on any +\verb|RandomAccessFile|. + +\section{Type-Wrapper Classes} +Collections manipulate \& store \textbf{Objects}, not primitive types. +Each Java primitive type has a corresponding \textbf{type-wrapper class} in \verb|java.lang| that enables primitives to be manipulated as Objects, e.g. +\verb|Boolean|, \verb|Byte|, \verb|Character|, \verb|Double|, \verb|Float|, \verb|Integer|, \verb|Long|, \verb|Short|. +Numeric type-wrapper classes extend the \verb|Number| class. +Methods related to primitive types are contained in the type-wrapper classes, e.g. \verb|parseInt| is located in the class \verb|Integer|. + +\subsection{Autoboxing \& Auto-Unboxing} +A \textbf{boxing conversion} converts a value of a primitive type to an Object of the corresponding type-wrapper class. +An \textbf{unboxing conversion} converts an object of a type-wrapper class to a value of the corresponding primitive type. +When these conversions are done automatically, they are referred to as \textbf{autoboxing} \& \textbf{auto-unboxing}. +For example: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +Double[] myDoubles = new Double[10]; +myDoubles[0] = 22.7; // autoboxed to a Double Object +double firstDoubleValue = myDoubles[0]; // auto-unboxed to a double primitive +\end{minted} + +\section{Collections} +A \textbf{Collection} (sometimes called a container) is an object that groups multiple elements into a single unit. +Collections are used to store, retrieve, \& manipulate data, and to transmit data from one method to another. +Collections typically represent data items that form a natural group. + +\subsection{Interfaces} +The core Collections interfaces are the interfaces used to manipulate Collections, and to pass them from one method to another. +The basic purpose of these interfaces is to allow Collections to be manipulated independently of the details of their representations. +The core Collections interfaces are the main foundation of the Collections framework. + +\begin{figure}[H] + \centering + \includegraphics[width=0.7\textwidth]{./images/core_collections_interfaces.png} + \caption{Core Collections Interfaces} +\end{figure} + +The core collection interfaces form a hierarchy: a \verb|Set| is a special kind of \verb|Collection|, a \verb|SortedSet| is a special kind of \verb|Set|, etc. +Note that the hierarchy consists of two distinct trees: a \verb|Map| is not a true \verb|Collection|. +\\\\ +To keep the number of core collection interfaces manageable, the JDK doesn't provide separate interfaces for each variant of each collection type. +Among the possible variants are immutable, fixed-size, \& append-only. +Instead, the modification operations in each interface are designated optional, i.e. a given implementation does not have to support all of these operations. +If an unsupported operation is invoked, the Collection will throw an \verb|UnsupportedOperationException|. +Implementations are responsible for documenting which of the optional operations they support. +All of the JDK's general-purpose implementations support all of the optional operations. + +\subsubsection{The \texttt{Collection} Interface} +The \verb|Collection| interface is the root of the Collection hierarchy. +A \verb|Collection| represents a group of objects, which are known as \emph{elements}. +Some \verb|Collection| implementations allow duplicate elements, while others do not; some \verb|Collection| implementations are ordered, and others are not. +The JDK doesn't provide any direct implementations of this interface: it provides only implementations of the more specific sub-interfaces like \verb|Set| \& +\verb|List|. +\\\\ +The \verb|Collection| interface is the lowest common denominator that all Collections implement. +It is used to pass Collections around and to manipulate them when maximum generality is desired. + +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +public interface Collection { + // Basic Operations + int size(); + boolean isEmpty(); + boolean contains(Object element); + boolean add(Object element); // Optional + boolean remove(Object element); // Optional + Iterator iterator(); + + // Bulk Operations + boolean containsAll(Collection c); + boolean addAll(Collection c); // Optional + boolean removeAll(Collection c); // Optional + boolean retainAll(Collection c); // Optional + void clear(); // Optional + + // Array Operations + Object[] toArray(); + Object[] toArray(T[] a); +} +\end{minted} +\caption{The \texttt{Collection} Interface} +\end{code} + +\section{Graphical User Interfaces} +\textbf{Graphical User Interfaces (GUIs)} give a program a distinctive ``look \& feel'', provide users with +a basic level of familiarity, and are built from GUI components such as controls, widgets, etc. +The user interacts with GUI components via the mouse, keyboard, etc. + +\subsection{Swing} +\textbf{Swing} GUI components are from the package \verb|javax.swing|. +They are lightweight components written entirely in Java. +The components originate from AWT (\verb|java.awt|). +A common superclass structure of many of the Swing components is: \verb|java.lang.Object| {\rightarrow} +\verb|java.awt.Component| {\rightarrow} \verb|java.awt.Container| {\rightarrow} \verb|javax.swing.JComponent|. +\\\\ +Some basic GUI components include: +\begin{itemize} + \item \verb|JLabel|: an area where uneditable text or icons can be displayed. + \item \verb|JTextField|: an area in which the user inputs data form the keyboard. Can also display information. + \item \verb|JButton|: an area that triggers an event when clicked. + \item \verb|JCheckBox|: a GUI component that is either selected or not. + \item \verb|JComboBox|: a drop-down list of items from which the user can make a selection by clicking an + item in the list or by typing into the box. + \item \verb|JPanel|: a container in which components can be placed. +\end{itemize} + +\section{INSERT MISSING GUI SHIT HERE} + + +\section{Multithreaded Programming} +A \textbf{process} is an instance of a program being executed. +A \textbf{multitasking} environment allows multiple process to be ran concurrently. +(In reality, only one process is running at a given time on a single CPU. +Time slicing between processes makes it appear as if they are all running at the same time.) +\\\\ +A \textbf{thread} is a ``lightweight process'', i.e. it does not have all the overhead that a process has. +Both processes \& threads have their own independent CPU state, i.e. they have their own processor stack, +their own instruction pointer, \& their own CPU register values. +Multiple threads can share the same memory address space, i.e. share the same variables. +Processes, on the other hand, generally do not share their address space with other processes. +As a rule of thumb, if an application or applet performs a time-consuming task, it should create and use its own thread of execution +to perform that task. + +\subsection{Threads \& Java} +Java has language-level support for threads and it is therefore easy to create multiple independent threads +of execution in Java. +Any class that is a subclass of \mintinline{java}{java.lang.Thread} or that implements the +\mintinline{java}{java.lang.Runnable} interface can be used to create threads. +\\\\ +When a program creates a thread, it can pass the \mintinline{java}{Thread} class constructor as an object whose +statements will be executed. +The program can start a thread's execution by using its \mintinline{java}{start()} method; the +\mintinline{java}{start()} method will in turn call the \mintinline{java}{Thread} object's +\mintinline{java}{run()} method. + + +\subsubsection{\texttt{java.lang.Runnable}} +To create a thread, we instantiate the \mintinline{java}{java.lang.Thread} class. +One of \mintinline{java}{Thread}'s constructors takes objects that implement the \mintinline{java}{Runnable} +interface. +The \mintinline{java}{Runnable} interface contains only a single method: +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +public interface Runnable { + public void run(); +} +\end{minted} +\caption{The \texttt{Runnable} interface} +\end{code} + + +To create a thread, we create an instance of the \mintinline{java}{Thread} class. +We start the thread by calling the \mintinline{java}{start()} method of the thread, which in turn invokes +the thread's \mintinline{java}{run()} method. +The thread will terminate when the \mintinline{java}{run()} method terminates. +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{java} +class Fred implements Runnable { + public void run() { + // insert code to be ran here + } + + public static void main(String args[]) { + Thread t = new Thread(new Fred()) { + t.start(); + } + } +} +\end{minted} +\caption{Creating \& Starting a Thread} +\end{code} + +\subsection{Thread Priority \& Daemons} +Every thread has a \textbf{priority}: threads with higher priority are executed in preference to threads +with lower priority. +Threads can also be marked as a \textbf{daemon}: a background thread that is not expected to exit. +New threads initially have their priority set to the priority of the creating thread. +The new thread is a daemon thread if \& only if the creating thread is a daemon thread + +\subsection{Threads \& the JVM} +When the Java Virtual Machine starts up, there is usually a single non-daemon (user) thread initially; this +thread calls the \mintinline{java}{main()} method of an application. +The JVM continues to execute threads until either the \mintinline{java}{exit()} method of the class +\mintinline{java}{Runtime} is called or all non-daemon (user) threads have died. + +\subsection{Thread Death} +Threads can be killed by calling their \mintinline{java}{stop()} method but this is not a good idea in general. +It is preferable to have a thread die naturally by having its \mintinline{java}{run()} return. +This is often done by altering some variable that causes a while loop to terminate in the \mintinline{java}{run()} +method. + +\subsection{Synchronisation} +Multithreaded programming requires special care, and is generally more difficult to debug. +We want to prevent multiple threads from altering the state of an object at the same time. +Sections of code that should not be executed simultaneously are called \textbf{critical sections}. +We want to have \textbf{mutual exclusion} of concurrent threads in critical sections of code. +In Java, this is done by using \textbf{synchronised methods} or \textbf{synchronised statements}. + +\subsubsection{The \texttt{synchronized} Statement} +A \mintinline{java}{synchronized} statement attempts to acquire a \textbf{lock} for the object or array +specified by the \mintinline{java}{expression}. + + + + + + + + + + +\end{document} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/04D9D15EC7D752D924204F5083801C00D119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/04D9D15EC7D752D924204F5083801C00D119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..e26599e7 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/04D9D15EC7D752D924204F5083801C00D119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{compareTo}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{anotherString}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/0673D832224B12B6777BC3EC0EC1BA9ACFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/0673D832224B12B6777BC3EC0EC1BA9ACFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..568dac99 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/0673D832224B12B6777BC3EC0EC1BA9ACFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,5 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{interface} \PYG{n+nc}{Runnable}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{run}\PYG{p}{();} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/09F17473584F4347C16CBEF55BA02133CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/09F17473584F4347C16CBEF55BA02133CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..c93c192e --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/09F17473584F4347C16CBEF55BA02133CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,6 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{ptivate}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{writeObject}\PYG{p}{(}\PYG{n}{ObjectOutputStream}\PYG{+w}{ }\PYG{n}{s}\PYG{p}{)}\PYG{+w}{ }\PYG{k+kd}{throws}\PYG{+w}{ }\PYG{n}{IOException}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{defaultWriteObject}\PYG{p}{();} +\PYG{+w}{ }\PYG{c+c1}{// customised serialization code} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/0C64E4109D086FA0522DD6E909B5C4B6CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/0C64E4109D086FA0522DD6E909B5C4B6CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..27f1c082 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/0C64E4109D086FA0522DD6E909B5C4B6CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,7 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kn}{package}\PYG{+w}{ }\PYG{n+nn}{java.io}\PYG{p}{;} + +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{interface} \PYG{n+nc}{Serializable}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// there's nothing in here!} +\PYG{p}{\PYGZcb{};} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/15763926F74EFA04BBE7030F5D4187CF67C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/15763926F74EFA04BBE7030F5D4187CF67C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..208aac09 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/15763926F74EFA04BBE7030F5D4187CF67C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,8 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{String}\PYG{+w}{ }\PYG{n}{myString}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Hello world!\PYGZdq{}}\PYG{p}{;} +\PYG{n}{String}\PYG{+w}{ }\PYG{n}{myString}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{String}\PYG{p}{();} +\PYG{k+kt}{char}\PYG{+w}{ }\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{ct326Array}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{err}{‘}\PYG{n}{C}\PYG{err}{\PYGZsq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{err}{‘}\PYG{n}{T}\PYG{err}{\PYGZsq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{err}{‘}\PYG{l+m+mi}{3}\PYG{err}{\PYGZsq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{err}{‘}\PYG{l+m+mi}{2}\PYG{err}{\PYGZsq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{err}{‘}\PYG{l+m+mi}{6}\PYG{err}{\PYGZsq{}}\PYG{+w}{ }\PYG{p}{\PYGZcb{};} +\PYG{n}{String}\PYG{+w}{ }\PYG{n}{ct326String}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{String}\PYG{p}{(}\PYG{n}{ct326Array}\PYG{p}{);} + +\PYG{n}{String}\PYG{+w}{ }\PYG{n}{fs}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{tring}\PYG{p}{.}\PYG{n+na}{format}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The value of the float variable is \PYGZpc{}f, while the value of the integer variable is \PYGZpc{}d, and the string is \PYGZpc{}s\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{floatVar}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{intVar}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{stringVar}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/157C9BDA2CD68AC95F4D2B97A1678EF0A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/157C9BDA2CD68AC95F4D2B97A1678EF0A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..5a0fde5b --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/157C9BDA2CD68AC95F4D2B97A1678EF0A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{run}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/180746C420DA07E8DBB513134FC2732067C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/180746C420DA07E8DBB513134FC2732067C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..d2a42162 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/180746C420DA07E8DBB513134FC2732067C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,8 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{class} \PYG{n+nc}{EnclosingClass}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{p}{...} +\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{ANestedClass}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{p}{...} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/1C11C267B5E2264B7292CA3A94A080D42283592159B570351A3776075FD0198E.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/1C11C267B5E2264B7292CA3A94A080D42283592159B570351A3776075FD0198E.pygtex new file mode 100644 index 00000000..de1bd5fd --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/1C11C267B5E2264B7292CA3A94A080D42283592159B570351A3776075FD0198E.pygtex @@ -0,0 +1,12 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYGZdl{} java Planet 175 + Your weight on MERCURY is 66.107583 + Your weight on VENUS is 158.374842 + Your weight on EARTH is 175.000000 + Your weight on MARS is 66.279007 + Your weight on JUPITER is 442.847567 + Your weight on SATURN is 186.552719 + Your weight on URANUS is 158.397260 + Your weight on NEPTUNE is 199.207413 + Your weight on PLUTO is 11.703031 +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/21B6A78E0C20595A4FD5F54A7E3DDC93CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/21B6A78E0C20595A4FD5F54A7E3DDC93CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..b4292a66 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/21B6A78E0C20595A4FD5F54A7E3DDC93CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,7 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{private}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{readObject}\PYG{p}{(}\PYG{n}{ObjectInputStream}\PYG{+w}{ }\PYG{n}{s}\PYG{p}{)}\PYG{+w}{ }\PYG{k+kd}{throws}\PYG{+w}{ }\PYG{n}{IOException}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{defaultReadObject}\PYG{p}{();} +\PYG{+w}{ }\PYG{c+c1}{// customised deserialization code} +\PYG{+w}{ }\PYG{c+c1}{// followed by code to update the object if necessary} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/25052B4935D09F04BC2D64428D756B53D119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/25052B4935D09F04BC2D64428D756B53D119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..8212cec0 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/25052B4935D09F04BC2D64428D756B53D119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{String}\PYG{+w}{ }\PYG{n+nf}{concat}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2611B87FC4DE06C69FDC8490AED4DFFD67C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2611B87FC4DE06C69FDC8490AED4DFFD67C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..2f5e7beb --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2611B87FC4DE06C69FDC8490AED4DFFD67C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,9 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{n}{String}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{args}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{earthWeight}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{Double}\PYG{p}{.}\PYG{n+na}{parseDouble}\PYG{p}{(}\PYG{n}{args}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{mass}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{earthWeight}\PYG{o}{/}\PYG{n}{EARTH}\PYG{p}{.}\PYG{n+na}{surfaceGravity}\PYG{p}{();} + +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Planet}\PYG{+w}{ }\PYG{n}{p}\PYG{+w}{ }\PYG{p}{:}\PYG{+w}{ }\PYG{n}{Planet}\PYG{p}{.}\PYG{n+na}{values}\PYG{p}{())}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Your weight on \PYGZpc{}s is \PYGZpc{}f\PYGZpc{}n\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{p}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{p}\PYG{p}{.}\PYG{n+na}{surfaceWeight}\PYG{p}{(}\PYG{n}{mass}\PYG{p}{));} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2B68961260F42199018103DBFA0E3AC3CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2B68961260F42199018103DBFA0E3AC3CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..ebed9d0d --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2B68961260F42199018103DBFA0E3AC3CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{elements}\PYG{p}{.}\PYG{n+na}{forEach}\PYG{p}{(}\PYG{n}{e}\PYG{+w}{ }\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{(}\PYG{n}{e}\PYG{p}{));} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2F86992A901A33F001A3A366DADC21E6CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2F86992A901A33F001A3A366DADC21E6CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..76373b58 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2F86992A901A33F001A3A366DADC21E6CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,14 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{ArrayList}\PYG{o}{\PYGZlt{}}\PYG{n}{Integer}\PYG{o}{\PYGZgt{}}\PYG{+w}{ }\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ArrayList}\PYG{o}{\PYGZlt{}}\PYG{n}{Integer}\PYG{o}{\PYGZgt{}}\PYG{p}{();} + +\PYG{c+c1}{// looping though an ArrayList using the Iterator class} +\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Iterator}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{.}\PYG{n+na}{iterator}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{i}\PYG{p}{.}\PYG{n+na}{hasNext}\PYG{p}{();)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{Integer}\PYG{+w}{ }\PYG{n}{value}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Integer}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{i}\PYG{p}{.}\PYG{n+na}{next}\PYG{p}{();} +\PYG{+w}{ }\PYG{c+c1}{// do some stuff} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{// looping though an ArrayList using a For-Each loop} +\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Integer}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{p}{:}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// do some stuff} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2FF0A3E8C199289706D385DB87EF99A4CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2FF0A3E8C199289706D385DB87EF99A4CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..329a3f7a --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/2FF0A3E8C199289706D385DB87EF99A4CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,13 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{class} \PYG{n+nc}{Fred}\PYG{+w}{ }\PYG{k+kd}{implements}\PYG{+w}{ }\PYG{n}{Runnable}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{run}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// insert code to be ran here} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{args}\PYG{o}{[]}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{Thread}\PYG{+w}{ }\PYG{n}{t}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{Thread}\PYG{p}{(}\PYG{k}{new}\PYG{+w}{ }\PYG{n}{Fred}\PYG{p}{())}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{t}\PYG{p}{.}\PYG{n+na}{start}\PYG{p}{();} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/319C70AD7F0A14A024952907E5458830A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/319C70AD7F0A14A024952907E5458830A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..42d7fe8c --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/319C70AD7F0A14A024952907E5458830A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{Runtime} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/3531F3CEA600547C81094B8DCE17F8FED119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/3531F3CEA600547C81094B8DCE17F8FED119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..63484275 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/3531F3CEA600547C81094B8DCE17F8FED119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{String}\PYG{+w}{ }\PYG{n+nf}{substring}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{beginIndex}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{endIndex}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/3A2632AD8303909C6EF9AB91DE5801ECA906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/3A2632AD8303909C6EF9AB91DE5801ECA906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..91e3ffcc --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/3A2632AD8303909C6EF9AB91DE5801ECA906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kd}{implements}\PYG{+w}{ }\PYG{n}{Serializable} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/448A7A35E5307A572CA0DF37729378B2A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/448A7A35E5307A572CA0DF37729378B2A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..35c71631 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/448A7A35E5307A572CA0DF37729378B2A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kd}{synchronized} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/45C789308D81D919898E51B253826521CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/45C789308D81D919898E51B253826521CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..ba57eb5c --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/45C789308D81D919898E51B253826521CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,22 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{interface} \PYG{n+nc}{Collection}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// Basic Operations} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{size}\PYG{p}{();} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{isEmpty}\PYG{p}{();} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{contains}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{element}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{add}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{element}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// Optional} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{remove}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{element}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// Optional} +\PYG{+w}{ }\PYG{n}{Iterator}\PYG{+w}{ }\PYG{n+nf}{iterator}\PYG{p}{();} + +\PYG{+w}{ }\PYG{c+c1}{// Bulk Operations} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{containsAll}\PYG{p}{(}\PYG{n}{Collection}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{addAll}\PYG{p}{(}\PYG{n}{Collection}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// Optional} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{removeAll}\PYG{p}{(}\PYG{n}{Collection}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// Optional} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{retainAll}\PYG{p}{(}\PYG{n}{Collection}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// Optional} +\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{clear}\PYG{p}{();}\PYG{+w}{ }\PYG{c+c1}{// Optional} + +\PYG{+w}{ }\PYG{c+c1}{// Array Operations} +\PYG{+w}{ }\PYG{n}{Object}\PYG{o}{[]}\PYG{+w}{ }\PYG{n+nf}{toArray}\PYG{p}{();} +\PYG{+w}{ }\PYG{n}{Object}\PYG{o}{[]}\PYG{+w}{ }\PYG{n+nf}{toArray}\PYG{p}{(}\PYG{n}{T}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{a}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/50D51C4E77B6F5B92B9B8C3B610BABC9A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/50D51C4E77B6F5B92B9B8C3B610BABC9A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..c4af32b2 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/50D51C4E77B6F5B92B9B8C3B610BABC9A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{start}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5139BDC2F332DCAE525702E7277AD12BCFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5139BDC2F332DCAE525702E7277AD12BCFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..72017382 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5139BDC2F332DCAE525702E7277AD12BCFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k}{new}\PYG{+w}{ }\PYG{n}{RandomAccessFile}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}farrago.txt\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}r\PYGZdq{}}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/58CA95C5B364C5229A72C650AD459C32A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/58CA95C5B364C5229A72C650AD459C32A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..1428c4d7 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/58CA95C5B364C5229A72C650AD459C32A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{main}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5C771413EAC721C34835C93A5A969C1A67C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5C771413EAC721C34835C93A5A969C1A67C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..38aabc9e --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5C771413EAC721C34835C93A5A969C1A67C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,33 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{enum}\PYG{+w}{ }\PYG{n}{Planet}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{MERCURY}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{3.303e+23}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{2.4397e6}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{VENUS}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{4.869e+24}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{6.0518e6}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{EARTH}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{5.976e+24}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{6.37814e6}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{MARS}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{6.421e+23}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{3.3972e6}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{JUPITER}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{1.9e+27}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{7.1492e7}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{SATURN}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{5.688e+26}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{6.0268e7}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{URANUS}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{8.686e+25}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{2.5559e7}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{NEPTUNE}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{1.024e+26}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{2.4746e7}\PYG{p}{),} +\PYG{+w}{ }\PYG{n}{PLUTO}\PYG{+w}{ }\PYG{p}{(}\PYG{l+m+mf}{1.27e+22}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mf}{1.137e6}\PYG{p}{);} + +\PYG{+w}{ }\PYG{k+kd}{private}\PYG{+w}{ }\PYG{k+kd}{final}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{mass}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{//in kilograms} +\PYG{+w}{ }\PYG{k+kd}{private}\PYG{+w}{ }\PYG{k+kd}{final}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{radius}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{//in meters} + +\PYG{+w}{ }\PYG{n}{Planet}\PYG{p}{(}\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{mass}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{radius}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{this}\PYG{p}{.}\PYG{n+na}{mass}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{mass}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{this}\PYG{p}{.}\PYG{n+na}{radius}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{radius}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n+nf}{mass}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{mass}\PYG{p}{;}\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n+nf}{radius}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{radius}\PYG{p}{;}\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kd}{final}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{G}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mf}{6.67300E\PYGZhy{}11}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{//universal gravitational constant (m3 kg-1 s-2)} + +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n+nf}{surfaceGravity}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{G}\PYG{+w}{ }\PYG{o}{*}\PYG{+w}{ }\PYG{n}{mass}\PYG{+w}{ }\PYG{o}{/}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{radius}\PYG{+w}{ }\PYG{o}{*}\PYG{+w}{ }\PYG{n}{radius}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n+nf}{surfaceWeight}\PYG{p}{(}\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{otherMass}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{otherMass}\PYG{+w}{ }\PYG{o}{*}\PYG{+w}{ }\PYG{n}{surfaceGravity}\PYG{p}{();} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5E79B10351EC7162C1948928D6ADEF9CCFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5E79B10351EC7162C1948928D6ADEF9CCFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..80a182e6 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/5E79B10351EC7162C1948928D6ADEF9CCFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,6 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{Scanner}\PYG{+w}{ }\PYG{n}{s}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{Scanner}\PYG{p}{(}\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{in}\PYG{p}{);} +\PYG{n}{String}\PYG{+w}{ }\PYG{n}{param}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{next}\PYG{p}{();} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{value}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{nextInt}\PYG{p}{();} +\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{close}\PYG{p}{();} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/62B577FF79736C7114F5F6BB04D84D46A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/62B577FF79736C7114F5F6BB04D84D46A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..1ecc035d --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/62B577FF79736C7114F5F6BB04D84D46A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{stop}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/666EF3AE9B88C689D05E6730F598547FA906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/666EF3AE9B88C689D05E6730F598547FA906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..10248a46 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/666EF3AE9B88C689D05E6730F598547FA906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{java}\PYG{p}{.}\PYG{n+na}{lang}\PYG{p}{.}\PYG{n+na}{Runnable} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/6DA6D945EAE344D6E27B647111317649D119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/6DA6D945EAE344D6E27B647111317649D119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..f8b9ed30 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/6DA6D945EAE344D6E27B647111317649D119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{String}\PYG{+w}{ }\PYG{n+nf}{replace}\PYG{p}{(}\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{oldChar}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{newChar}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/76A5E3603D97732D12B89BFF31B2A1DFA906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/76A5E3603D97732D12B89BFF31B2A1DFA906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..8dd0b891 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/76A5E3603D97732D12B89BFF31B2A1DFA906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{expression} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/77BE3C1C02D7552C6B2DB6A6C4DB9BCED119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/77BE3C1C02D7552C6B2DB6A6C4DB9BCED119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..0328b012 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/77BE3C1C02D7552C6B2DB6A6C4DB9BCED119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{String}\PYG{+w}{ }\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{split}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{regex}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7A48874248A5800E02703A930388C64FD119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7A48874248A5800E02703A930388C64FD119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..5c2794d7 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7A48874248A5800E02703A930388C64FD119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{String}\PYG{+w}{ }\PYG{n+nf}{strip}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7CAA865B68C9AD8B16196BDD51468C90D119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7CAA865B68C9AD8B16196BDD51468C90D119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..65b5a1ca --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7CAA865B68C9AD8B16196BDD51468C90D119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{equalsIgnoreCase}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{anotherString}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7ECDBEA815C813BD441AFDE7ED87E38CCFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7ECDBEA815C813BD441AFDE7ED87E38CCFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..a0524b76 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7ECDBEA815C813BD441AFDE7ED87E38CCFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,7 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{FileOutputStream}\PYG{+w}{ }\PYG{n}{out}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{FileOutputStream}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}theTime\PYGZdq{}}\PYG{p}{);} +\PYG{n}{ObjectOutputStream}\PYG{+w}{ }\PYG{n}{s}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ObjectOutputStream}\PYG{p}{(}\PYG{n}{out}\PYG{p}{);} +\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{writeObject}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Today\PYGZdq{}}\PYG{p}{);} +\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{writeObject}\PYG{p}{(}\PYG{k}{new}\PYG{+w}{ }\PYG{n}{Date}\PYG{p}{());} +\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{flush}\PYG{p}{();} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7FF8F113C277E23074D32DD80259BC1667C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7FF8F113C277E23074D32DD80259BC1667C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..ce6aa08a --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/7FF8F113C277E23074D32DD80259BC1667C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,12 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k}{try}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// statements that may throw an exception} +\PYG{p}{\PYGZcb{}} +\PYG{k}{catch}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{ExceptionType}\PYG{+w}{ }\PYG{n}{exceptionReference}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// statemetns to process the exception} +\PYG{p}{\PYGZcb{}} +\PYG{c+c1}{// a `try` is followed by any number of `catch` blocks} +\PYG{k}{catch}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{ExceptionType}\PYG{+w}{ }\PYG{n}{exceptionReference}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// statemetns to process the exception} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/8B1106E59EBE375C154B2A973AB1F382A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/8B1106E59EBE375C154B2A973AB1F382A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..486e746f --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/8B1106E59EBE375C154B2A973AB1F382A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{Thread} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/92983D0B1025EA84856F4B12E0970F5FCFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/92983D0B1025EA84856F4B12E0970F5FCFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..4e4db4a7 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/92983D0B1025EA84856F4B12E0970F5FCFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,5 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{Double}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{myDoubles}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{Double}\PYG{o}{[}\PYG{l+m+mi}{10}\PYG{o}{]}\PYG{p}{;} +\PYG{n}{myDoubles}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mf}{22.7}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// autoboxed to a Double Object} +\PYG{k+kt}{double}\PYG{+w}{ }\PYG{n}{firstDoubleValue}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{myDoubles}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// auto-unboxed to a double primitive} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/9699F21E2B09F9268FCC89DF9940F561A906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/9699F21E2B09F9268FCC89DF9940F561A906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..eb47c350 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/9699F21E2B09F9268FCC89DF9940F561A906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{exit}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/9DF814687C63DD01AD3BC64B028E18BE67C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/9DF814687C63DD01AD3BC64B028E18BE67C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..651fd56b --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/9DF814687C63DD01AD3BC64B028E18BE67C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,25 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{assertTrue}\PYG{p}{(}\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n}{test}\PYG{p}{)} +\PYG{n}{assertTrue}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n}{test}\PYG{p}{)} + +\PYG{n}{assertFalse}\PYG{p}{(}\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n}{test}\PYG{p}{)} +\PYG{n}{assertFalse}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n}{test}\PYG{p}{)} + +\PYG{n}{assertEquals}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{expected}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{actual}\PYG{p}{)} +\PYG{n}{assertEquals}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{expected}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{actual}\PYG{p}{)} + +\PYG{n}{assertSame}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{expected}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{actual}\PYG{p}{)} +\PYG{n}{assertSame}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{expected}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{actual}\PYG{p}{)} + +\PYG{n}{assertNotSame}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{expected}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{actual}\PYG{p}{)} +\PYG{n}{assertNotSame}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{expected}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{actual}\PYG{p}{)} + +\PYG{n}{assertNull}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{object}\PYG{p}{)} +\PYG{n}{assertNull}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{object}\PYG{p}{)} + +\PYG{n}{assertNotNull}\PYG{p}{(}\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{object}\PYG{p}{)} +\PYG{n}{assertNotNull}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Object}\PYG{+w}{ }\PYG{n}{object}\PYG{p}{)} + +\PYG{n}{fail}\PYG{p}{()} +\PYG{n}{fail}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{message}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/A6C4B29073744B319AEFEBEA11051952CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/A6C4B29073744B319AEFEBEA11051952CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..21473e98 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/A6C4B29073744B319AEFEBEA11051952CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{parameter}\PYG{+w}{ }\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{+w}{ }\PYG{n}{expression} +\PYG{p}{(}\PYG{n}{parameter1}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{parameter2}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{+w}{ }\PYG{n}{expression} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/B67CAAF6C4F09F215AE07DA9F5CFAC71CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/B67CAAF6C4F09F215AE07DA9F5CFAC71CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..9171e385 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/B67CAAF6C4F09F215AE07DA9F5CFAC71CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,9 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{argtest}\PYG{p}{(}\PYG{n}{Object}\PYG{p}{...}\PYG{+w}{ }\PYG{n}{args}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZlt{}}\PYG{+w}{ }\PYG{n}{args}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} + +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} + +\PYG{n}{argtest}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}test\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}data\PYGZdq{}}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/BCB75DD28B44612D1F364C866B781FB567C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/BCB75DD28B44612D1F364C866B781FB567C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..345c26bb --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/BCB75DD28B44612D1F364C866B781FB567C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,11 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{class} \PYG{n+nc}{EnclosingClass}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{p}{...} +\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{StaticNestedClass}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{p}{...} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{InnerClass}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{p}{...} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C13A17D3E4A2151C09FDB27CFCD3030E67C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C13A17D3E4A2151C09FDB27CFCD3030E67C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..b96b1897 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C13A17D3E4A2151C09FDB27CFCD3030E67C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,75 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// Fig. 10.20: TokenTest.java} +\PYG{c+c1}{// Testing the StringTokenizer class of the java.util package} + +\PYG{c+c1}{// Java core packages} +\PYG{k+kn}{import}\PYG{+w}{ }\PYG{n+nn}{java.util.*}\PYG{p}{;} +\PYG{k+kn}{import}\PYG{+w}{ }\PYG{n+nn}{java.awt.*}\PYG{p}{;} +\PYG{k+kn}{import}\PYG{+w}{ }\PYG{n+nn}{java.awt.event.*}\PYG{p}{;} + +\PYG{c+c1}{// Java extension packages} +\PYG{k+kn}{import}\PYG{+w}{ }\PYG{n+nn}{javax.swing.*}\PYG{p}{;} + +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{TokenTest}\PYG{+w}{ }\PYG{k+kd}{extends}\PYG{+w}{ }\PYG{n}{JFrame}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kd}{private}\PYG{+w}{ }\PYG{n}{JLabel}\PYG{+w}{ }\PYG{n}{promptLabel}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kd}{private}\PYG{+w}{ }\PYG{n}{JTextField}\PYG{+w}{ }\PYG{n}{inputField}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kd}{private}\PYG{+w}{ }\PYG{n}{JTextArea}\PYG{+w}{ }\PYG{n}{outputArea}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// set up GUI and event handling} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{n+nf}{TokenTest}\PYG{p}{()} +\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kd}{super}\PYG{p}{(}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Testing Class StringTokenizer\PYGZdq{}}\PYG{+w}{ }\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{Container}\PYG{+w}{ }\PYG{n}{container}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{getContentPane}\PYG{p}{();} +\PYG{+w}{ }\PYG{n}{container}\PYG{p}{.}\PYG{n+na}{setLayout}\PYG{p}{(}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{FlowLayout}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{promptLabel}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{JLabel}\PYG{p}{(}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Enter a sentence and press Enter\PYGZdq{}}\PYG{+w}{ }\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{container}\PYG{p}{.}\PYG{n+na}{add}\PYG{p}{(}\PYG{+w}{ }\PYG{n}{promptLabel}\PYG{+w}{ }\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{inputField}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{JTextField}\PYG{p}{(}\PYG{+w}{ }\PYG{l+m+mi}{20}\PYG{+w}{ }\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// inputField contains String to be parsed by StringTokenizer} + +\PYG{+w}{ }\PYG{n}{inputField}\PYG{p}{.}\PYG{n+na}{addActionListener}\PYG{p}{(} +\PYG{+w}{ }\PYG{c+c1}{// anonymous inner class} +\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ActionListener}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// handle text field event} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{n}{coid}\PYG{+w}{ }\PYG{n+nf}{actionPerformed}\PYG{p}{(}\PYG{n}{ActionEvent}\PYG{+w}{ }\PYG{n}{event}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n}{stringToTokenize}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{event}\PYG{p}{.}\PYG{n+na}{getActionCommand}\PYG{p}{();} +\PYG{+w}{ }\PYG{n}{StringTokenizer}\PYG{+w}{ }\PYG{n}{tokens}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{StringTokenizer}\PYG{p}{(}\PYG{+w}{ }\PYG{n}{stringToTokenize}\PYG{+w}{ }\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// Use StringTokenizer to parse String stringToTokenize with default delimiters "{\textbackslash}n{\textbackslash}t{\textbackslash}r"} + +\PYG{+w}{ }\PYG{n}{outputArea}\PYG{p}{.}\PYG{n+na}{setText}\PYG{p}{(}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Number of elements: \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{tokens}\PYG{p}{.}\PYG{n+na}{countTokens}\PYG{p}{()}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}\PYGZbs{}nThe tokens are:\PYGZbs{}n\PYGZdq{}}\PYG{+w}{ }\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// count number of tokens} + +\PYG{+w}{ }\PYG{c+c1}{// apend next token to outputArea as long as tokens exist} +\PYG{+w}{ }\PYG{k}{while}\PYG{+w}{ }\PYG{p}{(}\PYG{+w}{ }\PYG{n}{tokens}\PYG{p}{.}\PYG{n+na}{hasMoreTokens}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{n}{outputArea}\PYG{p}{.}\PYG{n+na}{append}\PYG{p}{(}\PYG{+w}{ }\PYG{n}{tokens}\PYG{p}{.}\PYG{n+na}{nextToken}\PYG{p}{()}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}\PYGZbs{}n\PYGZdq{}}\PYG{+w}{ }\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}}\PYG{+w}{ }\PYG{c+c1}{// end anonymous inner class} +\PYG{+w}{ }\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// end call to addActionListener} + +\PYG{+w}{ }\PYG{n}{container}\PYG{p}{.}\PYG{n+na}{add}\PYG{p}{(}\PYG{+w}{ }\PYG{n}{inputField}\PYG{+w}{ }\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{outputArea}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{JTextArea}\PYG{p}{(}\PYG{+w}{ }\PYG{l+m+mi}{10}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mi}{20}\PYG{+w}{ }\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{outputArea}\PYG{p}{.}\PYG{n+na}{setEditable}\PYG{p}{(}\PYG{+w}{ }\PYG{k+kc}{false}\PYG{+w}{ }\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{container}\PYG{p}{.}\PYG{n+na}{add}\PYG{p}{(}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{JScrollPane}\PYG{p}{(}\PYG{+w}{ }\PYG{n}{outputArea}\PYG{+w}{ }\PYG{p}{)}\PYG{+w}{ }\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{setSize}\PYG{p}{(}\PYG{+w}{ }\PYG{l+m+mi}{275}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mi}{260}\PYG{+w}{ }\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// set the window size} +\PYG{+w}{ }\PYG{n}{show}\PYG{p}{();}\PYG{+w}{ }\PYG{c+c1}{// show the window} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// execute application} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n}{args}\PYG{o}{[]}\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{TokenTest}\PYG{+w}{ }\PYG{n}{application}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{TokenTest}\PYG{p}{();} +\PYG{+w}{ }\PYG{n}{application}\PYG{p}{.}\PYG{n+na}{addWindowListener}\PYG{p}{(} +\PYG{+w}{ }\PYG{c+c1}{// anonymous inner class} +\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{WindowAdapter}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// handle event when user closes window} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{windowClosing}\PYG{p}{(}\PYG{+w}{ }\PYG{n}{WindowEvent}\PYG{+w}{ }\PYG{n}{windowEvent}\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{exit}\PYG{p}{(}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}}\PYG{+w}{ }\PYG{c+c1}{// end anonymous inner class} +\PYG{+w}{ }\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// end call to addWindowListener} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}}\PYG{+w}{ }\PYG{c+c1}{// end method main} +\PYG{p}{\PYGZcb{}}\PYG{+w}{ }\PYG{c+c1}{// end class TokenTest} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C2EC7F51BD86458950E4F5D99C2CB9A4CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C2EC7F51BD86458950E4F5D99C2CB9A4CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..cffdcfa6 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C2EC7F51BD86458950E4F5D99C2CB9A4CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}name count\PYGZpc{}\PYGZbs{}n\PYGZdq{}}\PYG{p}{);} +\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}\PYGZpc{}s \PYGZpc{}5d\PYGZpc{}\PYGZbs{}n\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{user}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{total}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C4619C0F1DEC1081DC59A20375F3F34FD119CDC5695F277E6308D6024CA363E3.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C4619C0F1DEC1081DC59A20375F3F34FD119CDC5695F277E6308D6024CA363E3.pygtex new file mode 100644 index 00000000..160ef3c7 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/C4619C0F1DEC1081DC59A20375F3F34FD119CDC5695F277E6308D6024CA363E3.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{abstract}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{Employee} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/D6427544238BEE451EB0DB73A148F4DDA906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/D6427544238BEE451EB0DB73A148F4DDA906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..f1a4d37a --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/D6427544238BEE451EB0DB73A148F4DDA906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{Runnable} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/DB5F18854F05B42FAC6FFCBF42BF7E2BA906B9DBE82F8695ADD70071484FCB56.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/DB5F18854F05B42FAC6FFCBF42BF7E2BA906B9DBE82F8695ADD70071484FCB56.pygtex new file mode 100644 index 00000000..cd8000ab --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/DB5F18854F05B42FAC6FFCBF42BF7E2BA906B9DBE82F8695ADD70071484FCB56.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{java}\PYG{p}{.}\PYG{n+na}{lang}\PYG{p}{.}\PYG{n+na}{Thread} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/ED89EE54BE8B59649A8E242120C36EE767C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/ED89EE54BE8B59649A8E242120C36EE767C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..56ec086e --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/ED89EE54BE8B59649A8E242120C36EE767C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,5 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{functionName}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{paremeterList}\PYG{p}{)}\PYG{+w}{ }\PYG{k+kd}{throws}\PYG{+w}{ }\PYG{n}{ExceptionType1}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{ExceptionType2}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// method body} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/EF69224252B0434D498EB16DA082C856CFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/EF69224252B0434D498EB16DA082C856CFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..45b45647 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/EF69224252B0434D498EB16DA082C856CFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,6 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n}{FileInputStream}\PYG{+w}{ }\PYG{n}{in}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{FileInputStream}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}theTime\PYGZdq{}}\PYG{p}{);} +\PYG{n}{ObjectInputStream}\PYG{+w}{ }\PYG{n}{s}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ObjectInputStream}\PYG{p}{(}\PYG{n}{in}\PYG{p}{);} +\PYG{n}{String}\PYG{+w}{ }\PYG{n}{today}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{String}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{readObject}\PYG{p}{();} +\PYG{n}{Date}\PYG{+w}{ }\PYG{n}{date}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Date}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{s}\PYG{p}{.}\PYG{n+na}{readObject}\PYG{p}{();} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/F3E3DFC88805AFBFDD4C25C7FDB4A66FCFCD10B6E967F145489C3C2B47048B4F.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/F3E3DFC88805AFBFDD4C25C7FDB4A66FCFCD10B6E967F145489C3C2B47048B4F.pygtex new file mode 100644 index 00000000..8a4fda78 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/F3E3DFC88805AFBFDD4C25C7FDB4A66FCFCD10B6E967F145489C3C2B47048B4F.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k}{new}\PYG{+w}{ }\PYG{n}{RandomAccessFile}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}farrago.txt\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}rw\PYGZdq{}}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/F52D5E44A487BF814E0B6843441E170D67C30541BBFC1CABB82AC82DF38DC1A5.pygtex b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/F52D5E44A487BF814E0B6843441E170D67C30541BBFC1CABB82AC82DF38DC1A5.pygtex new file mode 100644 index 00000000..c2e70844 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/F52D5E44A487BF814E0B6843441E170D67C30541BBFC1CABB82AC82DF38DC1A5.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{enum}\PYG{+w}{ }\PYG{n}{Days}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{n}{SUNDAY}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{MONDAY}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{TUESDAY}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{WEDNESDAY}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{THURSDAY}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{FRIDAY}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{SATURDAY}\PYG{+w}{ }\PYG{p}{\PYGZcb{};} +\end{Verbatim} diff --git a/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/algol_nu.pygstyle b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/algol_nu.pygstyle new file mode 100644 index 00000000..81971cf2 --- /dev/null +++ b/third/semester1/CT326_Programming_III/notes/_minted-CT326-Notes/algol_nu.pygstyle @@ -0,0 +1,76 @@ + +\makeatletter +\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax% + \let\PYG@ul=\relax \let\PYG@tc=\relax% + \let\PYG@bc=\relax \let\PYG@ff=\relax} +\def\PYG@tok#1{\csname PYG@tok@#1\endcsname} +\def\PYG@toks#1+{\ifx\relax#1\empty\else% + \PYG@tok{#1}\expandafter\PYG@toks\fi} +\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{% + \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}} +\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}} + +\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cs}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@nb}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@bp}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nf}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nv}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@no}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@s}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} +\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kp}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kt}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@fm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vg}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vi}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sa}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sb}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sc}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@dl}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@s2}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@se}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sh}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@si}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sx}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sr}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@s1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ss}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} + +\def\PYGZbs{\char`\\} +\def\PYGZus{\char`\_} +\def\PYGZob{\char`\{} +\def\PYGZcb{\char`\}} +\def\PYGZca{\char`\^} +\def\PYGZam{\char`\&} +\def\PYGZlt{\char`\<} +\def\PYGZgt{\char`\>} +\def\PYGZsh{\char`\#} +\def\PYGZpc{\char`\%} +\def\PYGZdl{\char`\$} +\def\PYGZhy{\char`\-} +\def\PYGZsq{\char`\'} +\def\PYGZdq{\char`\"} +\def\PYGZti{\char`\~} +% for compatibility with earlier versions +\def\PYGZat{@} +\def\PYGZlb{[} +\def\PYGZrb{]} +\makeatother + diff --git a/third/semester1/CT326_Programming_III/notes/images/InputStream.png b/third/semester1/CT326_Programming_III/notes/images/InputStream.png new file mode 100644 index 00000000..37dba8b9 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/InputStream.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/OutputStream.png b/third/semester1/CT326_Programming_III/notes/images/OutputStream.png new file mode 100644 index 00000000..ade05104 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/OutputStream.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/Reader.png b/third/semester1/CT326_Programming_III/notes/images/Reader.png new file mode 100644 index 00000000..1f33da87 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/Reader.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/Writer.png b/third/semester1/CT326_Programming_III/notes/images/Writer.png new file mode 100644 index 00000000..c6184379 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/Writer.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/access_level_specifiers.png b/third/semester1/CT326_Programming_III/notes/images/access_level_specifiers.png new file mode 100644 index 00000000..0c35e397 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/access_level_specifiers.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/core_collections_interfaces.png b/third/semester1/CT326_Programming_III/notes/images/core_collections_interfaces.png new file mode 100644 index 00000000..87b756cc Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/core_collections_interfaces.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/dir-entry.png b/third/semester1/CT326_Programming_III/notes/images/dir-entry.png new file mode 100644 index 00000000..953c9809 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/dir-entry.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/java-logo.png b/third/semester1/CT326_Programming_III/notes/images/java-logo.png new file mode 100644 index 00000000..3232c9b6 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/java-logo.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/tdd_cycle.png b/third/semester1/CT326_Programming_III/notes/images/tdd_cycle.png new file mode 100644 index 00000000..d9091737 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/tdd_cycle.png differ diff --git a/third/semester1/CT326_Programming_III/notes/images/tdd_cycle_oo.png b/third/semester1/CT326_Programming_III/notes/images/tdd_cycle_oo.png new file mode 100644 index 00000000..df8d9c94 Binary files /dev/null and b/third/semester1/CT326_Programming_III/notes/images/tdd_cycle_oo.png differ diff --git a/third/semester1/CT326_Programming_III/papers/2013_2014_CT326_1_1_1.PDF b/third/semester1/CT326_Programming_III/papers/2013_2014_CT326_1_1_1.PDF new file mode 100644 index 00000000..bc84f81d Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2013_2014_CT326_1_1_1.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2014_2015_CT326_1_1_1.PDF b/third/semester1/CT326_Programming_III/papers/2014_2015_CT326_1_1_1.PDF new file mode 100644 index 00000000..26786a56 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2014_2015_CT326_1_1_1.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2014_2015_CT326_1_2_3.PDF b/third/semester1/CT326_Programming_III/papers/2014_2015_CT326_1_2_3.PDF new file mode 100644 index 00000000..a1b2e443 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2014_2015_CT326_1_2_3.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2015_2016_CT326_1_1_5.PDF b/third/semester1/CT326_Programming_III/papers/2015_2016_CT326_1_1_5.PDF new file mode 100644 index 00000000..ab9a225a Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2015_2016_CT326_1_1_5.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2015_2016_CT326_1_2_3.PDF b/third/semester1/CT326_Programming_III/papers/2015_2016_CT326_1_2_3.PDF new file mode 100644 index 00000000..831f1d5b Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2015_2016_CT326_1_2_3.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2016_2017_CT326_1_1_5.PDF b/third/semester1/CT326_Programming_III/papers/2016_2017_CT326_1_1_5.PDF new file mode 100644 index 00000000..3d165c02 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2016_2017_CT326_1_1_5.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2016_2017_CT326_1_2_3.PDF b/third/semester1/CT326_Programming_III/papers/2016_2017_CT326_1_2_3.PDF new file mode 100644 index 00000000..eb1d28e0 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2016_2017_CT326_1_2_3.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2017_2018_CT326_1_1_5.PDF b/third/semester1/CT326_Programming_III/papers/2017_2018_CT326_1_1_5.PDF new file mode 100644 index 00000000..3d0074d6 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2017_2018_CT326_1_1_5.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2017_2018_CT326_1_2_3.PDF b/third/semester1/CT326_Programming_III/papers/2017_2018_CT326_1_2_3.PDF new file mode 100644 index 00000000..97b59e3f Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2017_2018_CT326_1_2_3.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2018_2019_CT326_1_1_5.PDF b/third/semester1/CT326_Programming_III/papers/2018_2019_CT326_1_1_5.PDF new file mode 100644 index 00000000..0a9b52a4 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2018_2019_CT326_1_1_5.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2018_2019_CT326_1_2_3.PDF b/third/semester1/CT326_Programming_III/papers/2018_2019_CT326_1_2_3.PDF new file mode 100644 index 00000000..4fb5ddcb Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2018_2019_CT326_1_2_3.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2019_2020_CT326_1_1_5.PDF b/third/semester1/CT326_Programming_III/papers/2019_2020_CT326_1_1_5.PDF new file mode 100644 index 00000000..cbbb443f Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2019_2020_CT326_1_1_5.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2021_2022_CT326_1_1_5.PDF b/third/semester1/CT326_Programming_III/papers/2021_2022_CT326_1_1_5.PDF new file mode 100644 index 00000000..dadf3c37 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2021_2022_CT326_1_1_5.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2021_2022_CT326_1_2_3.PDF b/third/semester1/CT326_Programming_III/papers/2021_2022_CT326_1_2_3.PDF new file mode 100644 index 00000000..5bf33447 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2021_2022_CT326_1_2_3.PDF differ diff --git a/third/semester1/CT326_Programming_III/papers/2022_2023_CT326_1_2_3.PDF b/third/semester1/CT326_Programming_III/papers/2022_2023_CT326_1_2_3.PDF new file mode 100644 index 00000000..9d312ca2 Binary files /dev/null and b/third/semester1/CT326_Programming_III/papers/2022_2023_CT326_1_2_3.PDF differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - GUI Lectures.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - GUI Lectures.pdf new file mode 100644 index 00000000..7f189742 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - GUI Lectures.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 0.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 0.pdf new file mode 100644 index 00000000..dc78ec21 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 0.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 1 (overloading constructors and polymophism)_S.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 1 (overloading constructors and polymophism)_S.pdf new file mode 100644 index 00000000..7bc2e557 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 1 (overloading constructors and polymophism)_S.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 10 (javadoc and lambda expressions).pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 10 (javadoc and lambda expressions).pdf new file mode 100644 index 00000000..ec83704d Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 10 (javadoc and lambda expressions).pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 2 (command line programming and common problems)_S.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 2 (command line programming and common problems)_S.pdf new file mode 100644 index 00000000..d8a6b950 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 2 (command line programming and common problems)_S.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 3 (Testing I)_S.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 3 (Testing I)_S.pdf new file mode 100644 index 00000000..0d60d3a2 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 3 (Testing I)_S.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 4 (throwing and handling exceptions)_S.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 4 (throwing and handling exceptions)_S.pdf new file mode 100644 index 00000000..0d40483f Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 4 (throwing and handling exceptions)_S.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 5 (Testing II)_S.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 5 (Testing II)_S.pdf new file mode 100644 index 00000000..2f745057 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 5 (Testing II)_S.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 6 (Strings).pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 6 (Strings).pdf new file mode 100644 index 00000000..3d5e916a Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 6 (Strings).pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 7 (nested classes).pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 7 (nested classes).pdf new file mode 100644 index 00000000..0b51d6ad Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 7 (nested classes).pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 8 (enums).pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 8 (enums).pdf new file mode 100644 index 00000000..24ed23ae Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 8 (enums).pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 9 (packages, varargs, and formatted input).pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 9 (packages, varargs, and formatted input).pdf new file mode 100644 index 00000000..292178c3 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lecture 9 (packages, varargs, and formatted input).pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Lectures Week 5 (IO Streams).pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Lectures Week 5 (IO Streams).pdf new file mode 100644 index 00000000..efcf7680 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Lectures Week 5 (IO Streams).pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - MTP Lectures.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - MTP Lectures.pdf new file mode 100644 index 00000000..4445e038 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - MTP Lectures.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Object serialisation.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Object serialisation.pdf new file mode 100644 index 00000000..e926bf7c Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Object serialisation.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Random Access Files.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Random Access Files.pdf new file mode 100644 index 00000000..660fc02b Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Random Access Files.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Streams lectures 2.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Streams lectures 2.pdf new file mode 100644 index 00000000..bb85ff33 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Streams lectures 2.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Streams lectures.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Streams lectures.pdf new file mode 100644 index 00000000..836d9064 Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Streams lectures.pdf differ diff --git a/third/semester1/CT326_Programming_III/slides/CT326 - Week 7.pdf b/third/semester1/CT326_Programming_III/slides/CT326 - Week 7.pdf new file mode 100644 index 00000000..2755491c Binary files /dev/null and b/third/semester1/CT326_Programming_III/slides/CT326 - Week 7.pdf differ