Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Java Programming Assignment: Concert Ticket System

Objective

Demonstrate knowledge of using while and for loops.

Overview

You are creating a system to track the number of tickets available and allow the user to buy tickets. There are two type of tickets - VIP tickets and General Floor tickets.

Procedure

Open BlueJ and create a new project called Assignment05-userName, where username is your USC username (your email address without the @usc.edu) . Get the starter code from Blackboard. Read over and understand the code that already exists.

ConsoleMenu.java (modified from in class CoffeeShop code)

Update the getUserChoice() method in the ConsoleMenu class to make the method loop in order to only allow the user to enter the numbers 1 through numOptions

TicketSystem.java

This skeleton class does some of the setup for the ticket system program; it is up to you to complete this code.

Instance Variables

There are 5 instance variables in this class. You should not create any more.

private Scanner input; // Used to get input from the user

private ConsoleMenu menu; // Used to display a menu and get input from the user private String concertName; // Name of the concert the user is buying tickets for private String venueName; //Name of the venue for the concert

private final int TOTAL_ROWS; //total number of rows in the venue (set in the constructor) private final int VIP_ROWS; // number of VIP rows in the venue (set in the constructor) private int vipSeatsSold; // Needs to increase when the user buys VIP tickets

private int generalSeatsSold; // Needs to increase when the user buys General Floor tickets

Class Variables

There are 3 static constants that you will also use in your program, for setting up the menu and for defining a standard number of seats per row.

Constructors

One constructor is provided for you, it is a version that takes 4 input variables and sets up the corresponding instance variables accordingly. In addition, the other 4 instance variables are initialized in this version of the constructor. Make sure you understand it.

Overload the constructor to allow a user of the system of the Ticket System to just provide a concert & venue name. Also provide a default constructor and set up the concert as "The Killers" playing at the "Staples Center". Do not simply copy and paste the code; you must use the programming construct this() as a method that allows one version of the constructors to call another. Each of the constructors that you provide should have only one statement.

Public Method

The heart of your program is the run method. This method will control how the ticket system runs and will call helper methods to perform tasks.

public void run()

• Print a welcome message that includes the eventName and the venue name. (Could be a method or code within run)

• Print the menu and get input from the user. Use a while or do-while loop to do this until the user enters the option 4 (to EXIT). Don't use a literal "magic "number 4; use the appropriate constant.

o To print the menu, use the ConsoleMenu object.
o Get the menu option by using the ConsoleMenu object.
o Use a switch statement to call the corresponding helper method. For 1, call the printSeats method. For 2, call the buyGeneralTickets method. For 3, call the buyVipTickets method.

• Print a closing message that includes the eventName. (Could be a method or code within run)

Private Methods

Create various helper methods to perform tasks. The following private methods are required. Create as many local variables in the methods as you need. You should not create any more instance variables. You may create other helper methods if you want.

private int vipSeatsAvailable()

• Calculate and return the number of VIP seats available. Use the number of VIP rows, and the number of seats per row to know the number of seats. Use the vipSeatsSold instance variable to figure out how many are available at any point during the program's run time.
private int generalSeatsAvailable()

• Calculate and return the number of Regular concert seats available. Use the total number of row, the number of VIP rows, and the number of seats per row to know the number of general seats in total. Use the generalSeatsSold instance variable to figure out how many are available at any point during the program's run time.

private void printSeats()

• Use nested for loops (Week 7 lecture) to print a diagram of the seats. Print a (V) for VIP seats and a (G) for General Floor seats. Use the TOTAL_ROWS, SEATS_PER_ROW, and VIP_ROWS constants.

• Follow the map with a print out of the number of VIP seats available and the number of General Floor seats available. Use the vipSeatsAvailable and generalSeatsAvailable private helper methods.

• BONUS: print an "x" instead of the (V) or (G) to indicate a seat that is sold.

private void printDashes(int num)

• Use a for loop to print the number of dashes (-) based on the parameter num. (See the example ticket below to see the what printed dashes does; if printDashes(50) is called, then the program loops to print 50 dashes in one row.)
private void printTicket(boolean isVip, int ticketsPurchased)

• Call the printDashes method twice to print two lines of 40 dashes.

• Print the concert name, followed by the venue name. (Include a tab character to indent the text)

• If the isVip parameter is true, then print "VIP Tickets". In the next line, print the starting and ending seat numbers. Use the vipSeatsSold instance variable and the ticketsPurchased parameter to calculate the seat numbers. (Note: printing seat numbers can be a little tricky. You will need to do a little problem-solving to figure out what seat numbers are sold. For example, if 4 vip seat are already sold, and somebody purchases 3 seats, then their seat numbers should be 5-7)

• If the isVip parameter is false, then print "\tGeneral Floor Tickets". In the next line, print the starting and ending seat numbers. Use the generalSeatsSoldinstance variable and the ticketsPurchased parameter to calculate them. (Similar thought process for seat numbers)

• Call the printDashes twice to print two lines of 40 dashes.

private void buyGeneralTickets()

• If there are no general seats available, then print an appropriate message.

• If there are general seats available, then tell the user how many seats are available and ask them how many seats they want to buy. Get their input.

o If the user enters a number less than 1, then print an appropriate message.
o If the user enters a number greater than the seats available, then print an appropriate message.
o If the user enters a valid number, then call the appropriate code to update ("sell") that number of general seats and call the printTicket method with the appropriate parameters.

private void buyVipTickets()

• If there are no vip seats available, then print an appropriate message.

• If there are vip seats available, then tell the user how many seats are available and ask them how many seats they want to buy. Get their input.

o If the user enters a number less than 1, then print an appropriate message.

o If the user enters a number greater than the seats available, then print an appropriate message.

o If the user enters a valid number, then call the appropriate code to update ("sell") that number of vip seats and call the printTicket method with the appropriate parameters.

You may create other helper methods if you want.

Documentation

Use Java doc comments before all methods to ensure good documentation of your code.

Code In Action (Sample Console Output)

Use the previous and following screen shots to see test input and the corresponding results.

Attachment:- Java-Assignment.rar

Java, Programming

  • Category:- Java
  • Reference No.:- M92475988
  • Price:- $120

Priced at Now at $120, Verified Solution

Have any Question?


Related Questions in Java

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As