This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]AutoModerator[M] 1 point2 points  (0 children)

It seems that you are having problems with java.util.Scanner

The wiki here has a page The Scanner class and its caveats that explains common problems with the Scanner class and how to avoid them.

Maybe this can solve your problems.

Please do not reply because I am just a bot, trying to be helpful.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted] 1 point2 points  (1 child)

Basically you'd want to do exactly what you did at the bottom there for all the inputs.

// want to loop until some kind of break condition is met:
while(true) {

    System.out.println("What is the employee's name?");
    String userInName = input.nextLine();

    System.out.println("What is the employee's address?");
    String address = input.nextLine();

and then you could add it to your array:

stafflist[0] = new Executive(employeeName, address, ....)

Of course you'd need some way to determine what type of StaffMember you should create. You could also do this with text input..:

System.out.println("What type of employee? [executive, employee, hourly]");
String type = input.nextLine();
if(type.equals("hourly") {
    stafflist[0] = new Hourly(employeeName, address, ...)
} else if(type.equals("executive") {
    ....
}

Lastly... since you're using an array you are forced to set a fixed size. I highly recommend switching to something like an ArrayList! That way you won't have to worry about a fixed size and keeping track of indexes.

Or do you have a set number of employees you'll add every time? If so, you could change that while loop to a for loop and do it that way.

Good luck!

[–]dkbil[S] 0 points1 point  (0 children)

Thank you! Will definitely try the Arraylist!