944,156 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 405
  • Java RSS
Nov 2nd, 2009
-1

hey i need some help looking over my coding

Expand Post »
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.


Java Syntax (Toggle Plain Text)
  1. public boolean addEvent(int year, int month, int day,
  2. int hour, int minute, int duration, String what){
  3. int index = CalenderEvent.indexOf(CalenderEvent);
  4. return index != 0;
  5. }
  6. public CalenderEvent findNextEvent(int year, int month, int day,
  7. int hour, int minute){
  8. if(CalenderEvent != CalenderEvent)
  9.  
  10. return null;
  11. return null;
  12. }
  13. public boolean removeEvent(int id) {
  14. if(id==id)
  15. return true;
  16. return f


is my coding right?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bkafroboy69 is offline Offline
10 posts
since Nov 2009
Nov 2nd, 2009
-1
Re: hey i need some help looking over my coding
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)
Java Syntax (Toggle Plain Text)
  1. public boolean addEvent(int year, int month, int day,
  2. int hour, int minute, int duration, String what){
  3. int index = CalenderEvent.indexOf(CalenderEvent);
  4. return index != 0;
  5. }
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
Java Syntax (Toggle Plain Text)
  1. 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...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Nov 2nd, 2009
0
Re: hey i need some help looking over my coding
Java Syntax (Toggle Plain Text)
  1. final public class CalenderEvent implements Comparable<Object> {
  2. private static int count = 0;
  3. final private Date Date;
  4. final private Time startTime;
  5. private int duration;
  6. final private String what;
  7. final private String where;
  8. final private String description;
  9. final private int id;
  10. final private boolean valid;
  11.  
  12. public CalenderEvent(int year, int month, int day,
  13. int hour, int minute, int duration, String what){
  14. count++;
  15. Date = new Date(month, day, year);
  16. startTime = new Time(hour, minute);
  17. this.duration= minute;
  18. this.what = what;
  19. this.where = toString();
  20. this.description = toString();
  21. this.id = count;
  22. this.valid=isValid(0, 0, 0);
  23.  
  24. }
  25. public static int getCount() {
  26. return count;
  27.  
  28.  
  29. }
  30. public Time getEndTime(int duration) {
  31. this.duration=this.duration+duration;
  32. if(this.duration>=60)
  33. {
  34. CalenderEvent.count=this.count+(this.duration/60);
  35. this.duration=this.duration%60;
  36. }
  37. return startTime ;
  38. }
  39.  
  40.  
  41. public Date getDate() {
  42. return Date;
  43. }
  44. public Time getStartTime() {
  45. return startTime;
  46. }
  47. public int getDuration() {
  48. return duration;
  49. }
  50. public String getWhat() {
  51. return what;
  52. }
  53. public String getWhere() {
  54. return where;
  55. }
  56. public String getDescription() {
  57. return description;
  58. }
  59. public int getId() {
  60. return id;
  61. }
  62. public boolean isValid(int Date, int startTime, int duration) {
  63. if (Date > Date || Date < Date)
  64. return false;
  65. if (startTime < startTime || startTime > startTime)
  66. return false;
  67. if (duration < 0 || duration > 60)
  68. return false;
  69.  
  70. return true;
  71. }
  72. public int compareTo(Object obj) {
  73. CalenderEvent otherObj = (CalenderEvent)obj;
  74. double result = getDate() - getStartTime() ;
  75. if (result > 0)
  76. return 1;
  77. else if (result < 0)
  78. return -1;
  79. return 0;
  80.  
  81. }
  82.  
  83. public String toString(){
  84. if(isValid(duration, duration, duration) == true) {
  85. return what+ " on "+Date+" at "+startTime+" for "+duration;}
  86. else return what+ " on "+Date+" at "+startTime+" for "+duration +" is not valid";
  87. }
  88.  
  89.  
  90.  
  91. }

here is the calenderevent class maybe this can clear things
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bkafroboy69 is offline Offline
10 posts
since Nov 2009
Nov 2nd, 2009
0
Re: hey i need some help looking over my coding
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.
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Need Initials
Next Thread in Java Forum Timeline: simple non gui menu





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC