do New Project § In BlueJ, create “New Project” named LASTNAME-theater-corp Use
ID: 3577916 • Letter: D
Question
do
New Project
§ In BlueJ, create “New Project” named LASTNAME-theater-corp
Use good programming style and Javadoc documentation standards
LASTNAME-theater-corp
CODE
Rating
Create “New Class…” for enumerated type named Rating
Declare the 3 possible values (as stated in requirements above on pg. 1)
Movie
Create “New Class…” named Movie to store the details of a movie
Declare the 2 fields for the movie details (as stated in requirements above)
Code Movie(String title, Rating rating) with initialization of the 2 fields
Code accessor method getTitle to return the title field
Code accessor method getRatingString to return a String representation of the rating field (MUST use toString method where necessary)
Theater
Create “New Class…” named Theater to store the details of a theater
Declare the 2 fields for the theater information (as stated in requirements)
Code a constructor with 1 parameter for initialization of the 2 fields
location field name MUST be SAME as parameter name and use this
MUST instantiate screens field appropriately
Code the appropriate accessor methods getLocation and getScreens
Code mutator method with the following header to add a movie to a screen:
public void addScreen(Integer screen, Movie movie)
TheaterCorp
Create “New Class…” named TheaterCorp
Declare the 3 fields for the theater corporation (as stated in requirements)
Code a constructor with 1 parameter for initialization of the 3 fields
corpName field name MUST be SAME as parameter name and use this
MUST instantiate both theaters and movies fields appropriately
Code accessor methods getCorpName, getTheaters and getMovies
Code the following mutator method to add a theater to the corporation:
public void addTheater(Theater theater)
Code the following overloaded methods to add a Movie to the movies collection for the theater corporation:
public void addMovie(Movie movie)
public void addMovie(String title, Rating rating)
Code a mutator method to return a boolean value after trying to sell (by removing) ALL theaters matching a certain location:
public boolean sellTheater(String location)
MUST first check if there are any theaters at all and (if not) just prints “NO THEATERS TO SELL”
MUST only use an Iterator with a for loop for iteration (see pg. 148)
MUST ensure that the searching for location matches even if the upper/lower-cases do not, but no need to worry about trimming or spaces (HINT: find a String method that eliminates case-sensitivity)
MUST print resulting message ONLY ONCE, if any Theater was:
sold (i.e. searched/found/removed), then prints (only one time) “SELLING THEATER - <location>”
otherwise, prints “NO THEATER LOCATION - <location>”
MUST return true if any Theater was sold … otherwise return false
CODE
TheaterCorp
(cont.)
In TheaterCorp, code a print method to output ALL the corporation’s movies:
public void listAllMovies( )
MUST first check if there are any movies at all and (if not) just prints “NO MOVIES EXIST”
MUST print heading “LIST OF MOVIES” (ONLY if >= 1 movie exists)
MUST use a for-each loop and print each Movie listing formatted as “ <title> (<rating>)” (e.g. “ Bambi (G)”)
NOTE: the leading spaces in the formatting
Code method to print ALL movies now playing at ALL theaters:
public void listAllTheaterMovies( )
MUST first check if any theaters, or prints “NO THEATERS EXIST”
MUST print heading “NOW PLAYING!!” (ONLY if >= 1 theater exists)
MUST use a for-each loop to iterate through all existing theaters and:
MUST print formatted heading for each and every location listing as “LOCATION - <location>” (e.g. “LOCATION - Pitman”)
MUST then check the screens at that location and:
if none exists, prints “NO SCREENS EXIST”
MUST otherwise, use a for-each loop with keySet to print each Movie listing on each of the screens with the output formatted as “ SCREEN <key> - <title> (<rating>)” (e.g. “ SCREEN 1 - Bambi (G)”) NOTE: leading spaces
Driver
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:
Driver.main({ })
NOW PLAYING!!
LOCATION- Pitman
SCREEN 1 - Bambi (G)
SCREEN 2 - Jumanji (PG)
LOCATION - Glassboro
SCREEN 1 - Jumanji (PG)
SCREEN 2 - Die Hard (R)
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
Fully test that all project requirements and details are met successfully
All spaces, text, headings and errors are printed exactly as required
Ensure code compiles AND executes with NO syntax, logic or runtime errors
Upload the LASTNAME-theatre-corp project codes into BB as a single zipped file.
do
New Project
§ In BlueJ, create “New Project” named LASTNAME-theater-corp
Use good programming style and Javadoc documentation standards
LASTNAME-theater-corp
CODE
Rating
Create “New Class…” for enumerated type named Rating
Declare the 3 possible values (as stated in requirements above on pg. 1)
Movie
Create “New Class…” named Movie to store the details of a movie
Declare the 2 fields for the movie details (as stated in requirements above)
Code Movie(String title, Rating rating) with initialization of the 2 fields
Code accessor method getTitle to return the title field
Code accessor method getRatingString to return a String representation of the rating field (MUST use toString method where necessary)
Theater
Create “New Class…” named Theater to store the details of a theater
Declare the 2 fields for the theater information (as stated in requirements)
Code a constructor with 1 parameter for initialization of the 2 fields
location field name MUST be SAME as parameter name and use this
MUST instantiate screens field appropriately
Code the appropriate accessor methods getLocation and getScreens
Code mutator method with the following header to add a movie to a screen:
public void addScreen(Integer screen, Movie movie)
TheaterCorp
Create “New Class…” named TheaterCorp
Declare the 3 fields for the theater corporation (as stated in requirements)
Code a constructor with 1 parameter for initialization of the 3 fields
corpName field name MUST be SAME as parameter name and use this
MUST instantiate both theaters and movies fields appropriately
Code accessor methods getCorpName, getTheaters and getMovies
Code the following mutator method to add a theater to the corporation:
public void addTheater(Theater theater)
Code the following overloaded methods to add a Movie to the movies collection for the theater corporation:
public void addMovie(Movie movie)
public void addMovie(String title, Rating rating)
Code a mutator method to return a boolean value after trying to sell (by removing) ALL theaters matching a certain location:
public boolean sellTheater(String location)
MUST first check if there are any theaters at all and (if not) just prints “NO THEATERS TO SELL”
MUST only use an Iterator with a for loop for iteration (see pg. 148)
MUST ensure that the searching for location matches even if the upper/lower-cases do not, but no need to worry about trimming or spaces (HINT: find a String method that eliminates case-sensitivity)
MUST print resulting message ONLY ONCE, if any Theater was:
sold (i.e. searched/found/removed), then prints (only one time) “SELLING THEATER - <location>”
otherwise, prints “NO THEATER LOCATION - <location>”
MUST return true if any Theater was sold … otherwise return false
Explanation / Answer
package org.jay.sample;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
enum Rating{
PG,R,G
}
class Movie{
private String title;
private Rating rating;
/**
* @param title
* @param rating
*/
public Movie(String title, Rating rating) {
this.title = title;
this.rating = rating;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the rating
*/
public String getRatingString() {
return rating.toString();
}
/**
* @param rating the rating to set
*/
public void setRating(Rating rating) {
this.rating = rating;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Movie [title=" + title + ", rating=" + rating + "]";
}
}
class Theater{
private Map<Integer, Movie>screens;
private String location;
/**
* @param screens
* @param location
*/
public Theater(String location) {
this.screens = new HashMap<>();
this.location = location;
}
/**
*
* @param screen
* @param movie
*/
public void addScreen(Integer screen, Movie movie){
screens.put(screen,movie);
}
/**
* @return the screens
*/
public Map<Integer, Movie> getScreens() {
return screens;
}
/**
* @return the location
*/
public String getLocation() {
return location;
}
}
class TheaterCorp{
private String corpName;
private List<Theater>theaters;
private List<Movie>movies;
/**
* @param corpName
* @param theaters
* @param movies
*/
public TheaterCorp(String corpName) {
this.corpName = corpName;
this.theaters = new ArrayList<>();
this.movies = new ArrayList<>();
}
/**
* @return the corpName
*/
public String getCorpName() {
return corpName;
}
/**
* @return the theaters
*/
public List<Theater> getTheaters() {
return theaters;
}
/**
* @return the movies
*/
public List<Movie> getMovies() {
return movies;
}
/**
*
* @param theater
*/
public void addTheater(Theater theater){
if(theater!=null){
theaters.add(theater);
}
}
/**
*
* @param movie
*/
public void addMovie(Movie movie){
if(movie!=null){
movies.add(movie);
}
}
/**
*
* @param title
* @param rating
*/
public void addMovie(String title, Rating rating){
if(title!=null && rating!=null && title.trim().length()>0){
Movie movie = new Movie(title, rating);
movies.add(movie);
}
}
/**
*
* @param location
* @return boolean
*/
public boolean sellTheater(String location){
boolean theaterFound=false;
if(theaters.size()>0){
for(Iterator<Theater> theaterIter = theaters.iterator(); theaterIter.hasNext();){
Theater theater=theaterIter.next();
if(theater.getLocation().equalsIgnoreCase(location)){
theaterIter.remove();
System.out.println("SELLING THEATER - "+location+"");
theaterFound=true;
break;
}
}
if(!theaterFound){
System.out.println("NO THEATER LOCATION - "+location+"");
}
}else{
System.out.println("NO THEATERS TO SELL");
return false;
}
return theaterFound;
}
/**
* List all movie
*/
public void listAllMovies(){
if(movies.size()>0){
System.out.println("LIST OF MOVIES");
for (Movie movie : movies) {
System.out.println(""+movie.getTitle()+" ("+movie.getRatingString()+")");
}
}else{
System.out.println("NO MOVIES EXIST");
}
}
/**
* List all theater movies
*/
public void listAllTheaterMovies(){
if(theaters.size()>0){
System.out.println("NOW PLAYING!!");
for (Theater theater : theaters) {
System.out.println("LOCATION - "+theater.getLocation()+"");
if(theater.getScreens().size()>0){
Map<Integer, Movie>screens=theater.getScreens();
for(Integer key:screens.keySet()){
System.out.println(" SCREEN "+key+" - "+screens.get(key).getTitle()+" ("+screens.get(key).getRatingString()+")");
}
}else{
System.out.println("NO SCREENS EXIST");
}
}
}else{
System.out.println("NO THEATERS EXIST");
}
}
}
public class Driver {
public static void main(String[] args) {
Movie movie1=new Movie("Bambi", Rating.G);
Movie movie2=new Movie("Jumanji", Rating.PG);
Movie movie3=new Movie("Die Hard", Rating.R);
Theater theater1=new Theater("Pitman");
theater1.addScreen(1, movie1);
theater1.addScreen(2, movie2);
Theater theater2=new Theater("Glassboro");
theater2.addScreen(1, movie2);
theater2.addScreen(2, movie3);
TheaterCorp corp=new TheaterCorp("PVR");
corp.addTheater(theater1);
corp.addTheater(theater2);
corp.addMovie(movie1);
corp.addMovie(movie2);
corp.addMovie(movie3);
corp.listAllTheaterMovies();
System.out.println("------------------------------------------");
corp.listAllMovies();
}
}
----------------------------------------------------------------Output-----------------------------------------------------------------
NOW PLAYING!!
LOCATION - Pitman
SCREEN 1 - Bambi (G)
SCREEN 2 - Jumanji (PG)
LOCATION - Glassboro
SCREEN 1 - Jumanji (PG)
SCREEN 2 - Die Hard (R)
------------------------------------------
LIST OF MOVIES
Bambi (G)
Jumanji (PG)
Die Hard (R)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.