Can anyone help me check where is my problem?
Question as bellow:
Write a program to implements an interview scheduler.
These are the requirements for the interview scheduler:
A prompt asks the executive secretary to input the time for the first interview, and then a loop continues to prompt for input of subsequent interview, and then a loop continues to prompt for input of subsequent interview times. Input terminates when the secretary enters a time at or after 5:00 pm. A loop executes pop() operations until the queue is empty. Each iteration outputs the time that the appointment begins, along with the amount of the time available for the director to carry out the interview. When the queue becomes empty, the time for the last interview is the difference between the office-closing time of 5:00 pm开发者_如何学运维. and the prior starting time for the last interview.
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class TimeSchedule {
public static void main(String args[]) {
Queue TimeList = new LinkedList();
DateFormat df = new SimpleDateFormat("HH:mm");
df = DateFormat.getDateInstance(DateFormat.LONG);
boolean loopstoper = false;
try {
Date limit = df.parse("17:00");
Scanner scan = new Scanner(System.in);
String time = scan.nextLine();
Date date = df.parse(time);
while (loopstoper == false) {
if (date.before(limit)) {
TimeList.offer(date);
} else {
loopstoper = true;
while (TimeList.size() > 0) {
System.out.println("Time Schedule = " + TimeList.poll());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
please help me check my work correct or not because it cannot run in Netbean software? Is that answer match that question? Thanks for your helping.
Well I copied your code and ran it - right off the bat
Date limit = df.parse("17:00");
line generated an error until I commented out the
df = DateFormat.getDateInstance(DateFormat.LONG);
line.
Next I note that you have a poorly formed loop, you scan in data then start your loop but never scan in anymore data - classic infinite loop.
See what you can do to fix these problems first. That first error was obvious and should have been found by you easily - if I am going to do your work I should be getting paid for it.
EDIT
Couple of additional comments. Do you have to use a LinkedList? Can the times come out of sequence, that is enter in 11am then 10am then 2pm? I suspect what you want is a simple sortable list - a simple ArrayList would do fine. Is there a duration parameter - can I enter 11am then 11:01am? Pretty short interview ;-)
Does this compile and run okay as is? The only thing that I can see that you're missing is the amount of time that the Director has for the current interview. I believer your instructions state that it is simply the difference between the start time of the current interview and the next (unless it's the last interview of the day, in which case use 5:00pm.)
精彩评论