-->
当前位置:首页 > 题库

PROGRAMMING:JMU enumeration weekday (complete code)

Luz5年前 (2021-05-10)题库478
This topic requires the preparation of an enumeration class * * weekday * *, including 7 constants from Monday to Sunday. The names of the seven constants are capitalized with the corresponding English words, and the order of the constants can be obtained by observing the examples.
This topic also requires writing the string input from the console into weekday type variable, and then use switch to execute the corresponding code according to the variable.
Finally, this problem requires the output of statistical results, and get the constant array of weekday, and then sort it and output. The following is the code framework, please complete the code in the corresponding position:
```
import java.util.Arrays;
import java.util.Scanner;
//Here is the definition of the generic class weekday
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//Here are some initialization codes for statistics
try {
while(sc.hasNext()) {
String weekDayStr = sc.next();
//Here we write the code to convert weekday STR into weekday type variable x
//Here we write the code that uses switch to output the corresponding information and statistics according to X type
}
}
} catch (Exception e) {
System. Out. Println ("input error");
}
//Output statistics here
//Here we write the code to get the weekday constant array and convert it into string array a
//Here we write the code to sort and print the a array
sc.close();
}
}
```
###Input format:
Enter a string representing the character constant X
###Output format:
When the input is working day, output: X is working day, serial number is y; When the input is the rest day, the output: X is the working day, the serial number is y
Statistical results
A string representation of a constant array sorted in order
###Input example:
```in
MONDAY
TUESDAY
SUNDAY
FRIDAY
SATURDAY
THURSDAY
wednesday
```
###Output example:
```out
Monday is a working day, serial number is 1
Tuesday is a weekday with serial number 3
Sunday is a rest day with the serial number of 0
Friday is a working day, serial number is 4
Saturday is a rest day, serial number is 6
Thursday is a weekday, serial number 5
Input error
4 working days in total
2 days off
[FRIDAY, MONDAY, SATURDAY, SUNDAY, THURSDAY, TUESDAY, WEDNESDAY]
```







answer:If there is no answer, please comment