Hi, I'm new in java. Can someone help me with this problem. I've attempted it and the code is as shown after the questions:

Question:

1. Create a new Movie class which has two properties, title and rating.
2. Create a new Cinema class, add method addMovieGoers which takes a collection of Humans and another-(Done)- method showMovie which does not take any arguments.(---DONE---) Your Cinema class should also have a setMovie method which takes a Movie as an argument.
3. When the addMovieGoers is called on a cinema instance the movie goers should be added to a private collection.
4. Add a new method to your family class that returns all family members.
5. In the main method of the Cinema class call a new static method that creates a family and a cinema then use the addMovieGoers method of the cinema to add the family members. Next create a new movie and use it to set the movie property of the cinema. Finally call cinema.showMovie.

Now, if you were careful your code may have executed without exception but there are quite a few loopholes in your code, to close them do the following.

1. In the showMovie method test whether or not the movie property has been set, if not throw an exception,<Pending> also add code to empty the Cinema whether the movie was shown or not.
2. In the setMovie method check that the movie title and rating have been set, if not throw an exception.
3. In the addMovieGoers method, check that the movie property has been set and if not throw an exception.
4. Also in the addMovieGoers method check that every member of the collection is a human and that they are old enough to watch the movie, if not throw an exception. Note that although the family has getMovieGoers method, you can't be sure it was used to build the collection.
5. Static main )Finally add another static method to the cinema class that demonstrates the usage of the cinema class. Include multiple scenarios to show how the exceptions work.
6. Remember about creating your own exceptions and passing them to the controlling module (here method with scenarios). After an exception occurs your code should stop execution of current scenario and go to another one.

MY CODE:
My code is as below and it's not working properly, so I need your help please.

//Movie class
public class Movie 
{
    String movieRating;
    public Movie(String rated, String mtitle) 
    {
        this.mrating=rated;
        this.title=mtitle;
    }
   
    public void setRating(String Rating) 
    {
        movieRating = Rating;
    }

    // Get the rating
    public String getRating() 
    {
        return movieRating;
    }

    public void setTitle(String title) 
    {
        this.title = title; 
    }
  
   
    public String getTitle() 
    { 
        return title; 
    }
    @Override
    public String toString() 
    {
        return "Movie"
        +" title="+getTitle() + 
        " rating="+getRating();
    }
    public static void main(String args [])
    {
        Movie mv= new Movie("","");
        mv.toString();
    }
                
    private String title;
    private String mrating;
    
}

//Cinema class
import java.util.*;
import java.io.*;
public class Cinema 
{
    public static final int maxRate = 3;
    public static final int minRate = 1;
    float cost;
    String Title,humans;
    ArrayList mGoers;

        public Cinema (String mtitle, float pounds) 
        {
                this.Title=mtitle;
                this.cost = pounds;
                mGoers = new ArrayList();

        }

        public float getcost (int people) 
        {
            return cost * people;
        }

        //methods for adding movie goers which takes a collection of Humans
        public void addMovieGoers()
        {
            int minAge=18;
            Family fam = new Family("",0);
            
            fam.listAll();
//            for (int cnt=0; cnt<mGoers.size(); cnt++)
//            {
//                Adult stud = (Adult) mGoers.get(cnt);
//                System.out.println(stud);
//            }
      
        }
        
        /**
        * Method check that the movie title and rating have been set,
        * if not throw an exception.
        */
        public void setMovie(Movie movieNew) throws IOException
        {
            try
            {
       
                if (!isObjectEmpty(movieNew.getTitle()) && !isObjectEmpty(movieNew.getRating()))
                {
                     System.out.println("The movie is called " +movieNew.getTitle()+ 
                            " and is rated " +movieNew.getRating()+ ".");
                }
                else
                {
                     System.out.println("Movie title and rating not set");
                }
            }
            catch(Exception e)
            {
                System.out.println("Title and Rating not Set");
            }
        }

