Thank you for your previous help. However I have another question:
I have three classes MovieRating class, Adult class, and Child class.
The Child class and Adult class both have a method canWatchmovie(MovieRating mrating)
in the Adult class the method always return true while in the Child class we must check the child's age to determine if they can watch movie or not. below is my code:
//MovieRating class
import java.util.*;
public class MovieRating
{
private Map ageMap = new HashMap();
public MovieRating()
{
ageMap.put("PG", 18); //parental Guidance
ageMap.put("G", 4); //general viewing
ageMap.put("A", 27); //Adult material
}
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 getMinAge()
{
// 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();
}
}
// method canWatchMovie in the Child class
public boolean canWatchMovie(MovieRating mrating)
{
//some code for checking the age property and movie rating here
return false
}
Some help please, I'm new to this java language.