How do a put the contents of case 1 into a method and call it?
See code snippet below:
Teacher jane = new Teacher("jane");
Teacher alex = new Teacher("alex");
Set<Teacher> teachers = new HashSet<Teacher>();
teachers.add(jane);
teachers.add(alex);
int selection = scan.nextInt();
switch (selection) {
case 1:
for (Teacher teacher : teachers) {
System.out.printf("%s ", teacher.getName());
}
break;
}
See Question&Answers more detail:os