public boolean addEvent(int year, int month, int day, int hour, int minute, int duration, String what);
This will return true if the event was added and false otherwise. Only valid events will be added to the list.

Also write:
public CalendarEvent findNextEvent(int year, int month, int day, int hour, int minute);
return the next event that starts at a time at or after the given time. If more than one such event exists, return one that has the smallest duration.

Write:
public boolean removeEvent(int id);
If an event with this id exists, remove it and return true. Otherwise, return false.

public boolean addEvent(int year, int month, int day, 
			 int hour, int minute, int duration, String what){	 
	int index = CalenderEvent.indexOf(CalenderEvent);
		return index != 0;
			} 
	 public CalenderEvent findNextEvent(int year, int month, int day, 
			 int hour, int minute){
		 if(CalenderEvent != CalenderEvent)
		 
				return null;
		return null;	 
			} 
	 public boolean removeEvent(int id) {
		 if(id==id)
		return true;
		return f

is my coding right?

Recommended Answers

All 3 Replies

Without knowing what is CalenderEvent structure like and how requested methods are called I see mistakes in all of them (wouldn't be surprised if you are supposed to use Generics and Collections in this)

public boolean addEvent(int year, int month, int day, 
			 int hour, int minute, int duration, String what){	 
	int index = CalenderEvent.indexOf(CalenderEvent);
		return index != 0;
			}

Presuming that your class CalendarEvent has method indexOf that accept CalendarEvent as argument this will not work as you did not initialized CalendarEvent object. This is more likely what you looking for

int index = CalenderEvent.indexOf(new CalenderEvent(year, month, day, hour, minute, duration, what));

This goes same for second method.

Last method will always be true because you are comparing same "id" values. So if the id did not exist it will attempt to delete event with this id and either your application will kick some errors and complain about deleting something that doesn't exists or it will do nothing and tell "yeah sure I delete it..."

Without more background info there is no way to help you with this...

final public class CalenderEvent implements Comparable<Object> {
	private static int count = 0;
	final private  Date Date;
	final private  Time startTime;
	private  int duration;
	final private  String what;
	final private  String where;
	final private  String description;
	final private  int id;
	final private  boolean valid;
	
	public CalenderEvent(int year, int month, int day, 
			int hour, int minute, int duration, String what){
		count++;
	Date = new Date(month, day, year);
    startTime = new Time(hour, minute);
    this.duration= minute;
    this.what = what;
    this.where = toString();
    this.description = toString();
    this.id = count;
    this.valid=isValid(0, 0, 0);
	
	}
	public static int getCount() { 
	      return count; 
	   
	
	}
	 public Time getEndTime(int duration) {
		 this.duration=this.duration+duration;
			if(this.duration>=60)
			{
			CalenderEvent.count=this.count+(this.duration/60);
			this.duration=this.duration%60;
			}
			return startTime ;
	}

	
	public Date getDate() {
		return Date;
	}
	public Time getStartTime() {
		return startTime;
	}
	public int getDuration() {
		return duration;
	}
	public String getWhat() {
		return what;
	}
	public String getWhere() {
		return where;
	}
	public String getDescription() {
		return description;
	}
	public int getId() {
		return id;
	}
	public boolean isValid(int Date, int startTime, int duration) {
		if (Date > Date || Date < Date)     
			return false;
        if (startTime < startTime || startTime > startTime) 
        	return false;
        if (duration < 0 || duration > 60) 
        	return false;

		return true;
	}
	public int compareTo(Object obj) {
		CalenderEvent otherObj = (CalenderEvent)obj;
		double result = getDate() - getStartTime() ;
		if (result > 0)
	         return 1;
	      else if (result < 0)
	         return -1;
	      return 0;

	}

	public String toString(){
		if(isValid(duration, duration, duration) == true) {
		return what+ " on "+Date+" at "+startTime+" for "+duration;}
   else return what+ " on "+Date+" at "+startTime+" for "+duration +" is not valid";
	}
	
	

}

here is the calenderevent class maybe this can clear things

Look at java doc java.util.Calendar and java.util.GregorianCalendar classes. Nice implemented interfaces, constructors and methods. Nice examples. Their use will reduce drastically the volume of code.
Most of Date methods are deprecated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.