        public void showMovie() 
        {
            try
            {
                Movie mv = new Movie("","");
                String mRating = mv.getRating();
                String mTitle = mv.getTitle();
                if((mRating!=null)&& (mTitle!=null))
                {
                    System.out.println("Title is "+mTitle+" and is Rated "
                            +mRating+"");
                }
                else
                {
                    System.out.println("Either Title or Rating is missing");
                }
            }
            catch(Exception e)
            {
                System.out.println("The Movie properties not set");
            }
            finally
            {
               System.out.println("The movie is over.");
            }

        }
        
        /**
        * Checks is indiacated Object is empty.
        * restrictions for raiting type (rating must be >=1 and <=3)
        */
        
        public boolean isObjectEmpty(Object obj)
        {
            int rating=1;
            boolean result = obj==null;
            if((rating<1)||(rating>3))
            {
                System.out.println("The rating is out of bounds");
            }
            else
            {
                System.out.println("Movie properly rated");
            }
            return result;
        }
        
        public static void main(String args[])
        {
            String temp;
            int rate;
            System.out.println("What's the Movie rating:");
            BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
            
            try
            {
                temp= stdin.readLine(); 
                rate=Integer.parseInt(temp);
                if((rate<1)||(rate>3))
                {
                    System.out.println("Rate out of bounds!");
                }
                else
                {
                    System.out.println("The following can go for a movie:");
                    Cinema cin = new Cinema("PG",maxRate);
                    cin.addMovieGoers();                 
                }
            }
            catch(Exception e)
            {
                 System.out.println("Movie not properly rated.");
            }
            finally
            {
                System.out.println("Cinema closed now.");
            }
           
        }
  
        

}

//Family class

import java.util.*;
import java.io.*;
//import java.util.Iterator;
public class Family extends Human
{

//    String me,myPatner,famMembers;
    int myAge;
//    private Child ourChild;
    String rating;
    ArrayList familia;
    public Family(String name, int Age)
    {
        this.name=name;
        this.age=Age;
//        ourChild=new Child("",0); 
        familia = new ArrayList();
        
    }
//     protected String getPName(String pName)
//    {
//      return famMembers = pName;
//
//    }  
    public String getMovieGoers()
    {
        return rating;  
    }
    
    //return all family members
    public void listAll()
    {

            for (int cnt=0; cnt<familia.size(); cnt++)
            {
                System.out.println(familia.get(cnt));
            }
    }
    public void addHumans(Adult newAdult)
    {
        try
        {
                familia.add(newAdult);

        }
        catch (NullPointerException npe)
        {
                System.err.println("Error: " + npe);
        }		
}
                
    public static void main(String args[])
    {
         Family  familia = new Family("",0);
         Adult father = new Adult("Russel" , 32);
         Adult mother = new Adult("Lisa",28);           
         
         // Populate the list using the .addHumans() methods
         familia.addHumans(father);
         familia.addHumans(mother);       
         //calls listAll() method to display the family members          
         familia.listAll();

    }

}

//MovieRating class

import java.util.HashMap;
import java.util.Map;

public class MovieRating 
{
    private Map ageMap = new HashMap();
    public MovieRating()
    {
        ageMap.put("G", new Integer(18));
        ageMap.put("PG", new Integer(16));
    }

