This commit is contained in:
Matti 2024-04-11 14:19:46 +02:00
parent 8026de2317
commit da9336ad09
2 changed files with 74 additions and 3 deletions

View File

@ -7,7 +7,7 @@ Dateien wie Bilder die zur Lösung einer Aufgabe gehören sind in <br><ins>Medie
## Bisher vorhanden:
- Vorlesung 3 komplett
- Vorlesung 4 erste 5/6
- Vorlesung 4 komplett
## Angefangene unfertige Lösungen:
- VL 4 aufg 6
- keine

View File

@ -2,6 +2,77 @@ package part4;
public class aufg6 {
public static void main(String[] args){
enum months{Jan, Feb, Mar, Apr, May, Jun, Jul, Aug}
enum months{Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}
// a) "Klassische" switch-commands
for(months month : months.values()){
short quarter;
switch (month){
case Jan:
case Feb:
case Mar: quarter = 1; break;
case Apr:
case May:
case Jun: quarter = 2; break;
case Jul:
case Aug:
case Sep: quarter = 3; break;
case Oct:
case Nov:
case Dec: quarter = 4; break;
default: quarter = 0;
}
System.out.println(month + ": " + quarter);
// b) Zusammenfassen mehrerer Ausdrücke
switch (month){
case Jan, Feb, Mar: quarter = 1; break;
case Apr, May, Jun: quarter = 2; break;
case Jul, Aug, Sep: quarter = 3; break;
case Oct, Nov, Dec: quarter = 4; break;
default: quarter = 0;
}
System.out.println(month + ": " + quarter);
// c) Pfeilnotation
quarter = switch (month) {
case Jan -> 1;
case Feb -> 1;
case Mar -> 1;
case Apr -> 2;
case May -> 2;
case Jun -> 2;
case Jul -> 3;
case Aug -> 3;
case Sep -> 3;
case Oct -> 4;
case Nov -> 4;
case Dec -> 4;
default -> 0;
};
System.out.println(month + ": " + quarter);
// d) Zusammenfassung in Pfeilnotation
quarter = switch (month){
case Jan, Feb, Mar -> 1;
case Apr, May, Jun -> 2;
case Jul, Aug, Sep -> 3;
case Oct, Nov, Dec -> 4;
default -> 0;
};
System.out.println(month + ": " + quarter);
}
}
}