你都没有在Start类里的search里面将数组元素赋值,怎么可能输出遍历?你应该在search里面加上一句话
div.initial;将数组元素赋值。否则里面的元素都是null,都break了 所以没结果
Start类:其中的search()方法是实现遍历数组。
public class Start {
public void search(){
DVDSet dvd=new DVDSet();
div.initial();
for(int i=0;i
break;
}else if(dvd.state[i]==0){ S
ystem.out.println((i+1)+"\t已借出\t"+"<<"+dvd.name[i]+">>\t"+dvd.date[i]);
}else if(dvd.state[i]==1){
System.out.println((i+1)+"\t可借\t"+"<<"+dvd.name[i]+">>");
}
}
}
}
main方法:
public static void main(String[] args) {
Strat start = new Start();
start.search();
}
你写的有点乱,我没测试,错的地方就是没初始化,你看看
类定义的时候不要new,用到的时候再new,设计一个类的时候最好设成private的变量,然后用eclipse自带的重构器添加get()和set()方法,用的比较多的方法可以都抽象到一个接口里去,然后在接口实现类里override....还有,你这个程序里面好像没有main函数、
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* 测试类
* @author Administrator
*
*/
public class Test02 {
public static void main(String[] args) {
MovieStore movieStore = new MovieStore();
DVDManage.initDVD(movieStore);
DVDManage.printAll(movieStore);
}
}
/**
* 电影类
* @author Administrator
*
*/
class Movie {
private String name;//电影名字
private int state;//是否可借
private String date;//电影日期
public Movie(String name, int state, String date) {
super();
this.name = name;
this.state = state;
this.date = date;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
/**
* 影片商店
* @author Administrator
*
*/
class MovieStore {
private List
public MovieStore() {
super();
movies = new ArrayList
}
public MovieStore(List
super();
this.movies = movies;
}
public List
return movies;
}
public void setMovies(List
this.movies = movies;
}
}
/**
* 影片管理系统
* @author Administrator
*
*/
class DVDManage {
/**
* 初始化影片
* @param movieStore
*/
public static void initDVD(MovieStore movieStore)
{
List
movies.add(new Movie("罗马假日", 0,"2010-7-1" ));
movies.add(new Movie("风声鹤唳", 1,"" ));
movies.add(new Movie("浪漫满屋", 1,"" ));
movieStore.setMovies(movies);
}
/**
* 打印出所有影片信息
* @param movieStore
*/
public static void printAll(MovieStore movieStore) {
List
for (Iterator iterator = movies.iterator(); iterator.hasNext();) {
Movie movie = (Movie) iterator.next();
if (movie.getState() == 0) {
System.out.println(("\t已借出\t" + "<<" + movie.getName()
+ ">>\t" + movie.getDate()));
} else if (movie.getState() == 1) {
System.out.println("\t可借\t" + "<<" + movie.getName()
+ ">>");
}
}
}
}