Enums injava
public class EnumTest {
Day day;
public EnumTest(Day day) {
this.day = day;
}
public void tellItLikeItIs() {
switch (day) {
case MONDAY:
System.out.println("Mondays are bad.");
break;
case FRIDAY:
System.out.println("Fridays are better.");
break;
case SATURDAY: case SUNDAY:
System.out.println("Weekends are best.");
break;
default:
System.out.println("Midweek days are so-so.");
break;
}
}
public static void main(String[] args) {
EnumTest firstDay = new EnumTest(Day.MONDAY);
firstDay.tellItLikeItIs();
EnumTest thirdDay = new EnumTest(Day.WEDNESDAY);
thirdDay.tellItLikeItIs();
EnumTest fifthDay = new EnumTest(Day.FRIDAY);
fifthDay.tellItLikeItIs();
EnumTest sixthDay = new EnumTest(Day.SATURDAY);
sixthDay.tellItLikeItIs();
EnumTest seventhDay = new EnumTest(Day.SUNDAY);
seventhDay.tellItLikeItIs();
}
}
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
Also in Java:
- HOW TO SUPRESS sonar warning in java code
- java jaxb unmarshall xml to map
- java - get open ports
- padding a string with 0 in java
- how to remove all items from alist in java
- java type casting
- java fileinputstream
- how to reverse a list in java
- how to exit a for loop in java
- Matlab java.lang.IllegalArgumentException: Invalid range
- java string to boolean
- how to break two loop in java
- loop java
- java double 2 decimal
- how to declare array java
- get current unix timestamp java
- java constructor
- how to check if a string contains only alphabets and space in java
- Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification
- eliminar el primer caracter de un string java
- java windowbuilder full screen
- how to copy all files and subdirectories in directory in java
- how to install java 8 on terminal os
- select photo from camera android