1 answer

Please include a DETAILED documentation so i can understand it better :) The purpose of this...

Question:

The purpose of this assignment is to learn how to work with iteration and constants Additionally, you get more practice on ho

please include a DETAILED documentation so i can understand it better :)

The purpose of this assignment is to learn how to work with iteration and constants Additionally, you get more practice on how to write all of your own code and Javadoc comments Problem Description This problem is inspired by the book's Problem P6.10 on page 304. You are to write an application to presell a limited number of movie tickets. The simple user interface will be contained in Main java and the object to implement this is referred to as TicketSeller and consists of only the following public methods: public TicketSeller(int initialTicketAllotment) -Specify the number of tickets you want to sell. public int requestTickets(int ticketRequest) Requests ticketRequest number of tickets. Returns TicketSeller.TOO_MANY_TICKETS_REQUESTED if there are more than TicketSeller.MAXIMUM_TICKETS ALLOWED. Note that one of these constants is private and one is public. Which one needs to be exposed to the user? public int getNumberOfBuyerso - Tracks number of ticket buyers. You only count buyers who have fulfilled a request. Errors don't count. Your Main,java should contain code to test your TicketSeller object. Note Your requests for tickets will always be positive integers. You can pre-sell O tickets. Note that all requests but a request for 0 tickets are requesting too many tickets. . You should use constants for TicketSeller.TOO MANY TICKETS_REQUESTED and TicketSeller.MAXIMUM TICKETS_ALLOWED not an enumerated type.

Answers

Hello, I have answered a similar question once. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// TicketSeller.java

public class TicketSeller {

                // private constant for storing maximum number of tickets per person

                private static final int MAXIMUM_TICKETS_ALLOWED = 4;

                // public constant for representing error state if too many tickets are

                // requested.

Here -999 can be replaced by any (negative) number,.

                public static final int TOO_MANY_TICKETS_REQUESTED = -999;

                // total number of tickets available

                private int numTickets;

                // total number of legit buyers

                private int numBuyers;

                /**

                * constructor to initialize number of tickets

                *

                * @param initialTicketAllotment

                *           - number of tickets available

                */

                public TicketSeller(int initialTicketAllotment) {

                                this.numTickets = initialTicketAllotment;

                                numBuyers = 0;

                }

                /**

                * method to request a specific number of tickets

                *

                * @param ticketRequest

                *            number of tickets wanted

                * @return TOO_MANY_TICKETS_REQUESTED if user asks for tickets more than

                *         MAXIMUM_TICKETS_ALLOWED or more than available tickets. In all

                *         other cases, returns the number of tickets available

                */

                public int requestTickets(int ticketRequest) {

                                if (ticketRequest > MAXIMUM_TICKETS_ALLOWED

                                                               || ticketRequest > numTickets) {

                                               // error

                                               return TOO_MANY_TICKETS_REQUESTED;

                                }

                                // valid. subtracting tickets

                                numTickets -= ticketRequest;

                                // incrementing buyers

                                numBuyers++;

                                // returning tickets left

                                return numTickets;

                }

                /**

                * returns the number of valid buyers

                *

                * @return the current value of numBuyers

                */

                public int getNumberOfBuyers() {

                                return numBuyers;

                }

}

// Main.java

import java.util.Scanner;

public class Main {

