Home > Back-end >  Why the case: 6 is an error when?
Why the case: 6 is an error when?

Time:05-08

 package test3. 

Public class Employee implements Comparable {
Private int ID; private String name; Private char sex;
private int age; Private int salary;
Public Employee (int ID, String name, char sex, int the age, int salary) {
This. ID=ID;
this.name=name;
This. Sex=sex;
this.age=age;
This. Salary=salary;
}
Public int getID () {
Return the ID;
}
Public String getName () {
return name;
}
Public char getSex () {
return sex;
}
Public int getAge () {
return age;
}
Public int getSalary () {
Return the salary;
}
Public String toString () {
Return ID + ", "+ name + + +", "sex", "+ +", "age, salary;
}
@ Override
Public int compareTo (Employee) o {
If (this. Salary> Grown alary) {
return 1;
} else if (this. Salaryreturn -1;
}
return 0;
}
}


 package test3. 

import java.util.ArrayList;
Import the Java. Util. Collections;
Import the Java. Util. HashMap;
import java.util.List;

Public class ExampleMap {
HashMap Hmap=new HashMap ();
Public void addEmployee (Employee e) {
Hmap. Put (um participant etID (), e);
}
Public String getEmployee would (int id) {
The Employee e=null;
For (Integer key: hmap keySet ()) {
If (key==id) {
E=hmap. Get (key);
}
}
Return e. oString ();
}
Public void deleteEmployee (int id) {
For (Integer key: hmap keySet ()) {
If (key==id) {
Hmap. Remove (key);
}
}
}
Public void updateEmployee (Employee e) {
For (Integer key: hmap keySet ()) {
If (key==um participant etID ()) {
Hmap. Put (key, e);
}
}
}
Public void showAllEmployee () {
For (Integer key: hmap keySet ()) {
System. The out. Println (hmap. Get (key). The toString ());
}
}
Public void sortBySalary () {
List the List=new ArrayList (hmap entrySet ());
The Collections. The sort (list);
For (Integer key: hmap keySet ()) {
System. The out. Println (hmap. Get (key). The toString ());
}
}
}



 package test3. 

import java.util.Scanner;
Public class test {
Public static void main (String [] args) {
ExampleMap em=new ExampleMap ();
While (true) {
System. The out. Println (" * * * * * * * * * * * * employee management System ");
System. The out. Println (" 1. Add the employee ");
System. The out. Println (" 2. Show all employee information ");
System. The out. Println (" 3. According to the ID number for employees ");
System. The out. Println (" 4. Modify the employee information ");
System. The out. Println (" 5. According to the id number to delete employees ");
System. The out. Println (" 6. Sort by salary ");
System. The out. Println (" 7. Quit ");
System.out.println("********************");
System. The out. Println (" please enter a number: ");
Scanner sc=new Scanner(System.in);
Int bh=sc. NextInt ();
The switch (bh) {
Case 1:
System. The out. Println (" you chose to add employees ");
System. The out. Println (" please enter the id number: ");
Int ID=sc. NextInt ();
System. The out. Println (" please input your name: ");
String name=sc. Next ();
System. The out. Println (" please enter the gender: ");
Char sex=sc. Next (). CharAt (0);
System. The out. Println (" please enter the age: ");
Int the age=sc. NextInt ();
System. The out. Println (" please enter the salary: ");
Int salary=sc. NextInt ();
The Employee e=new Employee (ID, name, sex, age, salary).
Em. AddEmployee (e);
break;
Case 2:
System. The out. Println (" you select the show all employee information ");
Em. ShowAllEmployee ();
break;
Case 3:
System. The out. Println (" you choose according to the ID to find employees ");
System. The out. Println (" please enter to find your id number: ");
ID=sc. NextInt ();
Em. GetEmployee would (ID);
break;
Case 4:
System. The out. Println (" please enter the employee information: ");
System. The out. Println (" please enter the id number: ");
ID=sc. NextInt ();
System. The out. Println (" please input your name: ");
Name=sc. NextLine ();
System. The out. Println (" please enter the gender: ");
Sex=sc. Next (). CharAt (0);
System. The out. Println (" please enter the age: ");
Age=sc. NextInt ();
System. The out. Println (" please enter the salary: ");
Salary=sc. NextInt ();
E=new Employee (ID, name, sex, age, salary).
Em. UpdateEmployee (e);
break;
Case 5:
System. The out. Println (" please enter the id number you are trying to remove: ");
ID=sc. NextInt ();
Em. DeleteEmployee (ID);
break;
Case 6:
Em. SortBySalary ();
Case 7:
return;
}
}
}
}

CodePudding user response:

What is wrong, should not be an error
  • Related