Skip to content
Snippets Groups Projects
Commit 1189f5c7 authored by Johanne Fixdal's avatar Johanne Fixdal
Browse files

Added ArrayList with new trains

parent 9c96478c
No related branches found
No related tags found
No related merge requests found
......@@ -4,21 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="885012ef-f9bd-49ba-ae4a-3de0b4c477fd" name="Changes" comment="Test gitlab push">
<change afterPath="$PROJECT_DIR$/.idea/checkstyle-idea.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/Clock.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/commands/Command.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/commands/Exit.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/commands/Print.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/commands/SetDelay.java" afterDir="false" />
<list default="true" id="885012ef-f9bd-49ba-ae4a-3de0b4c477fd" name="Changes" comment="Added while-loop and command methods">
<change afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/commands/Add.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/TrainDeparture.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/TrainDeparture.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/TrainDispatchApp.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/TrainDispatchApp.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/edu/ntnu/stud/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/edu/ntnu/stud/Main.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/edu/ntnu/stud/TrainDeparture.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/edu/ntnu/stud/TrainDeparture.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/edu/ntnu/stud/TrainDispatchApp.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/edu/ntnu/stud/TrainDispatchApp.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/commands/SetDelay.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/edu/ntnu/stud/commands/SetDelay.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -32,6 +23,9 @@
</list>
</option>
</component>
<component name="FormatOnSaveOptions">
<option name="myRunOnSave" value="true" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
......@@ -49,22 +43,23 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "false",
"git-widget-placeholder": "master",
"last_opened_file_path": "C:/Users/johan/OneDrive - NTNU/Dokumenter/programmering1/Train dispatch system/IDATT1003-2023-Mappe-TrainDispatchSystem-Template",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"settings.editor.selected.configurable": "preferences.pluginManager",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;code.cleanup.on.save&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/johan/OneDrive - NTNU/Dokumenter/programmering1/Train dispatch system/IDATT1003-2023-Mappe-TrainDispatchSystem-Template&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;actions.on.save&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager" selected="Application.TrainDispatchApp">
<configuration name="LocalTime" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="edu.ntnu.stud.LocalTime" />
......@@ -140,7 +135,11 @@
<workItem from="1697281569682" duration="334000" />
<workItem from="1697437763932" duration="6737000" />
<workItem from="1697540350806" duration="5001000" />
<workItem from="1697616758623" duration="13859000" />
<workItem from="1697616758623" duration="14822000" />
<workItem from="1697782536410" duration="3022000" />
<workItem from="1697795889522" duration="773000" />
<workItem from="1697796703125" duration="123000" />
<workItem from="1698043017141" duration="3989000" />
</task>
<task id="LOCAL−00001" summary="Initialized repo and made hello world">
<option name="closed" value="true" />
......@@ -163,7 +162,14 @@
<option name="presentableId" value="LOCAL−00003" />
<updated>1697437845699</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL−00004" summary="Added while-loop and command methods">
<option name="closed" value="true" />
<created>1697700893770</created>
<option name="number" value="LOCAL−00004" />
<option name="presentableId" value="LOCAL−00004" />
<updated>1697700893770</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
......@@ -172,6 +178,11 @@
<component name="VcsManagerConfiguration">
<MESSAGE value="Initialized repo and made hello world" />
<MESSAGE value="Test gitlab push" />
<option name="LAST_COMMIT_MESSAGE" value="Test gitlab push" />
<MESSAGE value="Added while-loop and command methods" />
<option name="LAST_COMMIT_MESSAGE" value="Added while-loop and command methods" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />
<select />
</component>
</project>
\ No newline at end of file
package edu.ntnu.stud;
import java.time.LocalTime;
public class Main {
public static void main(String[] args) {
LocalTime departureTime = LocalTime.of(12,30);
LocalTime delay = LocalTime.of(0,15);
TrainDeparture train = new TrainDeparture(departureTime,"L2","22","London", 4,delay);
System.out.println(train.informationBoard());
}
}
/** HUSK
/**
* HUSK
* lag en ny klasse som går på løkke og tilbyr tjenestene under
* Må ta inn objekter (dvs tog)
* kunne sortere objektene etter avreisetidspunkt (minst verdi først)
......@@ -26,4 +15,4 @@ public class Main {
* mulighet å ha en løkke som tilbyr tjenester med metoder gitt [1,2,3...]
* lage info-tavle
* if-setning på togavgang fjernes etter departure time og eventuelt delay er utløpt
* */
\ No newline at end of file
*/
\ No newline at end of file
package edu.ntnu.stud;
import edu.ntnu.stud.commands.Command;
import edu.ntnu.stud.commands.Exit;
import edu.ntnu.stud.commands.Print;
import edu.ntnu.stud.commands.SetDelay;
import java.util.Scanner;
import edu.ntnu.stud.commands.*;
import java.time.Clock;
import java.util.ArrayList;
import java.util.Scanner;
import java.time.LocalTime;
/**
* This is the main class for the train dispatch application.
*/
public class TrainDispatchApp {
public ArrayList<TrainDeparture> trains = new ArrayList<TrainDeparture>();
public LocalTime Clock(){
public static LocalTime Clock() {
return LocalTime.MIN;
}
public static void main(String[] args) {
TrainDispatchApp app = new TrainDispatchApp();
LocalTime departureTime = LocalTime.of(12, 30);
LocalTime delay = LocalTime.of(0, 15);
TrainDeparture train = new TrainDeparture(departureTime, "L2", "22", "London", 4, delay);
System.out.println(Clock());
System.out.println(train.informationBoard());
inputChoice(new TrainDispatchApp());
}
private static final Command[] COMMANDS = {
new SetDelay(),
new Print(),
new Exit()
new Exit(),
new Add()
};
public static void inputChoice(TrainDispatchApp app) {
......@@ -58,7 +62,6 @@ public class TrainDispatchApp {
}
//make a list with all train departures (objects)
// TODO: make clock
// TODO: make a loop with input-options
......
package edu.ntnu.stud.commands;
import edu.ntnu.stud.TrainDeparture;
import edu.ntnu.stud.TrainDispatchApp;
import edu.ntnu.stud.commands.Command;
import java.time.LocalTime;
import java.util.Scanner;
public class Add extends Command {
public Add() {
super("Add","Add a new train departure");
}
@Override
public boolean run(TrainDispatchApp app) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter departure time on format hh:mm");
String timeInput = sc.nextLine();
LocalTime departureTime = parseInput(timeInput);
String inputLine = "Enter the line";
String line = sc.nextLine();
//TODO if-loops to check whether or not no other train use the given line at the same time
String inputTrainNumber = "Enter train number";
String trainNumber = sc.nextLine();
//TODO check the number is availability
String inputDestination = "Enter the destination";
String destination = sc.nextLine();
String inputTrack = "Enter track";
int track = sc.nextInt();
//TODO set to -1 if no input is given
String inputDelay = "Enter delay on format hh:mm";
String delay = sc.nextLine();
LocalTime newDelay = parseInput(inputDelay);
TrainDeparture newTrain = new TrainDeparture(departureTime, line, trainNumber, destination, track, newDelay);
app.trains.add(newTrain);
return false;
}
private LocalTime parseInput(String input) {
String[] timeParts = input.split(":");
if(timeParts.length == 2){
try{
int hours = Integer.parseInt((timeParts[0]));
int minutes = Integer.parseInt(timeParts[1]);
//check if hours is less than 24 and minutes less tha 60
if (hours >= 0 && hours < 24 && minutes >=0 && minutes < 60){
return LocalTime.of(hours,minutes);
} else{
System.out.println("Invalid hours or minutes. Use hh:mm. Please try again");
}
} catch (NumberFormatException e){
System.out.println("Invalid input format. Please try again (hh:mm) ");
}
//If input is invalid, departureTime is set to midnight
} return LocalTime.MIN;
}
}
}
}
......@@ -12,11 +12,13 @@ public class SetDelay extends Command {
public SetDelay() {
super("Set delay", "Set the delay of a train departure");
}
@Override
public boolean run(TrainDispatchApp app) {
Scanner sc = new Scanner(System.in);
TrainDeparture trainDeparture = app.getTrainDeparture();
//TODO definer trainDeparture
//Ask user for new delay input
System.out.println("Enter the delay in the format hh:mm ");
......@@ -26,11 +28,12 @@ public class SetDelay extends Command {
LocalTime newDelay = parseDelayInput(delayInput);
//set new delay on TrainDeparture
trainDeparture.setDelay(newDelay);
return false;
//TODO get departure and delay, set on trainDeparture
}
private LocalTime parseDelayInput(String delayInput) {
String[] timeParts = delayInput.split(":");
......@@ -48,6 +51,7 @@ public class SetDelay extends Command {
System.out.println("Invalid input format. Please try again (hh:mm) ");
}
//If input is invalid, default to zero delay
} return LocalTime.MIN;
}
return LocalTime.MIN;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment