0

This is probably an easy one that i know but its not coming to me. Im supposed to be hardcoding the 6 instances of a movie class into the array that i have set up. I am unsure where i would do that in my actuall code.

public class movie {

	private String title;
	private int fightScenes;
	private int romanticScenes;
	private int musicalScenes;
	
	public movie (String name, int fight, int romance, int musical){
		title = name;
		fightScenes = fight;
		romanticScenes = romance;
		musicalScenes = musical;
	}
	
	public String getTitle(){
		return title;
	}
	
	public int getFightScenes(){
		return fightScenes;
		
	}
	
	public int getRomanticScenes(){
		return romanticScenes;
		
	}
	
	public int getMusicalScenes(){
		return musicalScenes;
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		final int numMovies = 6;
		int[] movies = new int[numMovies];
		
		 
		
		
		
		
	}

}
3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Ezzaral
Featured Replies
0

Just assign the elements your new instances

movies[0] = new Movie(...);

or you can initialize them all at once

int[] movies = {
  new Movie(...),
  new Movie(...),
...
};
1

How can you set the elements of an int array to objects?

Comments
Glad someone was paying attention ;)
0

LOL.. shows how much attention I was really paying to the code :)

That's what I get for hammering out a quick answer before I take care of something else at work.

Better check that declaration as Norm said.

0

Another potential problem is that the array is local to the main method. It will go away when main exits unless connected a variable that has larger scope.

0

Yes, I assume the array is to be used for some demo output within main(), though the intended usage is not stated.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.