    public boolean getStatus(String rating, int age)
    {

        Integer rateAge = (Integer)ageMap.get(rating);
        if(rateAge != null)
        {
            int minAge = rateAge.intValue();
            if (age < minAge )
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        return false;
    }
}

I'll really appreciate your help/corrections.

Recommended Answers

All 17 Replies

Where one class ends and the other starts?
Use code tags and have each class separately

the classes are separate. Look at this,
//Movie class
//Cinema class
//Family class
// MovieRating class

Shows you where each class starts. In my implementation they are all separate, I hope that's okay.

the classes are separate. Look at this,
//Movie class
//Cinema class
//Family class
// MovieRating class

Shows you where each class starts. In my implementation they are all separate, I hope that's okay.

now we see what classes there are, just not what code is in them...
what JavaAddict ment, was for you to use Code-Tags [*Code=Java]//enter code here[*/Code] without the *'s, so your code is a bit formatted.
which means we will able to see where the code for one class ends, and the other class starts

//enter code here

And to start, after a quick look, in your Movie class, you have:
String movieRating
private String title
private String mrating

You use mrating at the constructor and movieRating at the set, get methods.
Use only one of them in your class

The
public void addMovieGoers()
method should have as argument the element you want to add to the list, and not
hardcode it in the method: Family fam = new Family("",0)


You didn't do that:

Your Cinema class should also have a setMovie method which takes a Movie as an argument.

You should have a Movie attribute in your class that is been set by the argument of the above
method. Then treat this Movie like any other attribute in your methods:
showMovie() should show the above attribute and not create one inside it.

like, can you give me an example or modify the addMovieGoers() method as you've suggested above, I'm new to java please.

What type of object will those who go to the cinema will be?

public void addMovieGoers(Human h) {
mGoers.add(h);
}

And use the mGoers attribute to print what is needed

that's okay,
How do I check that the movie property has been set and if not throw an exception in the addMovieGoers() method?

that's okay,
How do I check that the movie property has been set and if not throw an exception in the addMovieGoers() method?

Use 'if' and 'throw' statements

there's something I dont understand about collections, for example if I want to create a collection of Human which consist of Adult and Child, ho do I do it?

Are Adult and Child instances of the Human class?:

Human adult = new Human();
Human child = new Human();

ArrayList<Human> list = new ArrayList<Human>();
list.add(adult);
list.add(child);

adult, child are instances of the Human class


OR

Assume you have a class: Human.
And 2 subclasses: Child extends Human and Adult extends Human

Then both classes are Human so you can do this:

Adult adult = new Adult();
Child child = new Child();

ArrayList<Human> list = new ArrayList<Human>();
list.add(adult);
list.add(child);

But remember, in the 2nd case, when you do get from the list you get back Human instances. And unless you know if what you get back is Adult or Child then you can only use methods that are declared in the Human class.

Human h1 = list.get(0);
h1.callMethod(); //declared in the Human class
Human h2 = list.get(1);
h2.callMethod(); //declared in the Human class

Child ch1 = (Child)list.get(1);
ch1.callSomeMethod(); //declared in the Child class

If the list.get(1) is not Child but Adult then you will get a Runtime error.

So before doing this: Child ch1 = (Child)list.get(1)
check if the returned object is Child: Google for: "instance of" keyword

Of course the second case might not be what you need to implement, I haven't read the code.
Also:

ArrayList

After reviewing the classes Family, I came to this conclusion.
You don't need an Adult class, nor a Child class. Family will not extend Human. It has a collection of humans.
This is how is done in reality. You family is not a Human. Your family consists by a group of Humans (father, mother, ...) they are all humans.

So you will have instances of Human class and you will use the age to determine if they are adults or not

Human h1 = new Human("name",5);
if (h1.getAge()<18) {
  System.out.println("This is a child");
}

I took the liberty of adding methods that do that check in the Human class. Also the Family will have an attribute ArrayList, in which you will add Humans (the members of the family)

Here is the modified code. Use these changes to correct the cinema class accordingly:

Human

public class Human {
    private String name = "";
    private int age = 0;

    public Human() {
    }
    
