130 lines
3.2 KiB
Java
130 lines
3.2 KiB
Java
package VL04.Aufgabe06;
|
|
|
|
/**
|
|
* Vorlesung 4 / Aufgabe 6
|
|
*
|
|
* @author Sebastian Brosch
|
|
*/
|
|
public class Aufgabe06 {
|
|
public static void main(String[] args) {
|
|
enum Months {
|
|
January,
|
|
February,
|
|
March,
|
|
April,
|
|
May,
|
|
June,
|
|
July,
|
|
August,
|
|
September,
|
|
October,
|
|
November,
|
|
December
|
|
};
|
|
String quarter = "";
|
|
Months month = Months.October;
|
|
|
|
System.out.printf("Monat: %s\n\n", month);
|
|
|
|
switch (month) {
|
|
case January:
|
|
quarter = "1. Quartal";
|
|
break;
|
|
case February:
|
|
quarter = "1. Quartal";
|
|
break;
|
|
case March:
|
|
quarter = "1. Quartal";
|
|
break;
|
|
case April:
|
|
quarter = "2. Quartal";
|
|
break;
|
|
case May:
|
|
quarter = "2. Quartal";
|
|
break;
|
|
case June:
|
|
quarter = "2. Quartal";
|
|
break;
|
|
case July:
|
|
quarter = "3. Quartal";
|
|
break;
|
|
case August:
|
|
quarter = "3. Quartal";
|
|
break;
|
|
case September:
|
|
quarter = "3. Quartal";
|
|
break;
|
|
case October:
|
|
quarter = "4. Quartal";
|
|
break;
|
|
case November:
|
|
quarter = "4. Quartal";
|
|
break;
|
|
case December:
|
|
quarter = "4. Quartal";
|
|
break;
|
|
default:
|
|
quarter = "";
|
|
}
|
|
|
|
System.out.printf("a.) ursprüngliche switch-Anweisung: %s\n", quarter);
|
|
|
|
switch (month) {
|
|
case January, February, March:
|
|
quarter = "1. Quartal";
|
|
break;
|
|
case April, May, June:
|
|
quarter = "2. Quartal";
|
|
break;
|
|
case July, August, September:
|
|
quarter = "3. Quartal";
|
|
break;
|
|
case October, November, December:
|
|
quarter = "4. Quartal";
|
|
break;
|
|
default:
|
|
quarter = "";
|
|
}
|
|
|
|
System.out.printf("b.) Zusammenfassung mehrerer Ausdrücke: %s\n", quarter);
|
|
|
|
switch (month) {
|
|
case January -> quarter = "1. Quartal";
|
|
case February -> quarter = "1. Quartal";
|
|
case March -> quarter = "1. Quartal";
|
|
case April -> quarter = "2. Quartal";
|
|
case May -> quarter = "2. Quartal";
|
|
case June -> quarter = "2. Quartal";
|
|
case July -> quarter = "3. Quartal";
|
|
case August -> quarter = "3. Quartal";
|
|
case September -> quarter = "3. Quartal";
|
|
case October -> quarter = "4. Quartal";
|
|
case November -> quarter = "4. Quartal";
|
|
case December -> quarter = "4. Quartal";
|
|
default -> quarter = "";
|
|
}
|
|
|
|
System.out.printf("c.) Pfeilnotation: %s\n", quarter);
|
|
|
|
switch (month) {
|
|
case January, February, March -> quarter = "1. Quartal";
|
|
case April, May, June -> quarter = "2. Quartal";
|
|
case July, August, September -> quarter = "3. Quartal";
|
|
case October, November, December -> quarter = "4. Quartal";
|
|
default -> quarter = "";
|
|
}
|
|
|
|
System.out.printf("d.) Zusammenfassung mehrerer Ausdrücke in Pfeilnotation: %s\n", quarter);
|
|
|
|
quarter = switch (month) {
|
|
case January, February, March -> "1. Quartal";
|
|
case April, May, June -> "2. Quartal";
|
|
case July, August, September -> "3. Quartal";
|
|
case October, November, December -> "4. Quartal";
|
|
default -> "";
|
|
};
|
|
|
|
System.out.printf("e.) switch-Ausdruck mit Pfeilnotation: %s\n", quarter);
|
|
}
|
|
}
|