Lab 8: Constructors and Reference Variables

due Monday, February 3 at 9:20am on Canvas

Pair Programming Required (or No Credit)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document along with your Lab code to Canvas.
  • Only ONE partner submits the Lab code on Canvas.
  • BOTH partners submit the contract.
  • Please make sure both your names are on all the files.
  • If you need help finding a partner, please contact me as soon as possible.

Movie Theater Part 3

  • In this lab, you will update the program you wrote from Lab 7 to include an additional class named Showtime, where we store all the information about a movie's showtime
  • Below is the new (required!) starter code for this lab:

Movie.java Starter Code:

/**
 * @author
 * @author
 * Lab 8, Movie.java
 */
import java.text.DecimalFormat;

public class Movie {
    private String name;
    private double price;
    private Showtime showtime;
    
    /**
     * Default constructor for the Movie
     * class. Initializes name to No name
     * price to 0.0, ticketsSold to 0,
     * calls the Showtime default constructor
     */
    public Movie() {
       
    }
    
    /**
     * Constructor for the Movie class
     * @param name the name of the movie
     * @param price the price of admissions
     * @param showTime the showtime
     */
    public Movie(String newName, double newPrice, Showtime newShowtime) {
       
    }
    
    /**
     * Returns the name of the movie
     * @return the movie name
     */
    public String getName() {
        return null;
    }
    
    /**
     * Returns the price of the movie
     * @return the movie price
     */
    public double getPrice() {
        return 0.0;
    }
    
    /**
     * Returns the Showtime
     * @return the showtime
     */
    public Showtime getShowtime() {
        return null;
    }
    
    /**
     * Updates the name of the movie
     * @param name the new movie name
     */
    public void setName(String name) {
       
    }
    
    /**
     * Updates the price for a movie admission
     * @param price the new movie price
     */
    public void setPrice(double price) {
       
    }
    
    /**
     * Updates the value of the showtime variable
     * @param newShowtime the updated movie showtime
     */
    public void setShowtime(Showtime newShowtime) {
       
    }

    /**
     * Converts a movie into a String
     * in the format:
     * <name>
     * Ticket Price: $<ticketPrice>
     * Show time: <showtime>
     * Hint: call the Showtime toString()
     * Note that there are no <> around the output
     * The <> mean fill in here
     */
    @Override public String toString() {
       
    }
}



  • Note that the above class has replaced all the information about a movie's showtime, with a new data type - Showtime, which is defined below:
Showtime.java Starter Code:
  • Create a new class named Showtime and copy and paste the below starter code into this file.
/**
 * @author
 * @author
 * Lab 8, Showtime.java
 */
public class Showtime {
    private String time;
    private final int SIZE = 9;
    private int ticketsSold;
    private String[][] seats = new String[SIZE][SIZE];
   
    /**
     * Default constructor for the Showtime class
     * Assigns the value "No showtime" to time,
     * Assigns the value 0 to ticketsSold
     * Calls initializeSeats method
     */
    public Showtime() {
       
    }
   
    /**
     * Constructor for the Showtime class
     * @param newTime the time the movie starts
     * Assigns the value 0 to ticketsSold
     * Calls initializes seats
     */
    public Showtime(String newTime) {
       
    }
   
    /**
     * Called by the constructors only
     * Assigns the value of "X" to each
     * seat in the seats array
     */
    private void initializeSeats() {
       
    }
   
    /**
     * Returns the showtime of the movie
     * @return the time the movie starts
     */
    public String getTime() {
        return null;
    }
   
    /**
     * Returns the number of tickets
     * that have been sold
     * @return the number of tickets sold
     */
    public int getTicketsSold() {
        return 0;
    }
   
    /**
     * Returns the value stored for
     * a particular seat
     * @param row the seat row number
     * @param col the seat column number
     * @return an "X" or "T"
     */
    public String getSeat(int row, int col) {
        return null;
    }
   
    /**
     * Updates the showtime of the movie
     * @param showTime the movie showtime
     */
    public void setShowTime(String newTime) {
       
    }
   
    /**
     * Updates a seat value to a T (Taken) or O (new Order)
     * and increases ticketsSold variable
     * @param row the row number
     * @param col the column number
     * @param symbol the letter to assign to that seat position
     */
    public void setSeat(int row, int col, String symbol) {
       
    }
   
