我正在编写一个允许用户参加大学课程的网络应用程序.课程可以在某些时间段给出 - 时间段是一天(一周,即周日,周一等)和一小时.有固定的时间段可以提供课程.我的问题是 - 实现这些时间段的最佳方法是什么?
我有一个想法就是使用枚举,但是有70个时隙.所以我想有两个枚举 - 一个用于工作日(虽然我打赌这已经存在于某个地方 - 你知道我在哪里可以找到这种类型的现有枚举吗?)和一个允许的小时数(例如 - 8:00 ,9:00,10:00等)并且有一个Timeslot班级同时举行这两个.
但是,我觉得必须有一个我没有想过的更优雅的解决方案 - 你怎么看?
就我个人而言,我认为单个枚举是一个完美的解决方案,尽管我同意在这种情况下它有点难看。
我可能会用这个接口实现一个类:
class ScheduledTime {
int time;
HashMap days<int, string>;
Time(String day, int hour) //Inits the "time" variable with this formula: day*10 + hour - someNum.
(someNum so that hour - someNum is 0)
boolean compareTo()/equals(); (just compare time)
String getDay()// Divide by 10 to get a number from 0 to 6, then just convert to sunday-monday.
int getTime() //Mod by 10 and then add someNum.
}
Run Code Online (Sandbox Code Playgroud)
使用 HashMap 将天数(0 到 6)转换为字符串,反之亦然。在构造函数期间实例化它。
| 归档时间: |
|
| 查看次数: |
7226 次 |
| 最近记录: |