【发布时间】:2014-02-04 11:39:15
【问题描述】:
我对 java 非常陌生。我试图创建一个返回一些电影信息的类(所有这些信息都存储在数组中)。我卡住了,不知道该怎么办。这是我的代码
电影类:
public class Movie {
String[] Director;
String[] Name;
String[] realeaseDate;
String[] lastShow;
public Movie()
{
String[] Director={"George Romero","Woody Allen","Steven Speilberg","James Cameron"};
String[] Name={"Diary of the Dead","Midnight in Paris","War of the Worlds","Terminator 2 - Judgment Day"};
String[] realeaseDate={"Dec 31 1999","Dec 28 1999","Dec 15 1999","Dec 10 1999"};
String[] lastShow={"Jan 13 2000","Jan 29 2000","Jan 23 2000","Jan 15 2000"};
}
public String getDirector()
{
return Director;
}
public String getName()
{
return Name;
}
public String getRealease()
{
return realeaseDate;
}
public String getLast()
{
return lastShow;
}
}
现在这是我的主要内容:
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
String newLine = System.getProperty("line.separator");
Movie movies = new Movie();
System.out.println("Avaliable movies"+newLine);
System.out.println("Director: "+ movies.getDirector()+newLine+"Name :"+ movies.getName()+ newLine + "Realease Date: "+ movies.getRealease()+newLine+"Last Show :"+ movies.getLast()+newLine);
}
}
我希望结果是这样的:
所有可用的电影
乔治... 日记... 十二月.. 一月...
史蒂文.. 斯达夫斯达... 十二月... 一月..
。 . .
【问题讨论】:
-
你在构造函数中隐藏了你的字段。还要检查您的退货类型。另外,检查如何打印出数组的内容。另外,请查看封装。
-
也就是说,把
String[] Director={"George Romero","Woody ...改成Director={"George Romero","Woody ... -
另外值得注意的是,您已经定义了
String[] Director,但您的方法getDirector()返回了String。 -
我认为你真正想要的是一系列电影...而不是包含一系列不同电影的电影