日期:2014-05-20  浏览次数:20692 次

求大牛帮忙解决一个课本的例题,源代码却有错误
题目:有一个音像店出租电影业务,需要编写一个应用程序进行管理,在进行出租时能够很快找到顾客需要的电影。例如,在实际应用中,可能会通过以下方式查找需要的电影:
  通过标题(title)查找电影
  可将电影分成不同的类型(type),如喜剧片、战斗片等。因此在进行出租时,可在某一特定的类型中查找电影;
  查找包括某一演员(actor/actress)的电影

代码:
电影类Moive:
import java.util.*; 
public class Movie {
private String title,type;
private Vector<String>actors;
public String getTitle(){
return title;
}
public String getType(){
return type;
}
public Vector<String>getActors(){
return actors;
}
public void setTitle(String aTitle){
title=aTitle;
}
public void setType(String aType){
type=aType;
}
public Movie(){
this("???","???");
}
public Movie(String aTitle,String aType){
title=aTitle;
type=aType;
actors=new Vector<String>();
}
@Override
public String toString(){
return ("Movie:"+"\""+title+"\"");
}
public void addActor(String anActor){
actors.add(anActor);
}
}


MovieStore类:
import java.util.*;

public class MovieStore {
private Hashtable movieList, actorList, typeList;

public Hashtable getMovieList() {
return movieList;
}

public Hashtable getActorList() {
return actorList;
}

public Hashtable getTypeList() {
return typeList;
}

public MovieStore() {
movieList = new Hashtable();
actorList = new Hashtable();
typeList = new Hashtable();
}

public String toString() {
return ("MovieStore with" + movieList.size() + "movies.");
}

public void addMovie(Movie aMovie) {
movieList.put(aMovie.getTitle(), aMovie);
if (!typeList.containsKey(aMovie.getType())) {
typeList.put(aMovie.getType(), new Vector<Movie>());
}
((Vector<Movie>) typeList.get(aMovie.getType())).add(aMovie);
for (String anActor : aMovie.getActors()) {
if (!actorList.containsKey(anActor)) {
actorList.put(anActor, new Vector<Movie>());
}
((Vector<Movie>) actorList.get(anActor)).add(aMovie);
}
}

public void removeMovie(Movie aMovie) {
movieList.remove(aMovie.getTitle());
((Hashtable) typeList.get(aMovie.getType())).remove(aMovie);
if (!((Hashtable) typeList.get(aMovie.getType())).isEmpty()) {
typeList.remove(aMovie.getType());
}
for (String anActor : aMovie.getActors()) {
((Vector<Movie>) actorList.get(anActor)).removeElement(aMovie);
if (!((Hashtable) actorList.get(anActor)).isEmpty()) {
actorList.remove(anActor);
}
}
}

public void removeMovie(String aTitle){
if(movieList.get(aTitle)==null){
System.out.println("No movie with that title");
}else{
removeMovie((Movie) movieList.get(aTitle));
}
}

private void removeMovie(Vector<Movie> vector) {
// TODO Auto-generated method stub

}

public void listMovies(){
Enumeration<String>titles=movieList.keys();