From e60f0f41ddd5e182743000637af3483bffe20d19 Mon Sep 17 00:00:00 2001 From: hello Date: Fri, 11 Oct 2019 12:29:03 +0800 Subject: [PATCH] Update incident model --- .../address/model/incident/Description.java | 1 - .../address/model/incident/Incident.java | 40 +++++++++++++++++-- .../address/model/incident/IncidentID.java | 39 ++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/main/java/seedu/address/model/incident/IncidentID.java diff --git a/src/main/java/seedu/address/model/incident/Description.java b/src/main/java/seedu/address/model/incident/Description.java index d9779e525f8..39b2a6f2387 100644 --- a/src/main/java/seedu/address/model/incident/Description.java +++ b/src/main/java/seedu/address/model/incident/Description.java @@ -19,7 +19,6 @@ public Description() { this.desc = ""; } - @Override public String toString() { return desc; diff --git a/src/main/java/seedu/address/model/incident/Incident.java b/src/main/java/seedu/address/model/incident/Incident.java index 82c97601b72..2e41971eaf5 100644 --- a/src/main/java/seedu/address/model/incident/Incident.java +++ b/src/main/java/seedu/address/model/incident/Incident.java @@ -1,5 +1,7 @@ package seedu.address.model.incident; import java.time.LocalDateTime; +import java.util.Scanner; + import seedu.address.model.person.Person; import seedu.address.model.vehicle.District; import seedu.address.model.vehicle.Vehicle; @@ -13,6 +15,7 @@ public class Incident { private Person operator; private LocalDateTime dateTime; private Vehicle car; + private IncidentID id; //needs to be entered by operator private Description incidentDesc; @@ -26,14 +29,43 @@ public class Incident { */ public Incident(String caller) { + //this.operator = autofilled on sign in this.dateTime = LocalDateTime.now(); + this.id = new IncidentID(dateTime.getMonthValue(), dateTime.getYear()); + this.incidentDesc = promptForDescription(); + this.location = promptForLocation(); this.callerNumber = caller; - //operator = autofilled when sign in - //location = prompt and return value from GUI - incidentDesc = new Description(); //prompt to fill in desc now. if n, empty desc, if yes, use string from GUI - //car = auto-assigned?? + //this.car = VehicleAssigner.assignVehicle(location); } + + /** + * static method to prompt operator for incident location + * @return district which will be stored to location + */ + public static District promptForLocation() { + System.out.println("Enter location:"); //need to change to GUI prompt + Scanner sc = new Scanner(System.in); //need to change to GUI input + String dist = sc.next(); + while(!District.isValidDistrict(dist)) { + System.out.println("Please enter a valid district"); + dist = sc.next(); + } + return new District(dist); + } + + public static Description promptForDescription() { + System.out.println("Enter incident description now? y/n"); //change to GUI + Scanner sc = new Scanner(System.in); //change to GUI + String desc = ""; + if(sc.next().equals("y")) { + System.out.println("Please enter description:"); + desc = sc.nextLine(); + } + return new Description(desc); + } + + public LocalDateTime getTime() { return this.dateTime; } diff --git a/src/main/java/seedu/address/model/incident/IncidentID.java b/src/main/java/seedu/address/model/incident/IncidentID.java new file mode 100644 index 00000000000..a6053bffcd5 --- /dev/null +++ b/src/main/java/seedu/address/model/incident/IncidentID.java @@ -0,0 +1,39 @@ +package seedu.address.model.incident; + +/** + * Generates Incident ID for the incident in this format: MMYYYYXXXX + * MM = Month of incident + * YYYY = Year of incident + * XXXX = incident number of the month + */ + +public class IncidentID { + private static int PREVIOUSM = 0; + private int mm; + private int yyyy; + private static int XXXX = 0; + private String ID; + + /** + * Generates the ID for the incident based on the following inputs + * @param mm month of incident + * @param yyyy year of incident + */ + public IncidentID(int mm, int yyyy) { + if(PREVIOUSM != mm) { + PREVIOUSM = mm; + XXXX = 0; + } else { + XXXX++; + } + + this.mm = mm; + this.yyyy = yyyy; + int temp = mm * 100000000 + yyyy * 1000 + XXXX; + this.ID = String.format("%10d", temp); + } + + public String getID() { + return this.ID; + } +}