Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Help!! Schedual class with time and date

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help!! Schedual class with time and date

    I am in need of some help to solve a task but I have no clue how to do!!
    The task is to design and implement a class representing a schedule. It should be possible to add and remove moments and I can use ints to represent date and time and it should be a method that checks that no moments collide, the method should not write anything but retur a boolean!
    Now this is how far I have gotten:

    import java.util.ArrayList;
    public class Schema {
    private static final int MAX = 31;
    private ArrayList<Integer> numbers = new ArrayList<Integer>();

    private boolean okNumber(int i) {
    return i >= 0 && i <= MAX;
    }
    public void add(int i) {
    if (okNumber(i) && !numbers.contains(i) ){
    numbers.add(i);
    }
    }
    public void delete(int i) {
    if (okNumber(i))
    numbers.remove((Integer) i);
    }

    The problem is how to get the time in the class, i have no idéa and would be very happy for any help!!


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help!! Schedual class with time and date

    You said that you could use ints to represent time, but did you know that Java already has Calendar and Date classes that are very useful for this kind of thing? Can you use those?

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help!! Schedual class with time and date

    I can use those too, however wouldnt the class be more complicated by using them? Since its only a class and not a program? (Sry i am a beginner)

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help!! Schedual class with time and date

    I understand the beginner's concern that MoreClasses = MoreComplicated.

    That's simply not true if the MoreClasses side of the equation is mostly classes that already exist in Core Java. That means someone else has already done a lot of the work so you won't have to.

    Build your program on the backs of those who've gone before you, hopefully writing good code for you to use. Their efforts should save you work and get you started the right direction.

  5. #5
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help!! Schedual class with time and date

    thanks for the tips, would be very helpful with some code since i have no idéa how to do. Can i still use a arraylist, and if i still would want to use int how should i do it?

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help!! Schedual class with time and date

    There are many tutorials with example code on the web for Java Calendar, GregorianCalendar, Date, etc. Dive in and start reading and writing.

  7. #7
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help!! Schedual class with time and date

    the thing is, ive got a "OK" on what ive done sofar, how can i complete the class that i have started??

    --- Update ---

    shoul i use objects instead of ints to combine time and date (int, int)

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help!! Schedual class with time and date

    Whether you use existing classes for dates and times or develop your own, the Schedule class you're designing will have to contain events with names, start and stop dates and times, and the methods needed to do the checking you've described. At a minimum, I suggest you need an Event class (or the name of your choice) to describe the events which will make up the items in the schedule.

    If you proceed down the events as ints path, how will you name the items? How will you determine start and stop dates and times. For the latter, you could count the number of minutes from some point in time (your birthday?) and then calculate the date and time of day from that, but that's where using the existing classes begins to look a lot more attractive.

    It's not an easy problem, and I'm not sure you've thought it through very far. Give your design some more thought and determine how you'd answer some of the questions I've raised. Others will probably occur to you as you proceed.

Similar Threads

  1. Using Date() to get Start Time and Finish Time of a copyFiles method
    By dalythe in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 17th, 2013, 09:50 PM
  2. Parsing a full date/time/timezone date to "yyyy-MM-dd"
    By Occidentally in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 4th, 2012, 08:57 AM
  3. Date and Time Picker
    By Hrithik in forum Java Theory & Questions
    Replies: 3
    Last Post: September 25th, 2012, 08:55 AM
  4. [SOLVED] how to get phone time and date
    By mahdi in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: August 26th, 2009, 11:15 AM
  5. How to Get the current date and time
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 2
    Last Post: December 2nd, 2008, 01:55 PM

Tags for this Thread