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

Removed ClockUpdate as an own Commands class

parent 03ee14c7
No related branches found
No related tags found
No related merge requests found
/**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.Calendar;
import java.util.Scanner;
public class ClockUpdate extends Command {
public ClockUpdate() {
super("Update clock", "Update the clock by entering new time");
}
@Override
public boolean run(TrainDispatchApp app) {
Scanner sc = new Scanner(System.in);
System.out.println("Type in new time on format hh:mm: ");
String clockInput = sc.nextLine();
LocalTime newClock = parseInput(clockInput);
if (newClock != null) {
TrainDeparture.setClock(newClock);
System.out.println("The clock is now updated to " + TrainDeparture.getClock());
} else {
System.out.println("Invalid input format. Please try again (hh:mm) ");
}
return false;
}
private LocalTime parseInput(String clockInput) {
try {
String[] timeParts = clockInput.split(":");
if (timeParts.length == 2) {
int hours = Integer.parseInt(timeParts[0]);
int minutes = Integer.parseInt(timeParts[1]);
if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
return LocalTime.of(hours, minutes);
}
}
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
// Handle parsing errors here
}
return null;
}
}
*/
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment