Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6.X2 DRAW (by hand) an object diagram with: TheaterCorp object named myCorp corp

ID: 3578924 • Letter: 6

Question

6.X2

DRAW (by hand) an object diagram with:

TheaterCorp object named myCorp

corpName of ”United Movies”

the following Movie elements in the movies HashSet field:

movies.add(new Movie(“Bambi”, Rating.G))

movies.add(new Movie(“Jumanji”, Rating.PG))

movies.add(new Movie(“DieHard”, Rating.R))

the following Theater elements in the theaters ArrayList field:

1st element location is”Pitman” with the following screens HashMap elements:

screens.put( 1 , )

screens.put( 2 , )

2nd element location is”Glassboro” with the following screens HashMap elements:

screens.put( 1 , )

screens.put( 2 , )

NOTE: Make sure the HashMap Movie references à the same Movie objects in the HashSet

I Dont know the Solutions

6.X3

WRITE only ONE line of code using chaining to return the location of the 2ndTheater element in the theaters field for the above project    (NOTE: Assume that all the elements do indeed exist)

WRITE the result of this statement execution given the current state from object diagram in 6.X2

6.X4

WRITE ONE line of code using chaining to return the title of the Movie playing on screens with key 1 of the 1st element in the theaters field for the above project

WRITE the result of this statement execution given the current state from object diagram in 6.X2

6.X5

WRITE ONE line of code using chaining to return the Rating String representation of the Movie playing on screens with key 1 of the 2nd element in the theaters field for the above project

WRITE the result of this statement execution given the current state from object diagram in 6.X2

6.X2

DRAW (by hand) an object diagram with:

TheaterCorp object named myCorp

corpName of ”United Movies”

the following Movie elements in the movies HashSet field:

movies.add(new Movie(“Bambi”, Rating.G))

movies.add(new Movie(“Jumanji”, Rating.PG))

movies.add(new Movie(“DieHard”, Rating.R))

the following Theater elements in the theaters ArrayList field:

1st element location is”Pitman” with the following screens HashMap elements:

screens.put( 1 , )

screens.put( 2 , )

2nd element location is”Glassboro” with the following screens HashMap elements:

screens.put( 1 , )

screens.put( 2 , )

NOTE: Make sure the HashMap Movie references à the same Movie objects in the HashSet

I Dont know the Solutions

6.X3

WRITE only ONE line of code using chaining to return the location of the 2ndTheater element in the theaters field for the above project    (NOTE: Assume that all the elements do indeed exist)

WRITE the result of this statement execution given the current state from object diagram in 6.X2

6.X4

WRITE ONE line of code using chaining to return the title of the Movie playing on screens with key 1 of the 1st element in the theaters field for the above project

WRITE the result of this statement execution given the current state from object diagram in 6.X2

6.X5

WRITE ONE line of code using chaining to return the Rating String representation of the Movie playing on screens with key 1 of the 2nd element in the theaters field for the above project

WRITE the result of this statement execution given the current state from object diagram in 6.X2

Create a "New Class..." named Driver to start execution of a project whose current state is presented in Exercise 6 X2 and thereby depicted by the object diagram drawn there MUST include ONLY a main method with proper header and body contents CHECK your work by calling mycorp.listAllTheaterMovies ()to ensure terminal output matches the following: May also CHECK the solutions and results of your Exercises 6 X3-6.X5 by using println statements here in your main method to test

Explanation / Answer

package com.nu.test;

public class Movie {
  
   private String movieName;
   private String rating;
  
   public Movie(String movieName, String rating) {
       this.movieName = movieName;
       this.rating = rating;
   }
  
   /* (non-Javadoc)
   * @see java.lang.Object#hashCode()
   */
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result
               + ((movieName == null) ? 0 : movieName.hashCode());
       result = prime * result + ((rating == null) ? 0 : rating.hashCode());
       return result;
   }

   /* (non-Javadoc)
   * @see java.lang.Object#equals(java.lang.Object)
   */
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Movie other = (Movie) obj;
       if (movieName == null) {
           if (other.movieName != null)
               return false;
       } else if (!movieName.equals(other.movieName))
           return false;
       if (rating == null) {
           if (other.rating != null)
               return false;
       } else if (!rating.equals(other.rating))
           return false;
       return true;
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return movieName+" "+"("+rating+")";
   }

   /**
   * @return the movieName
   */
   public String getMovieName() {
       return movieName;
   }
   /**
   * @param movieName the movieName to set
   */
   public void setMovieName(String movieName) {
       this.movieName = movieName;
   }
   /**
   * @return the rating
   */
   public String getRating() {
       return rating;
   }
   /**
   * @param rating the rating to set
   */
   public void setRating(String rating) {
       this.rating = rating;
   }
  
  

}

----------------------------------------------------------------------------------------------

package com.nu.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class MapTest {

   public static void main(String[] args) {

       System.out.println("Driver main");
       System.out.println("now playing");
       ListAllTheatresMovies();
   }

   private static void ListAllTheatresMovies() {
       HashSet<Movie> movies = new HashSet<Movie>();
       Map<Integer, Movie> pitsmanScreens = new HashMap<Integer, Movie>();
       Movie movie1 = new Movie("Bombie", "G");
       Movie movie2 = new Movie("Jumanji", "PG");
       Movie movie3 = new Movie("Die Hard", "R");
       movies.add(movie1);
       movies.add(movie2);
       movies.add(movie3);

       pitsmanScreens.put(1, movie1);

       pitsmanScreens.put(2, movie2);

       pitsmanScreens.put(3, movie3);
      
      
       Map<Integer, Movie> GlassbroScreens = new HashMap<Integer, Movie>();
       GlassbroScreens.put(1, movie1);

       GlassbroScreens.put(2, movie2);

       GlassbroScreens.put(3, movie3);
      
       int count=0;
       System.out.println("pitman");
       for (Map.Entry<Integer, Movie> entry : pitsmanScreens.entrySet()) {
           ++count;
           Movie movie=entry.getValue();
       System.out.println("screen= " + count + "--" + movie);
       }

   System.out.println("Glassboro");  
int count1=0;
   for (Map.Entry<Integer, Movie> entry : GlassbroScreens.entrySet()) {
           ++count1;
           Movie movie=entry.getValue();
       System.out.println("screen= " + count1 + "--" + movie);
   }
  
   System.out.println("to retrieve the rating");
   for (Map.Entry<Integer, Movie> entry : pitsmanScreens.entrySet()) {
      
           Movie movie=entry.getValue();
       System.out.println("moviename " +movie.getMovieName() +"---"+"rating "+ movie.getRating());
       }

  
   }

}

output

Driver main
now playing
pitman
screen= 1--Bombie (G)
screen= 2--Jumanji (PG)
screen= 3--Die Hard (R)
Glassboro
screen= 1--Bombie (G)
screen= 2--Jumanji (PG)
screen= 3--Die Hard (R)
to retrieve the rating
moviename Bombie---rating G
moviename Jumanji---rating PG
moviename Die Hard---rating R