I'm trying to take multiple user inputs (which will be strings in this case / names) and store it into an array that is in another class
Based on what I've researched many advise to use a list instead of an array, but in this case an array was specified to be used.
I was able to breakdown the problem by using code that was meant to receive an integer as input and I had made changes to receive a string instead, however, in the case where I entered for example, 3 names were to be entered and the code prompted me to enter the names, only 2 were allowed to be entered
Here's the class where the array was initialized
public class Movie {
private String id;
private String name;
private String description;
private String[] genre;
private String[] actors;
private String[] language;
private String countryOfOrigin;
private Map<String, Integer> ratings;
//Constructor
public Movie(String id, String name, String description, String[] genre, String[] actors, String[] language, String countryOfOrigin, Map<String, Integer> ratings){
this.id = id;
this.name = name;
this.description = description;
this.genre = genre;
this.actors = actors;
this.language = language;
this.countryOfOrigin = countryOfOrigin;
this.ratings = ratings;
}
//setters
public void setid(String id){
this.id = id;
}
public void setname(String name){
this.name = name;
}
public void setDescription(String description){
this.description = description;
}
public void setGenre(String[] genre){
this.genre = genre;
}
public void setActors(String[] actors){
this.actors = actors;
}
//getters
public String getId(){
return id;
}
public String getName(){
return name;
}
public String getDescription(){
return description;
}
public String[] getGenre(){
return genre;
}
public String[] getActors(){
return actors;
}
Here's the main file with the code for the person to enter the names
public class Main{
public static void main(String[] args) {
//Scanner initialization
Scanner input = new Scanner(System.in);
System.out.println("How many actors star in this movie?: ");
int num = input.nextInt();
String array[] = new String[num];
System.out.println("Enter the " + num + " actors starred now");
for (int i = 0; i < array.length; i++){
array[i] = input.nextLine();
}
}
My problem is I'm not sure if I need to first store the values into the local array "array" and THEN assign said array to the class Movie actors array, or if I need to directly assign the values into the class Movie actors array. If so, I'm unsure how to do that.
My other problem is the one mentioned above where if I entered 3 names to be stored, it only allows me to enter 2