Below is my code focus area is case 1 and case 2. please suggest some simple ways to accept full name considering I am a beginner:
package Tester;
import java.util.Scanner;
import com.app.org.Emp;
import com.app.org.Mgr;
import com.app.org.Worker;
public class TestOrganization {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("How many people you want to recruit");
Emp[] org = new Emp[sc.nextInt()]; //holder array ...its not a emp object...its array type of object
boolean exit = false;
int index = 0;
while(!exit) {
System.out.println("Options\n"+"1.Hire Manager\n"+"2.Hire Worker\n"+"3.Display information of all employees\n"
+ "4.Update Performance Bonus or Hourly Rate");
switch (sc.nextInt()) {
case 1:{
if(index<org.length && index>=0) {
System.out.println("Manager Details: id, name, deptId, basic, performBonus");
org[index++] = new Mgr(sc.nextInt(),sc.nextLine(),sc.next(),sc.nextDouble(),sc.nextInt());
}else {
System.out.println("Invalid!!! index");
}
break;
}
case 2:{
if(index<org.length && index>=0) {
System.out.println("Worker Details: id, name, deptId, basic, hw, hr");
org[index++] = new Worker(sc.nextInt(),sc.nextLine(),sc.next(),sc.nextDouble(),sc.nextDouble(),sc.nextDouble());
}else System.out.println("invalid!!! index");
break;
}
case 3:{
System.out.println("Employees Details");
for (Emp e : org) {
if(e!=null)
System.out.println(e);
}
}
input: How many people you want to recruit 5 Options 1.Hire Manager 2.Hire Worker 3.Display information of all employees 4.Update Performance Bonus or Hourly Rate 1 Manager Details: id, name, deptId, basic, performBonus 101 samarth shukla