    public Human(String name, int age) {
        setAge(age);
        setName(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    
    public boolean isAdult() {
        return (age>=18);
    }
    
    public boolean isChild() {
        return (age<18);
    }
    
    public String toString() {
        return "Name: "+name+", Age: "+age;
    }

and Family

import java.util.*;
import java.io.*;
//import java.util.Iterator;
public class Family
{
    private ArrayList<Human> familyMembers;
    private String familyName; 
    
    public Family(String familyName)
    {
        this.familyName=familyName;
        familyMembers = new ArrayList<Human>();
    }
    
    public String getFamilyName() {
        return familyName;
    }

    public void setFamilyName(String familyName) {
        this.familyName = familyName;
    }
    
    public ArrayList<Human> getMembers()
    {
        return familyMembers;
    }

    //return all family members
    public void listAll()
    {
        for (int cnt=0; cnt<familyMembers.size(); cnt++)
        {
            System.out.println(familyMembers.get(cnt));
        }
    }
    
    public void addMember(Human newMember)
    {
        try
        {
            familyMembers.add(newMember);
        }
        catch (NullPointerException npe)
        {
            System.err.println("Error: " + npe);
        }
    }
    
    public int getFamilySize() {
        return familyMembers.size();
    }

    public static void main(String args[])
    {
        Family familia = new Family("<Name of the Family>");
        Human father = new Human("Russel" , 32);
        Human mother = new Human("Lisa",28);
        Human son = new Human("Patrick",8);

        familia.addMember(father);
        familia.addMember(mother);
        familia.addMember(son);
        
        familia.listAll();
    }
}

I'm stuck in the Cinema class addMovieGoers method. How do I change my code to do the following:
check that every member of the collection is a human and that they are old enough to watch the movie, if not throw an exception
Add another static method to the cinema class that demonstrates the usage of the cinema class.

Since there have been many changes to the code post the latest Cinema class.
I believe that the human class has a method getAge(). Use it to get the age, use the rating of the movie to get the minimum age and compare these two. You also have written a MRating class with a hashMap. You can use that.

The latest code is as:

Cinema class


import java.util.*;
import java.io.*;
public class Cinema
{
public static final int maxRate = 3;
public static final int minRate = 1;
float cost;
String Title,humans;
ArrayList mGoers;
//instantiating Movie class
Movie mv = new Movie("","");
String mRating = mv.getRating();
String mTitle = mv.getTitle();


public Cinema (String mtitle, float pounds)
{
this.Title=mtitle;
this.cost = pounds;
mGoers = new ArrayList();


}


public float getcost (int people)
{
return cost * people;
}



//methods for adding movie goers which takes a collection of Humans
public void addMovieGoers(Human h)
{
mGoers.add(h); // collection of Human
Human h1 = new Human();
if (h1.getAge()<18)
{
System.out.println("This is a child");
}
else  // Adults, that is age>18
{
Movie movieNew = new Movie("Title","Rating");
try
{


if (!isObjectEmpty(movieNew.getTitle()) && !isObjectEmpty(movieNew.getRating()))
{
System.out.println("The movie is called " +movieNew.getTitle()+
" and is rated " +movieNew.getRating()+ ".");


System.out.println("And the movie goers are: "+mGoers.add(h)+"");


}
else
{
System.out.println("Movie title and rating not set");
}
}
catch(Exception e)
{
System.out.println("Movie properties are not Set");
}
}


}


/**
* Method check that the movie title and rating have been set,
* if not throw an exception.
*/
public void setMovie(Movie movieNew) throws IOException
{
try
{


if (!isObjectEmpty(movieNew.getTitle()) && !isObjectEmpty(movieNew.getRating()))
{
System.out.println("The movie is called " +movieNew.getTitle()+
" and is rated " +movieNew.getRating()+ ".");
}
else
{
System.out.println("Movie title and rating not set");
}
}
catch(Exception e)
{
System.out.println("Title and Rating not Set");
}
}


public void showMovie()
{
try
{


if((mRating!=null)&& (mTitle!=null))
{
System.out.println("Title is "+mTitle+" and is Rated "
+mRating+"");
}
else
{
System.out.println("Either Title or Rating is missing");
}
}
catch(Exception e)
{
System.out.println("The Movie properties not set");
}
finally
{
System.out.println("The movie is over.");
}


}


/**
* Checks is indiacated Object is empty.
* restrictions for raiting type (rating must be >=1 and <=3)
*/


public boolean isObjectEmpty(Object obj)
{
boolean result = obj==null;


// check if movie Title and Rating are set
if((mRating!=null)&& (mTitle!=null))
{
System.out.println("The rating is out of bounds");
}
else
{
System.out.println("Movie properly rated");
}
return result;
}


public static void main(String args[])
{
String temp;
int rate;
System.out.println("What's the Movie rating:");
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));


try
{
temp= stdin.readLine();
rate=Integer.parseInt(temp);
if((rate<1)||(rate>3))
{
System.out.println("Rate out of bounds!");
}
else
{
//
System.out.println("The following can go for a movie:");
Cinema cin = new Cinema("",0);


}
}
catch(Exception e)
{
System.out.println("Movie not properly rated.");
}
finally
{
System.out.println("Cinema closed now.");
}


}
}


