Rename 'CT326_Programming_III' to 'CT326: Programming III'

This commit is contained in:
2023-12-09 16:50:55 +00:00
parent a7e7f78f52
commit 066ec2d356
193 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,6 @@
// Andrew Hayes, ID: 21321503
public class DateInPastException extends RuntimeException {
public DateInPastException(String s) {
super(s);
}
}

View File

@ -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; }
}

View File

@ -0,0 +1,6 @@
// Andrew Hayes, ID: 21321503
import java.time.LocalDateTime;
public interface NCTBookingSlotWebservice {
public LocalDateTime getBookingDateTime(TestCentre testCentre);
}

View File

@ -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; }
}