English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

key and age as value, then a method to check if a person can watch a movie according to the rating in age in the Map?
That method e.g. canWatchMovie( ) takes rating as a parameter?

Thanks for your HELP...

2007-02-19 14:31:21 · 1 answers · asked by Cyr B 1 in Computers & Internet Programming & Design

1 answers

you mean something like this?

import java.util.*;


public class RatingChecker {

public enum RATING {GENERAL, PG13, R17};

private Map fRatingsMap = new HashMap();

public RatingChecker(){
fRatingsMap.put(RATING.GENERAL, new Integer(0));
fRatingsMap.put(RATING.PG13, new Integer(13));
fRatingsMap.put(RATING.R17, new Integer(17));
}

public boolean canWatchMovie(int age, RATING rating){
boolean canWatch = true;
Integer ratingAge = fRatingsMap.get(rating);
if (age < ratingAge.intValue()){
canWatch = false;
}
return canWatch;
}

}

2007-02-22 18:31:09 · answer #1 · answered by vincentgl 5 · 0 0

fedest.com, questions and answers