So this is my first time asking on stackoverflow but i need help with this problem. I have to use enums that includes constructors, methods, and static methods.
So everything in the main was already written and rest I wrote it but I am lost now.
The question is to solve this half written code and have the output. The output is suppose to look like this:
Today's a weekday.
The abbreviation for MONDAY is M
The abbreviation for MONDAY is T
The abbreviation for MONDAY is W
The abbreviation for MONDAY is R
The abbreviation for MONDAY is F
The abbreviation for MONDAY is S
The abbreviation for MONDAY is Y
SUNDAY
MONDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
true
true
true
true
My code so far:
import java.util.List;
public class DayOfWeekDriver
{
public enum DayOfWeek{
MONDAY("M"), TUESDAY("T"), WEDNESDAY("W"), THURSDAY("R"), FRIDAY("F"), SATURDAY("S"), SUNDAY("S");
static{
MONDAY.next = TUESDAY;
TUESDAY.next = WEDNESDAY;
WEDNESDAY.next = THURSDAY;
THURSDAY.next = FRIDAY;
FRIDAY.next = SATURDAY;
SATURDAY.next = SUNDAY;
SUNDAY.next = MONDAY;
}
private DayOfWeek next;
public DayOfWeek nextDay(){
return next;
}
private String abbreviation;
private String day;
DayOfWeek(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getAbbreviation() {
return abbreviation;
}
public String getDays(){
return day;
}
}
public char getLetter(){
}
public static void main(String[] args)
{
DayOfWeek today = DayOfWeek.FRIDAY;
if (today == DayOfWeek.SATURDAY || today == DayOfWeek.SUNDAY)
{
System.out.println("Today's a weekend.");
}
else
{
System.out.println("Today's a weekday.");
}
for (DayOfWeek day : DayOfWeek.values())
{
System.out.printf("The abbreviation for %s is %c \n",
day, day.getLetter());
}
for (Character c : "YMWFTRS".toCharArray())
{
System.out.println(DayOfWeek.toDayOfWeek(c));
}
List<DayOfWeek> list = DayOfWeek.getDays();
System.out.println(list.get(0) == DayOfWeek.values()[0]);
System.out.println(DayOfWeek.MONDAY.next() == DayOfWeek.TUESDAY);
System.out.println(today.next() == DayOfWeek.SATURDAY);
System.out.println(DayOfWeek.SUNDAY.next() == DayOfWeek.MONDAY);
}
}
And also if I can get suggestions where to learn more of java that would be great! Thank you.