日期:2014-05-20 浏览次数:20727 次
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);
}
}
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();