Hi, I'm trying to use a map in my application. the class MovieRating which contains the map is as below:
import java.util.*;
public class MovieRating
{
private Map ageMap = new HashMap();
private String movieRating;
public MovieRating()
{
ageMap.put("PG", 18); //parental Guidance
ageMap.put("G", 4); //general viewing
ageMap.put("A", 27); //Adult material
}
public String getRating()
{
return movieRating;
}
public boolean getStatus(String rating, int age)
{
int mAge,gAge,aAge;
mAge = Integer.getInteger((String) ageMap.get("PG"));
gAge = Integer.getInteger((String) ageMap.get("G"));
aAge = Integer.getInteger((String) ageMap.get("G"));
if (age < mAge )
{
return false;
}
else if (age >= mAge)
{
return true;
}
return false;
}
public int getPGuidance()
{
// Retrieve the minimum age allowed to watch movie rated PG.
return (Integer)ageMap.get("PG");
}
public int getGeneral()
{
// Retrieve the age allowed to watch movie rated G.
return (Integer)ageMap.get("G");
}
public int getAdult()
{
// Retrieve the age allowed to watch movie rated Adult.
return (Integer)ageMap.get("A");
}
public Object getValue()
{
// return ageMap.values();
return ageMap.toString();
}
}
I now want to use the three ratings and age in the map in a method in a different class to determine whether the various individuals of various age groups can watch a certain movie or not. the method is called getMovieGoers and is as below: NOTE: This method is in a different class called Family within the same package. It returns a collection of moviegoers from the arraylist.
public void getMovieGoers(MovieRating mRt)
{
Adult a = new Adult("Robert",33);
Adult b = new Adult("Sue",27);
Adult c = new Adult("Tracy",20);
ArrayList ads = new ArrayList();
ads.add(a); ads.add(b);ads.add(c);
Collection myAdults =ads;
if(mRt.getRating()!=null)
{
try
{
if(ourChild.getAge()< mRt.getAdult() || ourChild.getAge()<mRt.getPGuidance() )
{
System.out.println(ourChild.getName()+" cannot watch movie rated A, but can watch"+
" movie rated PG under parental advice. The following adults can watch: "+
""+myAdults+"");
}
else if(ourChild.getAge()>= mRt.getPGuidance() && ourChild.getAge()<mRt.getAdult())
{
System.out.println(ourChild.getName()+" can freely watch the movie rated PG."+
" but cannot watch movies rated A. The following can watch both: "+myAdults+"");
}
else
{
System.out.println("The following can watch movies rated G: "+ourChild.getName()+
"," +myAdults+"");
}
}
catch(Exception e)
{
System.out.println("Movie rating not found.");
}
}
}
When I run my application and call the method in the main, it does not list the moviegoers and I suspect the problem is picking the rating and age pair from the map in the MovieRating class. Some help please.....