hey i need some help looking over my coding

Reply

Join Date: Nov 2009
Posts: 4
Reputation: bkafroboy69 is an unknown quantity at this point 
Solved Threads: 0
bkafroboy69 bkafroboy69 is offline Offline
Newbie Poster

hey i need some help looking over my coding

 
-1
  #1
21 Days Ago
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.


  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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,177
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer
 
0
  #2
21 Days Ago
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)
  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
  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...
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: bkafroboy69 is an unknown quantity at this point 
Solved Threads: 0
bkafroboy69 bkafroboy69 is offline Offline
Newbie Poster
 
0
  #3
21 Days Ago
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #4
21 Days Ago
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.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC