Question

Java program. Mike's Movie Theater is a local cinema showing the latest Hollywood hits. Create a...

Java program.

Mike's Movie Theater is a local cinema showing the latest Hollywood hits. Create a class called Movie that stores basic information about a single movie: the title, the running time or length of the film (in minutes), the showtimes (as a single string, such as "11:00,3:15,7:30"), and the film's rating (R, PG-13, PG, or G). Include get and set methods for each; the setter for rating should check that the value is one of the four valid options and, if not, should set the rating to "Not Rated". Be sure to include a constructor that allows values to be set upon instantiation. Finally, a method called addPreviews should accept the number of previews to be shown prior to the movie, and then add 2 minutes for each to the movie's running time.

Demonstrate that your class works in a program called MovieDemo. It does not need to have user input, but make sure you demonstrate that all methods and fields work correctly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Arrays;

class Movie {
    private String title;
    private int length;
    private String showTime;
    private String ratings;
    public Movie(String title, int length, String showTime, String ratings) {
        this.title = title;
        this.length = length;
        this.showTime = showTime;
        setRatings(ratings);
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public int getLength() {
        return length;
    }
    public void setLength(int length) {
        this.length = length;
    }
    public String getShowTime() {
        return showTime;
    }
    public void setShowTime(String showTime) {
        this.showTime = showTime;
    }
    public String getRatings() {
        return ratings;
    }
    public void setRatings(String ratings) {
        if(Arrays.asList(new String[] {"R", "PG-13", "PG", "G"}).indexOf(ratings) == -1) {
            this.ratings = "Not Rated";
        } else {
            this.ratings = ratings;
        }
    }

    public void addPreviews(int p) {
        length += 2*p;
    }
    @Override
    public String toString() {
        return "Movie [
title: " + title + "
length: " + length + "
showTime: " + showTime + "
ratings: " + ratings
                + "]
";
    }   

}

public class MovieDemo {

    public static void main(String[] args) {
        Movie SpiderMan = new Movie("Spider Man", 90, "1:00", "PG-13");
        System.out.println(SpiderMan);

        SpiderMan.setRatings("XYZ");
        System.out.println(SpiderMan);

        SpiderMan.addPreviews(4);
        System.out.println(SpiderMan);
    }

}


Please upvote, as i have given the exact answer as asked in question. Still in case of any concerns in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
Java program. Mike's Movie Theater is a local cinema showing the latest Hollywood hits. Create a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...

    WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...

  • Write a program in java. You are tasked with writing an application that will keep track...

    Write a program in java. You are tasked with writing an application that will keep track of Insurance Policies. Create a Policy class called InsurancePolicies.java that will model an insurance policy for a single person. Use the following guidelines to create the Policy class: • An insurance policy has the following attributes: o Policy Number o Provider Name o Policyholder’s First Name o Policyholder’s Last Name o Policyholder’s Age o Policyholder’s Smoking Status (will be “smoker” or “non-smoker”) o Policyholder’s...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Java Painter Class This is the class that will contain main. Main will create a new...

    Java Painter Class This is the class that will contain main. Main will create a new Painter object - and this is the only thing it will do. Most of the work is done in Painter’s constructor. The Painter class should extend JFrame in its constructor.  Recall that you will want to set its size and the default close operation. You will also want to create an overall holder JPanel to add the various components to. It is this JPanel that...

  • Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due:...

    Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due: Wednesday, March 25 70 points (+ up to 15 extra credit) The purpose of this assignment is to give you practice implementing your own classes. It also provides extra practice with arrays. Task Implement a class Task, which is used to represent a job that should be done. It should contain the following private fields: .name text description of what job should be done...

  • In this assignment, we will be making a program that reads in customers' information, and create...

    In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...

  • Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic me...

    Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT