I have the following code:
public void amountOfDepartments() {
Scanner keyboard = new Scanner(System.in);
System.out.print("Amount of departments to create: ");
int amountOfDepartments = keyboard.nextInt();
keyboard.nextLine();
this.departments = new String[amountOfDepartments];
for(int i = 0; i < amountOfDepartments-1; i++) {
System.out.print("Enter department name: ");
departments[i] = keyboard.nextLine();
}
}```
```java
public void setDepartment(Person person) {
int departmentChoice;
Scanner keyboard = new Scanner(System.in);
System.out.print("\nNew Employee: " + person.getFirstName());
Arrays.stream(departments).forEach(System.out::println);
System.out.print("\nEnter department code: ");
departmentChoice = keyboard.nextInt();
switch (departmentChoice) {
case 1:
this.department = departments[0];
person.setEmail(person.getFirstName().toLowerCase() + "." + person.getLastName().toLowerCase() + "@" + this.department + companySuffix);
break;
case 2:
this.department = "development";
person.setEmail(person.getFirstName().toLowerCase() + "." + person.getLastName().toLowerCase() + "@" + this.department + companySuffix);
break;
case 3:
this.department = "accounting";
person.setEmail(person.getFirstName().toLowerCase() + "." + person.getLastName().toLowerCase() + "@" + this.department + companySuffix);
break;
default:
System.out.println("Incorrect input, try again.\n");
}
}```
Pay no attention the the last bit of code, I'm still in the midst of editing.
My question is if it's possible to add the amount of cases predefined in the first method "amountOfDepartments" automatically? Not sure how to explain this better..
For example: if I would call the method amountOfMethods and I select 5 and add them accordingly, the call to method setDepartment should automatically have assigned 5 cases to the switch statement. Is this something that is possible with a switch statement? If not, what's a better way to accomplish this ?
