Forums Register Login

My first attempt at an app: a simple calendar

+Pie Number of slices to send: Send
Hello everyone. First time poster, long-ti just started to read this place after seeing it in an O'Reilly book.

I'm taking my first Java lessons. To get some practice I've been trying to make my Very First Application (that isn't retyped word-for-word from a coursebook) but I may have skipped ahead farther than I can handle.

My goal is to make a program that, when run, prints my next class to a command prompt, along with the room number and start/end time of the class. The way I've been doing this is:

- Make a class Interface creates all the Course objects and handles printing the result
- Make a class Course with the name, start time, end time, day of week and room of the course as variables
- Import the calendar function, make a new calendar object, and get the day of the week from it
- ?
- Profit!

I'm having trouble tying it all together though, and the more I think about it the more I think I may be going about the whole thing backwards. For instance, I input the data for each course as a series of strings, but that seems like a roundabout way of doing things - I've been looking for a way of importing the variables from a plain text file, so I just have to swap that out next semester when the courses change, but can't find how to do it. Moreover, I can't seem to figure out how to compare the current date and time to the one listed for each object in Course (that is, I'd want a method that goes through the list of courses and finds the next one that matches both the current date and the current time, but it seems I can only manage to check one specific object at a time. I doubt I'm supposed to copy the code for that one check for all 15-odd objects of the same class).

I'm not looking for a full solution, but some pointers to get me started, or even just a general idea of the best way to go about this would be awfully handy.
+Pie Number of slices to send: Send
I recommend you name your class something other than Interface. "interface" (with a lower case) is a keyword in Java so this is confusing.

I agree that later you will want to read the data from a text file. Hard coding it is fine at first until you get the rest of the logic working. Or if you want to read in a file now, this tutorial page covers I/O.

Comparing dates/times seems like a better place to start with. Do you know how to get a java.util.Date object from a java.util.Calendar? Then you can use the compareTo method to check ordering. You can only check one at a time, but that's ok because you are in a loop. Or at least you want to be. What are you storing the 15 or so classes in? Is it an array or ArrayList or the like? If not, take a look at doing that.
+Pie Number of slices to send: Send
Thanks for the info. I hadn't been using arrays, but I'm reading up on them now
Do Re Mi Fa So La Tiny Ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 966 times.
Similar Threads
Class schedule
Number of days between the 2 given dates.
Dealing with Time Differences
Calendar Class
Gregorian roll() function- April Fools Bug??
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:25:39.