Hi madman228! Welcome to bytes.com!
It's great to have you here!
When you post, please always keep to the
Posting Guidelines and when you post code, please post it in
[code] ... [/code] tags.
About your question:
Have you ever used more than one class in Java? For example, you would have your main class:
- public class Main {
-
public static void main(String[] args) {
-
// Your code here
-
}
-
}
and then a second class that I'll just call
Mumble for the moment:
- public class Mumble {
-
// Global variables here
-
public Mumble(...) {
-
// This is the constructor. It is called every time you create a new Object from the class "Mumble".
-
}
-
// More of your code here
-
}
Now, you should create a new class called
Day, right? And what should that class do? Oh yes:
The class Day should store the day, such as Sun for
Sunday.
So, there should be a variable to save the day. (No, not like a superhero! ^^) What datatype would "Sun" be? I'd say: String. So, it would look something like this:
- public class Day {
-
private String day;
-
// More variables here
-
public Day(...)
-
{
-
// variable initialisations here
-
}
-
// More stuff here
-
}
Now, to set a day, you'll need a so called "setter". That's a method normally called something like
setValue(datatype variable) (e.g.
setDay(String myDay)) which will change the global variable
value (here:
day). Printing and returning (or "getting" -> a "getter" function) the current day aren't difficult either.
Returning the previous / next day is a bit more complicated. Basically, I see two methods. Either you check which the next day would be by means of a few if clauses:
- if(day.equals("Sun") return "Mon";
-
else if(day.equals("Mon") return "Tue";
-
else ...
and then call that several times for question f), or you have an array of all days and save the day's number in your class as well:
- public class Day {
-
private String day;
-
private int dayOfTheWeek;
-
public String[] days = {"Sun", "Mon", ...};
-
// ...
-
}
and then go through the array with that integer. You can also use that for part f).
Now, you'll have to do the writing of those classes yourself, but what I've given you should be more than enough to get you started.
Otherwise, I'll just wish you the best and hope you enjoy being part of
bytes.com!
Greetings,
Nepomuk