                public static void main(String[] args) {

                                // scanner to read user input

                                Scanner scanner = new Scanner(System.in);

                                // getting initial number of tickets

                                System.out.print("Enter the total number of tickets: ");

                                int n = scanner.nextInt();

                                // creating a TicketSeller object

                                TicketSeller seller = new TicketSeller(n);

                                int remaining = n; // number of tickets remaining

                                // loops until all tickets are sold

                                while (remaining > 0) {

                                               // asking for input

                                               System.out.print("Input the number of tickets you want: ");

                                               int tickets = scanner.nextInt();

                                               // requesting tickets

                                               int result = seller.requestTickets(tickets);

                                               if (result == TicketSeller.TOO_MANY_TICKETS_REQUESTED) {

                                                               // error

                                                               System.out.println("Too many tickets requested, try again!");

                                               } else {

                                                               // valid number of tickets

                                                               System.out.println("Thank you for your purchase! " + result

                                                                                               + " number of tickets are remaining");

                                                               // updating number of tickets available

                                                               remaining = result;

                                               }

                                }

                                System.out.println("Tickets have been sold out!");

                                // displaying number of buyers

                                System.out.println("Number of buyers: " + seller.getNumberOfBuyers());

                }

}

/*OUTPUT*/

Enter the total number of tickets: 10

Input the number of tickets you want: 6

Too many tickets requested, try again!

Input the number of tickets you want: 2

Thank you for your purchase! 8 number of tickets are remaining

Input the number of tickets you want: 4

Thank you for your purchase! 4 number of tickets are remaining

Input the number of tickets you want: 2

Thank you for your purchase! 2 number of tickets are remaining

Input the number of tickets you want: 2

Thank you for your purchase! 0 number of tickets are remaining

Tickets have been sold out!

Number of buyers: 4

.

Similar Solved Questions

