Hi everyone! I need help writing a program to get a starting time from the user, getting a period from the user, getting the number of points from the user, and outputting the number of points the user wants with their period as the interval starting from their start time. Here is what it should look like:
I have written the test code but I am having a lot of trouble writing the actual code. If somebody could please help me out it would be much appreciated! I am fairly new java so this is pretty difficult for me. Here is my test program:
And here is my actual program:
I this I am on the right track but I am having trouble getting integers from my TestTime class into my Time class. I am also having trouble setting the given time into hours:minutes format and also outputting the final times in the same hours:minute format. Thank you ahead of time for the help!
Enter start time as hours minutes in 24-hour format 12 34 Enter period amount in minutes 15 Enter number of time points requested 10 Time points starting at 12:34 and every 15 minutes: 12:34 12:49 13:04 13:19 13:34 213:49 14:04 14:19 14:34 14:49 15:04
I have written the test code but I am having a lot of trouble writing the actual code. If somebody could please help me out it would be much appreciated! I am fairly new java so this is pretty difficult for me. Here is my test program:
import java.util.Scanner; public class TestTime { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter start time as hours minutes in 24-hour format"); int startHour = input.nextInt(); int startMinute = input.nextInt(); System.out.println("Enter period amount in minutes"); int period = input.nextInt(); System.out.println("Enter number of time points requested"); int numTimePoints = input.nextInt(); Time startTime = new Time(startHour, startMinute); System.out.println("Time points starting at " + startTime + " and every " + period + " minutes:"); Time currentTime = startTime; System.out.println(currentTime); for(int i=0; i<numTimePoints; i++) { currentTime = currentTime.advanceMinutes(period); System.out.println(currentTime); } } }
And here is my actual program:
public class Time { private int hours; private int minutes; private int time; TestTime tt = new TestTime(); //Sets time to 0:00 (12 midnight) public Time() { tt.startHour = 0; tt.startMinute = 00; } //Initializes this to the given time public Time (int hours, int minutes) { hours = tt.startHour; minutes = tt.startMinute; time = (hours * 60) + minutes; } //Set this to the given time public void set(int hours, int minutes) { } //Get the hour public int getHours() { return hours; } //Get the minutes public int getMinutes() { return minutes; } //Return a Time object that is minutes ahead of this time public Time advanceMinutes(int minutes) { return minutes = time + tt.period; } //Print this time in hours:minutes format. Appends a 0 if hours/minutes is a single digit public String toString() { int hours1 = minutes / 60; int remainder = minutes % 60; } }
I this I am on the right track but I am having trouble getting integers from my TestTime class into my Time class. I am also having trouble setting the given time into hours:minutes format and also outputting the final times in the same hours:minute format. Thank you ahead of time for the help!