匿名用户
1级
2013-09-14 回答
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 movies;//影片
public MovieStore() {
super();
movies = new ArrayList();
}
public MovieStore(List movies) {
super();
this.movies = movies;
}
public List getMovies() {
return movies;
}
public void setMovies(List movies) {
this.movies = movies;
}
}
/**
* 影片管理系统
* @author Administrator
*
*/
class DVDManage {
/**
* 初始化影片
* @param movieStore
*/
public static void initDVD(MovieStore movieStore)
{
List movies = new ArrayList();
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 movies = movieStore.getMovies();
for (Iterator iterator = movies.iterator(); iterator.hasNext();) {
Movie movie = (Movie) iterator.next();
if (movie.getState() == 0) {
System.out.println(("\t已借出\t" + "<
+ ">>\t" + movie.getDate()));
} else if (movie.getState() == 1) {
System.out.println("\t可借\t" + "<
+ ">>");
}
}
}
}