Java代写:CS110 A Reminder App based on Objects

代写一个时间管理的App,需要用到面向对象程序设计。

Requirement

Our goal here is to use object-oriented programming, to define a simple calendar based reminder system, with which you can schedule events and be reminded of them.

There is much to do. Do as much as you can, but in a manner that my tests will not break your application.

You should define two classes:

  1. An Event class that encapsulates the date, time, and description of a scheduled event.
  2. A Reminder class that is made from the two classes, Calendar and Clock, from our handouts; you may use inheritance or composition. (See alarm1.py and alarm2.py.) But your code should depend only on Calendar and Clock; my test bed will provide both calendar.py and clock.py.

Class Reminder should implement (among others) a method, interact(), which, when invoked, will interact with a user. Commands include the following:

  • q – Quit.
  • ? – Display a summary of commands.
  • t – Show the ‘current’ date and time. The Reminder keeps it’s own time, initially the real date and time. Its time (and date) are advanced only in response to commands.
  • e – Schedule an event, consisting of a date, a time and an event description, separated by commas. A date consists of an (integer) month, day, and (optionally) a year, separated by the “/“. If the year is left out, it’s 2016 by default. A time consists of an (integer) hour (on a 24-hour clock) and an (integer) minute, separated by the colon. We ignore seconds here.
  • s – Search for scheduled events that contain all of the strings in the given list, and print them out.
  • x – Delete all of the events found using the previous s command. One may want to repeat the s command with a more specific key (list of strings) before deleting events.
  • p – Print out all scheduled events.
  • m – Advance the reminder’s own sense of time by n minutes; if n is omitted, 1 is assumed. The reached time is printed. Any events whose times are reached, are announced (displayed) before the reached time is printed.
  • h – Advance the reminder’s own sense of time by n hours; if n is omitted, 1 is assumed. The reached time is printed. Any events whose times are reached, are announced (displayed) before the reached time is printed.
  • d – Advance the reminder’s own sense of time by n days; if n is omitted, 1 is assumed.
  • w – Write out the currently scheduled events to the named file. Anything in the file is overwritten. But the events remain scheduled.
  • r – Read in and schedule events from the named file. These replace all currently scheduled events. Any events that have passed (with times less than the ‘current’ time are ignored.

Several important points:

  1. You can, and should define both classes, Event and Reminder in the file reminder.py; that should be your only Python file.
  2. You should depend only on the classes, Clock and Calendar, in clock.py and calendar.py respectively. You can import these. You may use other Python packages. I used time and copy.
  3. Your scheduled events should maintain the invariant that no scheduled events are past due. That is, end scheduling of an event in the ‘past’ is rejected and ignored; any past due event loaded from a file (including init.txt at the start) is ignored. Announcing an event (when its time comes) causes it to be removed from the list of scheduled events.
  4. Events should be announced when their time comes. This can be detected after each command that advances time: m, h or d.
  5. At the start of the interact() loop, before any commands are even prompted for (ie before the command loop), interact() reads and schedules events from the file init.txt. If this file doesn’t exist, nothing happens.
  6. At the end of interaction (ie after a q command, or even after leaving the command loop itself), all remaining scheduled events are written to the file named, init.txt.
  7. Your task is much easier if you keep the list of scheduled events sorted by time, earliest first. I keep track of epoch time (see the documentation for Python’s time package).
  8. Handle exceptions as best you can. The important thing is not to be thrown out of the command loop by an exception that is raised. Catch it inside the loop. Otherwise, provide as meaningful error messages as you can (when catching exceptions).

An example run:

>>> r = Reminder()
>>> r.interact()
Loading events from init.txt.
No init.txt file found; no events pre-loaded.
11/27/2016, 17:10
> e 11/27/2016, 17:15, Test 1
11/27/2016, 17:15,  Test 1
> e 11/27/2016, 18:15, Test 2
11/27/2016, 18:15,  Test 2
> e 11/27/2016, 19:15, Test 3
11/27/2016, 19:15,  Test 3
> e 11/27/2016, 20:15, Test 3
11/27/2016, 20:15,  Test 3
> p
11/27/2016, 17:15,  Test 1
11/27/2016, 18:15,  Test 2
11/27/2016, 19:15,  Test 3
11/27/2016, 20:15,  Test 3
> h
***** Reminder *****
11/27/2016, 17:15,  Test 1
11/27/2016, 18:10
> p
11/27/2016, 18:15,  Test 2
11/27/2016, 19:15,  Test 3
11/27/2016, 20:15,  Test 3
> ?

Reminder Commands:
  q       [for quit]
  ?       [ask for help]
  t       [print 'current' time]
  e , ,  [schedule event]
  s      [search for event with all strings]
  x       [delete found event]
  p       [print scheduled events]
  m    [advance time  minutes, one if no ]
  h    [advance time  hours, one if no ]
  d    [advance time  days, one if no ]
  w   [write scheduled events to the named file.]
  r   [read and schedule events from the named file.]


> w foo.txt
> s ("Test 3")
11/27/2016, 19:15,  Test 3
11/27/2016, 20:15,  Test 3
> x
2 events removed.
> p
11/27/2016, 18:15,  Test 2
> r foo.txt
11/27/2016, 18:15,   Test 2
11/27/2016, 19:15,   Test 3
11/27/2016, 20:15,   Test 3
> p
11/27/2016, 18:15,   Test 2
11/27/2016, 19:15,   Test 3
11/27/2016, 20:15,   Test 3
> t
11/27/2016, 18:10
> m 4
11/27/2016, 18:14
> m
***** Reminder *****
11/27/2016, 18:15,   Test 2
11/27/2016, 18:15
> m20
11/27/2016, 18:35
> p
11/27/2016, 19:15,   Test 3
11/27/2016, 20:15,   Test 3
> q
Scheduled events saved to init.txt.
>>> r = Reminder()
>>> r.interact()
Loading events from init.txt.
11/27/2016, 19:15,    Test 3
11/27/2016, 20:15,    Test 3
11/27/2016, 17:15
> q
Scheduled events saved to init.txt.
>>> r = Reminder()
>>> r.interact()
Loading events from init.txt.
11/27/2016, 19:15,     Test 3
11/27/2016, 20:15,     Test 3
11/27/2016, 17:17
> p
11/27/2016, 19:15,     Test 3
11/27/2016, 20:15,     Test 3
> h
11/27/2016, 18:17
> h
***** Reminder *****
11/27/2016, 19:15,     Test 3
11/27/2016, 19:17
> p
11/27/2016, 20:15,     Test 3
> h
***** Reminder *****
11/27/2016, 20:15,     Test 3
11/27/2016, 20:17
> q
Scheduled events saved to init.txt.
>>>

Here is an example where exceptions were detected. The important thing is not to be thrown out of the command loop, no matter what the error. Otherwise, try to provide meaningful errors. For example,

>>> r = Reminder()
>>> r.interact()
Loading events from init.txt.
No init.txt file found; no events pre-loaded.
11/27/2016, 17:30
> e xxx
Badly formed event.
> r silly.txt
Error in loading events from silly.txt.
> y
Say what?
> q
Scheduled events saved to init.txt.
>>>

You should submit two files to the vault for homework6:

  1. memo.txt – This will contain a (plain-text) narrative explaining the design of your solution, how you tested it and the results of test runs.
  2. reminder.py – your Python program defines the two classes, Event and Reminder. It should load silently; we will test it with something like,

Don’t forget your docstrings!
Have fun!