With your solid foundation in place it is time to start thinking about code; spe
ID: 3576921 • Letter: W
Question
With your solid foundation in place it is time to start thinking about code; specifically “how to make your program modular”. With large programs it is always better to develop top-down to ensure organization; you focus on the broad picture first and concern yourself with the small details later. Using your documents from Part A break your program down into several methods or objects you think you will need to complete your software. Your program should complete functionality taught throughout the class, including but not limited to: User Input Reading and Writing to a File Using Arrays Using a Menu Using Methods Creating a Dynamic System (add, enter, delete, modify) Searches and Sorts For this submission you will provide: Your rough work before attempting to code. Pseudo Code List of Methods The actual completed code for your program. Screen shots of your program running. Documentation of the work you completed, this should provide dates and time you spent on your assignment and what functionality you were able to complete and what functionality you were unable to code. (This is not a README file but rather a journal of your progress.) If you do not fully understand this submission, please feel free to contact your teacher for further instructions, good luck and have fun!
JAVA
Explanation / Answer
package org.jay.sample;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
enum Rating{
PG,R,G
}
class Movie implements Comparable<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 + "]";
}
@Override
public int compareTo(Movie obj) {
return this.title.compareTo(obj.getTitle());
}
}
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 void sortMovies(){
Collections.sort(movies);
}
}
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();
corp.sortMovies();
System.out.println("---------------After sorting---------------------------");
corp.listAllMovies();
corp.sellTheater("pitman");
System.out.println("---------------After removing theater from location pitman---------------------------");
corp.listAllTheaterMovies();
}
}
-------------------------------------------------------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)
---------------After sorting---------------------------
LIST OF MOVIES
Bambi (G)
Die Hard (R)
Jumanji (PG)
SELLING THEATER - pitman
---------------After removing theater from location pitman---------------------------
NOW PLAYING!!
LOCATION - Glassboro
SCREEN 1 - Jumanji (PG)
SCREEN 2 - Die Hard (R)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.