1 answer
Knowing that at the instant shown ter AB has a constant angular velocity of 4 radis...
Knowing that at the instant shown ter AB has a constant angular velocity of 4 radis clockwise, determine the angular acceleration of bar BD and bar DE (Round the final answers to two decimal places 175 B Th15 The angular acceleration of bat eos The angular acceperation of har DES rady Clockwise radi...
1 answer
To save for retirement, you deposit $8,592.06 at the end of every 6 months. If you...
To save for retirement, you deposit $8,592.06 at the end of every 6 months. If you make these payments for the next 44 years while you work, and the interest rate is 12.03%, how much will you have in your retirement account when you go to retire? That is, immeidately after the last payment is made A...
1 answer
V 4. For the circuit shown, name the currents and write sufficient equations to solve for...
V 4. For the circuit shown, name the currents and write sufficient equations to solve for them....
1 answer
B. i) Convert ft) -10est+ 8est sin(12t) to the s-domain, for fit)>o. ii) Convert F(s) :24-to...
B. i) Convert ft) -10est+ 8est sin(12t) to the s-domain, for fit)>o. ii) Convert F(s) :24-to the time domain. s2+5s+6...
1 answer
2. For the following circuit determine: (a) Reotal: (b) current in the circuit; (c) power delivered...
2. For the following circuit determine: (a) Reotal: (b) current in the circuit; (c) power delivered to the circuit. 几3二千几...
1 answer
Find the ratio of the number of water molecules in one tablespoon of water to the...
Find the ratio of the number of water molecules in one tablespoon of water to the number of tablespoons of water on the entire earth. FIND THE RATIO OF THE NUMBER OF WATER MOLECULES IN ONE TABLESPOON OF WATER TO THE NUMBER OF TABLESPOONS OF WATER ON THE ENTIRE EARTH...
1 answer
Alpine Luggage has a capacity to produce 440,000 suitcases per year. The company is currently producing...
Alpine Luggage has a capacity to produce 440,000 suitcases per year. The company is currently producing and selling 360,000 units per year at a selling price of $399 per case. The cost of producing and selling one case follows: Variable manufacturing costs $ 162 Fixed manufacturing costs...
1 answer
A waiter received a $5.25 tip. If the check totaled $25, what percentage was received?
A waiter received a $5.25 tip. If the check totaled $25, what percentage was received?...
1 answer
The diagram below shows a long wire with a right angle bend. A current of !...
The diagram below shows a long wire with a right angle bend. A current of ! 3.32 A flows through the wire. Determine the magnetic field (in unit vector rotation) at the point which is a distance - 1.72 cm from the comer of the bend. (Assume that the +x axis is directed to the right, the +y axis is d...
1 answer
What happens if monopolist charges a price of $2? SMC Revenues and costs (dollars) ATC AVC...
What happens if monopolist charges a price of $2? SMC Revenues and costs (dollars) ATC AVC MR. | LITIQ 0 100 200 800 300 400 500 600 700 Quantity...
1 answer
I need help in these questions in 30 minutes, please answer them fast Question 42 The...
I need help in these questions in 30 minutes, please answer them fast Question 42 The price leader will sometimes flood the market with deeply-discounted goods. Why? It has the capacity to punish other firms that are defecting from order in an industry It will realize high profits in the short-...
1 answer
Describe the levels of evidence and provide an example of the type of practice change that could result from each. Could...
Describe the levels of evidence and provide an example of the type of practice change that could result from each. Could you please provide an example for when a strong recommendation can be made from lower levels of evidence? Have you found an application of this in your own topic or practice?...
1 answer
6. A circular corrugated metal water channel has a slope of 1:800 and a diameter of 6 ft (a) Estimate the normal discharge, in gal/min, when the water depth is 4 ft. (b) For this condition, calcu...
6. A circular corrugated metal water channel has a slope of 1:800 and a diameter of 6 ft (a) Estimate the normal discharge, in gal/min, when the water depth is 4 ft. (b) For this condition, calculate the average wall shear stress. P 1.94 Slug/ft The geometry of this circular partly full channel is g...
1 answer
Cell bio help Question 19 2 pts During iPSC formation, which protein is most likely to...
cell bio help Question 19 2 pts During iPSC formation, which protein is most likely to be decreased? O cyclin D O Nanog Sox2 0 Oct4 E-cadherin...
1 answer
Based on the above information, place in the order of priority the correct sequence that each...
Based on the above information, place in the order of priority the correct sequence that each intervention should occur (What will you do first?) • Infuse the diltiazem at 10 mg/hr. • Infuse the IV fluid 0.9% NS at 50 ml/hr. Obtain intravenous access using an 18-or 20-gauge peripheral angi...
1 answer
A stock has a beta of 1.22the expected return on the market is 12 percent, and...
A stock has a beta of 1.22the expected return on the market is 12 percent, and the risk- free rate is 4.65 percent. What must the expected return on this stock be? (Do not round Intermediate calculations and enter your answer as a percent rounded to 2 decimal places, e.g., 32.16.) Expected return %...
1 answer
3 What is the structure of (PhCH2)3SnCl? (Draw a 3-D molecular strucutre)
3 What is the structure of (PhCH2)3SnCl? (Draw a 3-D molecular strucutre)...
1 answer
Light of wavelength 618.0 nm is incident on a narrow slit. The diffraction pattern is viewed...
Light of wavelength 618.0 nm is incident on a narrow slit. The diffraction pattern is viewed on a screen 62.5 cm from the slit. The distance on the screen between the fifth order minimum and the central maximum is 1.71 cm. What is the width of the slit?...
1 answer
Common-Size Balance Sheets Feb. 01, 2019 Feb. 02, 2018 Feb. 01. 2019 Feb 02, 2018 cell...
Common-Size Balance Sheets Feb. 01, 2019 Feb. 02, 2018 Feb. 01. 2019 Feb 02, 2018 cell references to ar credit 3 Current assets 4 Cash and cash equivalents 5 Short Investments 6 Merchandise Inventory.net 7 Other current assets 3 Total current assets $ 511 21B $ 588 102 12,561 938 14,228 BAG 12,772 1...
1 answer
The figure shows a rectangular array of charged particles fixed in place, with distance a =...
The figure shows a rectangular array of charged particles fixed in place, with distance a = 30.1 cm and the charges shown as integer multiples of q1 = 2.02 pC andq2 = 7.94 pC. With V= 0 at infinity, what is the net electric potential at the rectangle's center?...