java 程序设计英文题Question 3 Design [30 marks]Suppose you are asked to write an organizer program that stores both scheduled meetings and birthdays.Both scheduled meetings and birthdays have a label that describes the meeting or name of the p
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 11:45:34
java 程序设计英文题Question 3 Design [30 marks]Suppose you are asked to write an organizer program that stores both scheduled meetings and birthdays.Both scheduled meetings and birthdays have a label that describes the meeting or name of the p
java 程序设计英文题
Question 3 Design [30 marks]
Suppose you are asked to write an organizer program that stores both scheduled meetings and birthdays.Both scheduled meetings and birthdays have a label that describes the meeting or name of the person whose birthday it is.Scheduled meetings also have a start time,end time,and location (locations are just stored as strings),whereas birthdays only have the name of the person(which is the
label) and a date of the birthday.The standard Java Date class may be used to store times/dates.
Assume the meeting/birthday information may be added to your program in any order.The class which stores all the meetings and birthdays must have the following methods :
● birthdays() - returns,as a String,the list of birthdays that will occur within the next 7 days.
● overlapping() - returns true if and only if any scheduled meetings are overlapping in time.
Note that,you are not expected to design/implement any code which loads this information from a file or inputs it from a user.
i.[5 marks] What question(s) would you ask the client to help refine the specification?State any reasonable assumptions you make to answer these question(s).Use these assumptions for the following parts of this question.
ii.[10 marks] Draw the UML Class diagram for your design.Include fields and methods within the class diagram.
iii.[5 marks] Implement the classes stated in your design.
iv.[5 marks] State what test cases you would use to help validate the "overlapping" method.
v.[5 marks] Use the big O notation to analysis the worst case complexity of the "birthdays" and "overlapping" methods.Discuss if any improvements could be made on this.All your answers to this question should be saved in this directory.The code for part iii must be saved in ".java" files,the other answers place in a file called "Q3answers.odt".Use 'ooffice' to edit this 'odt' file.
既然我给了100分就是希望能详细点,如果连图都有的话再加100也没问题,望高手速来,
各位是不是都理解错了,我要的不是翻译,我要的是程序设计啊...
java 程序设计英文题Question 3 Design [30 marks]Suppose you are asked to write an organizer program that stores both scheduled meetings and birthdays.Both scheduled meetings and birthdays have a label that describes the meeting or name of the p
***Part I***
It is assumed that "today" is excluded from "within the next 7 days".
It is assumed that birthday is stored as Date type with value of 0 for hours,
minutes and seconds.
It is assumed that a meeting can be hold right after previous one finished.
In other words, Meeting A, with finishing time of 10:00:00,
and Meeting B, with a starting time of 10:00:00,
are not considered as overlapped.
It is assumed that meeting with a duration of 0 seconds is valid and can cause
Overlapping.
It is assumed that this schedule system may have further update with more types of
events.
It is assumed that every type of events will have at least a label with String
type and a time with Date type.
It is assumed that different types of events should be handled separately.
***Part II***
See attached image.
***Part III***
ScheduleImpl.java
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
public class ScheduleImpl implements Schedule {
private ArrayList<Meeting> meetings;
private ArrayList<Birthday> birthdays;
public ScheduleImpl () {
meetings = new ArrayList<Meeting>();
birthdays = new ArrayList<Birthday>();
}
@Override
public void add(Event item) {
}
@Override
public void add(int type, Event item) {
}
@Override
public void get(String label) {
}
@Override
public void get(int type, int position) {
}
@Override
public void update(String label, Event item) {
}
@Override
public void update(int type, String label, Event item) {
}
@Override
public void remove(String label) {
}
@Override
public void remove(int type, String label) {
}
@Override
public void sort() {
}
@Override
public String birthdays() {
StringBuilder result = new StringBuilder();
result.append("List of birthdays in next 7 days:");
for (int i = 0; i < birthdays.size(); i++) {
Date b = birthdays.get(i).getDOB(); // Birthday
Calendar t = Calendar.getInstance(); // Today
Calendar n = Calendar.getInstance();
n.add(Calendar.WEEK_OF_YEAR, 1); // Next 7 days
if (b.compareTo(t.getTime()) > 0 && b.compareTo(n.getTime()) < 0) {
result.append(birthdays.get(i).toString());
}
}
return result.toString();
}
@Override
public boolean overlapping() {
for (int i = 0; i < meetings.size() - 1; i++) {
for (int j = i + 1; j < meetings.size(); j++) {
Date s1 = meetings.get(i).getStartTime();
Date s2 = meetings.get(j).getStartTime();
Date f1 = meetings.get(i).getFinishTime();
if (s1.compareTo(s1) <= 0 && f1.compareTo(s2) > 0) {
return true;
}
}
}
return false;
}
}
interface Schedule {
public static final String DATE_FORMAT = "EEE dd-MM-yyyy";
public static final String TIME_FORMAT = "HH:mm:ss";
public static final int MEETING = 0;
public static final int BIRTHDAY = 1;
void add(Event item);
void add(int type, Event item);
void get(String label);
void get(int type, int position);
void update(String label, Event item);
void update(int type, String label, Event item);
void remove(String label);
void remove(int type, String label);
void sort();
String birthdays();
boolean overlapping();
}
class Event {
protected static final SimpleDateFormat DATE_FORMATTER =
new SimpleDateFormat(Schedule.DATE_FORMAT);
protected static final SimpleDateFormat TIME_FORMATTER =
new SimpleDateFormat(Schedule.TIME_FORMAT);
private String label;
private Date Date;
protected String getLabel() {
return label;
}
protected void setLabel(String label) {
this.label = label;
}
protected Date getDate() {
return Date;
}
protected void setDate(Date date) {
this.Date = date;
}
}
class Birthday extends Event {
public Birthday (String name, Date dateOfBirth) {
setLabel(name);
Calendar dob = Calendar.getInstance();
dob.setTime(dateOfBirth);
dob.set(Calendar.HOUR, 0);
dob.set(Calendar.MINUTE, 0);
dob.set(Calendar.SECOND, 0);
setDate(dob.getTime());
}
public String getName() {
return getLabel();
}
public Date getDOB() {
return getDate();
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append(getName());
for (int i = getName().length() / 8; i < 4; i++) {
result.append("\t");
}
result.append("- ");
result.append(DATE_FORMATTER.format(getDOB()));
return result.toString();
}
}
class Meeting extends Event {
private Date finishTime;
private String location;
public Meeting (String description, Date startTime, Date finishTime,
String location) {
setLabel(description);
setDate(startTime);
this.finishTime = finishTime;
this.location = location;
}
public String getDescription() {
return getLabel();
}
public void setDescription(String description) {
setLabel(description);
}
public Date getStartTime() {
return getDate();
}
public void setStartTime(Date startTime) {
setDate(startTime);
}
public Date getFinishTime() {
return finishTime;
}
public void setFinishTime(Date finishTime) {
this.finishTime = finishTime;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append(getDescription());
result.append(":\n");
result.append(DATE_FORMATTER.format(getStartTime()));
result.append(" from ");
result.append(TIME_FORMATTER.format(getStartTime()));
result.append(" to ");
result.append(TIME_FORMATTER.format(getFinishTime()));
result.append("\nAt: ");
result.append(getLocation());
return result.toString();
}
}
***Part IV***
Test case 1: separated meetings
– expected return : False
e.g. A. 09:00 – 10:00 B. 11:00 – 12:00
Test case 2: consequent meetings
– expected return : False
e.g. A. 09:00 – 10:00 B. 10:00 – 11:00
Test case 3: partially overlapped meetings
– expected return : True
e.g. A. 09:00 – 10:00 B. 10:30 – 11:30
Test case 4: partially overlapped meetings (same start time)
– expected return : True
e.g. A. 09:00 – 10:00 B. 09:00 – 09:30
Test case 5: entirely overlapped meetings
– expected return : True
e.g. A. 09:00 – 12:00 B. 10:00 – 11:00
Test case 6: entirely overlapped meetings (same start time)
– expected return : True
e.g. A. 09:00 – 12:00 B. 09:00 – 10:00
Test case 7: exactly overlapped meetings