java程序设计英文_java 程序设计英文题

展开全部

***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 meetings;

private ArrayList birthdays;

public ScheduleImpl () {

meetings = new ArrayList();

birthdays = new ArrayList();

}

@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 

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()) 

result.append(birthdays.get(i).toString());

}

}

return result.toString();

}

@Override

public boolean overlapping() {

for (int i = 0; i 

for (int j = i + 1; 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 

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

–62616964757a686964616fe4b893e5b19e31333264623862 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

– expected return : True

e.g. A. 09:00 – 10:00 B. 09:00 – 10:00

***Part V***

All running times listed below are for average case.

running time of methods:

birthdays() O(n)

overlapping() O(n^2)

Recommendations on improvement:

Using sorted data (sort birthdays by date of birth, sort meetings by start time)

which takes O(n log n) to O(n^2) to sort (only needed once).

After sorting and implementing modified CRUD functions,

although create/delete functions will take O(log n) instead of O(1) to finish,

read/update functions will take O(log n) instead of O(n) to finish.

Additionally, birthdays() will take O(log n) instead of O(n) and

overlapping() will take O(n) instead of O(n^2).

In conclusion, applying these recommended improvements would significantly boost on overall performance, especially while dealing with large size datasets.

3bdbee24940ae34daf7ea0565ba58f2a.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值