I need to write a method to cancel the appointment scheduled at the given time, if it exists and return true if an appointment was canceled, and false otherwise.
Here is my thinking process shown in some steps:
1) make a StringTokenizer and a temporary string 2) loop while tokens still exist 3) check if the appointment exists, if not return false. 4) use an if statement to check if the substring of the token indicating time is equal to the time passed through the parameter (isBooked checks to see if they have the same time, if they do, then apptment must be cancelled) -if true: dont add it to the temp string -if false: add the token to the temp string 5)loop ends, return true
Here is the code that I attempted to do so far, I tried lots of things and I am quite frustrated at this point, I know it doesnt work. No arrays allowed, or else my life would be so much easier. Any tips, hints, suggestions would be GREATLY appreciated.
String st = "^14%Paul's house?Group Meeting,^9%Nutty Professor's Office?Office Hours,^12%MegaBits?Lunch ";
int time = 10;
appointment ap1 = new appointment();
Joined: Dec 15, 2002
Thanks for all the suggestions and input, I am currently going through all the code to see how it works and whether it helps accomplish my task or not. I might have not been clear enough in my first post, I'll reclarify.
the schedule will actually be in this form, containing many appointments:
There are no commas separating. The only delimiters are ^ % ? and \n (no \n for the last line).
What it's supposed to do is first see if the time, integer appStart, matches with the given time. If it matches, then the appointment at that specific time, or shall I say, the whole line "^atthatspecifictime%location?description\n" will be removed. The only way I can think of doing this is by readding all the tokens into a temp string and then assigning the temp string (updated string without that specific line) into the schedule string.
If I call the cancelmethod, say cancelAppointment(9), I need to take out the appointment specifically at 9, then my new schedule string will be like "^14%Paul's house?Group Meeting\n^12%MegaBits?Lunch".
And since I wrote a method earlier to check if the appointment exists at a given time, I can use that to see if the appointment exists. Using the example above, if there exists an appointment at 9, I want to cancel it, or "remove it", then return true, if it does not exist, there is nothing to cancel, so I simply return false.
Joined: Dec 15, 2002
Tried doing some more, confused at this point..
Need to somehow add all the tokens to one string excluding ones that I dont want..