| | |
hey i need some help looking over my coding
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2009
Posts: 5
Reputation:
Solved Threads: 0
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.
is my coding right?
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.
Java Syntax (Toggle Plain Text)
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?
-1
#2 Nov 2nd, 2009
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)
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
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...
Java Syntax (Toggle Plain Text)
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; }
Java Syntax (Toggle Plain Text)
int index = CalenderEvent.indexOf(new CalenderEvent(year, month, day, hour, minute, duration, what));
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...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Nov 2009
Posts: 5
Reputation:
Solved Threads: 0
0
#3 Nov 2nd, 2009
Java Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- New technology apostle on the rise (Community Introductions)
- Need java source code for cross matching two large access database records (Java)
- Need help in sudoku coding 4 by 4 dimentional. (JavaScript / DHTML / AJAX)
- Relaxing while coding (Geeks' Lounge)
- Hey guys. (Community Introductions)
- Random number Generation (C)
- Help with search coding (ASP)
- Malthusian Equation Help (Java)
- Getting rid off the border round link images (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: Need Initials
- Next Thread: simple non gui menu
Views: 220 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool keyword linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