 //MovieRating class


import java.util.HashMap;
import java.util.Map;


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)
{


Integer rateAge = (Integer)ageMap.get(rating);
if(rateAge != null)
{
int minAge = rateAge.intValue();
if (age < minAge )
{
return false;
}
else
{
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();
}
}


  //Human class


public class Human {
private String name = "";
private int age = 0;


public Human() {
}


public Human(String name, int age) {
setAge(age);
setName(name);
}


public String getName() {
return name;
}


public void setName(String name) {this.name = name;
}


public int getAge() {
return age;
}


public void setAge(int age) {
this.age = age;
}


public boolean isAdult() {
return (age>=18);
}


public boolean isChild() {
return (age<18);
}


public String toString() {
return "Name: "+name+", Age: "+age;
}


public class <strong class="highlight">Human</strong> { private String name = ""; private int age = 0; public <strong class="highlight">Human</strong>() { } public <strong class="highlight">Human</strong>(String name, int age) { setAge(age); setName(name); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public boolean isAdult() { return (age>=18); } public boolean isChild() { return (age<18); } public String toString() { return "Name: "+name+", Age: "+age; }



and Family
Help with Code Tags
(Toggle Plain Text)


import java.util.*;
import java.io.*;
//import java.util.Iterator;
public class Family
{
private ArrayList<Human> familyMembers;
private String familyName;


public Family(String familyName)
{
this.familyName=familyName;
familyMembers = new ArrayList<Human>();
}


public String getFamilyName() {
return familyName;
}


public void setFamilyName(String familyName) {
this.familyName = familyName;
}


public ArrayList<Human> getMembers()
{
return familyMembers;
}


//return all family members
public void listAll()
{
for (int cnt=0; cnt<familyMembers.size(); cnt++)
{
System.out.println(familyMembers.get(cnt));
}
}


public void addMember(Human newMember)
{
try
{
familyMembers.add(newMember);
}
catch (NullPointerException npe)
{
System.err.println("Error: " + npe);
}
}


public int getFamilySize() {
return familyMembers.size();
}


public static void main(String args[])
{
Family familia = new Family("<Name of the Family>");
Human father = new Human("Russel" , 32);
Human mother = new Human("Lisa",28);
Human son = new Human("Patrick",8);


familia.addMember(father);
familia.addMember(mother);
familia.addMember(son);


familia.listAll();
}
}

Sorry the posting above was interfered with. The code is:

// Cinema class

import java.util.*;
import java.io.*;
public class Cinema 
{
//    public static final int maxRate = 3;
//    public static final int minRate = 1;
    float cost;
    String Title,humans;
    ArrayList mGoers;
    //instantiating Movie class
    Movie mv = new Movie("","");
    String mRating = mv.getRating();
    String mTitle = mv.getTitle();

        public Cinema (String mtitle, float pounds) 
        {
                this.Title=mtitle;
                this.cost = pounds;
                mGoers = new ArrayList();

        }

        public float getcost (int people) 
        {
            return cost * people;
        }
       

        //methods for adding movie goers which takes a collection of Humans
        public void addMovieGoers(Human h)
        {
            mGoers.add(h); // collection of Human
            Human h1 = new Human();
            if (h1.getAge()<18) 
            {
                System.out.println("This is a child");
            }
            else  // Adults, that is age>18
            {
                Movie movieNew = new Movie("Title","Rating");
                try
                {

                    if (!isObjectEmpty(movieNew.getTitle()) && !isObjectEmpty(movieNew.getRating()))
                    {
                         System.out.println("The movie is called " +movieNew.getTitle()+ 
                                " and is rated " +movieNew.getRating()+ ".");

                         System.out.println("And the movie goers are: "+mGoers.add(h)+"");

                    }
                    else
                    {
                         System.out.println("Movie title and rating not set");
                    }
                }
                catch(Exception e)
                {
                    System.out.println("Movie properties are not Set");
                }      
            }
            
        }
        
        /**
        * Method check that the movie title and rating have been set,
        * if not throw an exception.
        */
        public void setMovie(Movie movieNew) throws IOException
        {
            try
            {
                      
                if (!isObjectEmpty(movieNew.getTitle()) && !isObjectEmpty(movieNew.getRating()))
                {
                     System.out.println("The movie is called " +movieNew.getTitle()+ 
                            " and is rated " +movieNew.getRating()+ ".");
                }
                else
                {
                     System.out.println("Movie title and rating not set");
                }
            }
            catch(Exception e)
            {
                System.out.println("Title and Rating not Set");
            }
        }
     
        public void showMovie() 
        {
            try
            {

                if((mRating!=null)&& (mTitle!=null))
                {
                    System.out.println("Title is "+mTitle+" and is Rated "
                            +mRating+"");
                }
                else
                {
                    System.out.println("Either Title or Rating is missing");
                }
            }
            catch(Exception e)
            {
                System.out.println("The Movie properties not set");
            }
            finally
            {
               System.out.println("The movie is over.");
            }

        }
        
        /**
        * Checks is indiacated Object is empty.
        * restrictions for raiting type (rating must be >=1 and <=3)
        */
        
        public boolean isObjectEmpty(Object obj)
        {
            boolean result = obj==null;

             // check if movie Title and Rating are set
            if((mRating!=null)&& (mTitle!=null))
            {
                System.out.println("The rating is out of bounds");
            }
            else
            {
                System.out.println("Movie properly rated");
            }
            return result;
        }
        
        public static void main(String args[])
        {
            String temp;
            int rate;
            System.out.println("What's the Movie rating:");
            BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
            
            try
            {
                temp= stdin.readLine(); 
                rate=Integer.parseInt(temp);
                if((rate<1)||(rate>3))
                {
                    System.out.println("Rate out of bounds!");
                }
                else
                {
//                                             
                    System.out.println("The following can go for a movie:");
                    Cinema cin = new Cinema("",0);

                }
            }
            catch(Exception e)
            {
                 System.out.println("Movie not properly rated.");
            }
            finally
            {
                System.out.println("Cinema closed now.");
            }
           
        }
}

//MovieRating class

import java.util.HashMap;
import java.util.Map;

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)
    {

        Integer rateAge = (Integer)ageMap.get(rating);
        if(rateAge != null)
        {
            int minAge = rateAge.intValue();
            if (age < minAge )
            {
                return false;
            }
            else
            {
                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();
    }
}

// Human class

public class Human {
    private String name = "";
    private int age = 0;

    public Human() {
    }
    
    public Human(String name, int age) {
        setAge(age);
        setName(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    
    public boolean isAdult() {
        return (age>=18);
    }
    
    public boolean isChild() {
        return (age<18);
    }
    
    public String toString() {
        return "Name: "+name+", Age: "+age;
    }

First of reread the requirements for the Cinema class and do it all over again.

You will a Movie attribute in the class. You will not instantiate it but use the setMovie() to set its value.
When you call the showMovie, check if the above attribute is null or not in order to see if it set or not.
The same check when you add Humans.

Also when you add Humans all you do display if they are child or not. That is not what is required.
From the Human argument you will get the age. From the movie attribute (if it is set) you will get the rating. And from the MovieRating class you will check if you can add that human or not.

If the class needs a collection of Humans have an ArrayList as attribute and add the Human given to that ArrayList.

You don't need the isEmptyObject method. Just check if the movie is null or if their attributes are set (if they are null or not)

And again reread the requirements and see what you really need

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.