    /**
     * Prints out the seats array to the console
     * with row and column numbers
     * and with the placement of the SCREEN in
     * row 10
     * Along with the message "Here are the
     * available seats for <name>:"
     * Note that there are no <> around the output
     * @param name the name of the movie
     */
    public void printSeatingChart(String name) {
       
    }
   
    /**
     * Returns a String in the format
     * Showtime: <time>
     */
    @Override public String toString() {
        return "";
    }

}


Theater.java Starter Code:

/**
 * @author
 * @author
 * Lab 8, Theater.java
 */

import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.PrintWriter;
import java.io.IOException;

public class Theater {
    public static void main(String[] args) throws IOException {
        int row, col, rowCol, seats, total = 0;
        String name, showTime;
        double price;
        ArrayList<Movie> movies = new ArrayList<Movie>();
       
       
        File file = new File("movies.txt");
        Scanner input = new Scanner(file);
        while(input.hasNextLine()) {
           
        }
        input.close();
        input = new Scanner(System.in);
       
        System.out.println("Welcome to the CineBucks Movie Theater!");
        System.out.println("\nBelow are our current movies and showtimes:\n");
       
        System.out.println("\nThank you! Please come again.");

        input.close();
    }
}



Input file: movies.txt:

Stars Wars: The Rise of Skywalker
10.50
7:35pm
5
14
15
16
58
59
Little Women
11.00
8:25pm
11
33
34
35
36
61
62
78
79
11
12
13
1917
14.95
9:10pm
4
24
25
26
27
Dolittle
12.50
6:40pm
9
15
28
29
41
42
43
54
55
56
The Gentlemen
13.75
8:35pm
3
94
95
96

Sample Output:

Welcome to the CineBucks Movie Theater!

Below are our current movies and showtimes:

Option 1:
Stars Wars: The Rise of Skywalker
Ticket price: $10.50
Showtime: 7:35pm

Option 2:
Little Women
Ticket price: $11.00
Showtime: 8:25pm

Option 3:
1917
Ticket price: $14.95
Showtime: 9:10pm

Option 4:
Dolittle
Ticket price: $12.50
Showtime: 6:40pm

Option 5:
The Gentlemen
Ticket price: $13.75
Showtime: 8:35pm

Enter the option number of the movie: 2

You selected Little Women!


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X X X X X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Enter the rowcol of the seat to purchase: 44
Your ticket is confirmed!


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X X O X X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Another seat (y/n)?: y


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X X O X X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Enter the rowcol of the seat to purchase: 34

Sorry! That seat is already taken!
Please try again.


Another seat (y/n)?: y


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X X O X X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Enter the rowcol of the seat to purchase: 43
Your ticket is confirmed!


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X O O X X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Another seat (y/n)?: y


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X O O X X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Enter the rowcol of the seat to purchase: 44

Sorry! That seat is already taken!
Please try again.


Another seat (y/n)?: y


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X O O X X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Enter the rowcol of the seat to purchase: 45
Your ticket is confirmed!


Here are the available seats for Little Women:

  1 2 3 4 5 6 7 8 9
1 T T T X X X X X X
2 X X X X X X X X X
3 X X T T T T X X X
4 X X O O O X X X X
5 X X X X X X X X X
6 T T X X X X X X X
7 X X X X X X X T T
8 X X X X X X X X X
9 X X X X X X X X X
*******SCREEN******

Another seat (y/n)?: n

You ordered 3 tickets for Little Women at 8:25pm.
Your total today is: $33.00.


Thank you! Please come again.



What to Submit:

  • Submit your completed Showtime.java, Movie.java and Theater.java files to Canvas
    • Make sure both partners' names are on all the files
    • Only one partner should submit the code
    • both partners submit the pair programming contract to Canvas (5 point deduction for missing contract).
  • Please remove all package statements before submitting (5 point deduction)
  • Please do not submit as a zip file (5 point deduction)
  • Please submit properly formatted code (5 point deduction)
    • Go to Source->Format before submitting

How You Will Be Graded:

  • 100 points: The assignment works as shown in the sample output. All required features are implemented and implemented correctly.
  • 80-100 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly. Wording or spacing choices may differ from those shown.
  • 40-80 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly.
  • 0 points: Code does not compile or outputs an error at runtime, or the starter code was altered from what was provided (rather than added on to).