So, first off, in my class Film I need to declare various fields including a string array of actors a fixed length (5). My default constructor needs to set these values for now but later I think I'll need the 5 string values to null so I can add actors up to the limit. I then want to be able to create instances of the class using values passed to a constructor and finally add actors to the string array of a given film - where there's a free spot (and throw an exception when there's not one).
What I have so far:
public class Film {
private String title;
private String[] actors = new String[5]; // can I set the limit here and use this string below?
private double budget;
// default constructor:
public Film() {
title = "Default title";
// This creates a new string though and doesn't limit to 5 :o(
authors = new String[] {"a","b","c","d","e"};
budget = 1.1
}
// constructor which takes values passed in:
public Film(String title, double budget, String[] actors) {
this.title = title;
this.budget = budget;
this.actors = actors;
}
}
In my main programme, I have the following which shows an error on the comma after the budget value and I can't work out why:
public class Main {
Film homeAlone = new Film("Home Alone", 10.9, ("McCauley", "John", "Paul", "George", "Ringo"));
}
And as for the 'adding an actor' method - I don't know where to start. Any help would be greatly appreciated!
Cheers,
Mike
new String[]{"McCauley", "John", "Paul", "George", "Ringo"}budget = 1.1missing semicolon after definition