bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 5, Problem 8PP

Explanation of Solution

a.

Method heading for each method:

  • The method heading is "public void sellTickets(int number)" that takes a parameter "number" of integer type and update the number of tickets sold and total sales.
  • The method heading is "public void phoneSalesOver()" that takes no parameters and sales can be made at the venue only...

Explanation of Solution

b.

Preconditions and postconditions of each method:

  • Precondition and postcondition of "public void sellTickets(int number)" method.
    • Precondition: checks whether the input is positive and less than or equal to number of unsold tickets.
    • Postcondition: update the number of tickets sold and total sales.
  • Precondition and postcondition of "public void phoneSalesOver()" method.
    • Precondition: None.
    • Postcondition: This method is used to sell the tickets only at the venue.
  • Precondition and postcondition of "public int getTicketsSold()" method...

Explanation of Solution

c.

Test class for some Java statement:

//Create an object for ConcertPromoter

ConcertPromoter con = new ConcertPromoter();

//Call initialize () method

con.initialize("The Ducks", 100, 10.00, 12.00);

//Display the header message

System.out.println("Concert Promoter Sales Program started");

//Create an object for Scanner class

Scanner reader = new Scanner(System.in);

//Declare and initialize the flag variable

boolean done = false;

//Loop executes until the true

while (!done)

{

/*Call phoneSalesOnly() method to check whether sales through phone. */

if (con.phoneSalesOnly())

//Display the Sales details

System.out.println("Sell tickets (S), Change to venue sales (V), Finish selling (F)");

/*Otherwise, display the modified sales details. */

else

System.out.println("Sell tickets (S), Finish selling (F)");

//Read the input from user

String response = reader.next();

//Check whether the input is equal to "F"

if (response...

Explanation of Solution

d.

Implementation of class:

ConcertPromoter.java:

//Import the java package

import java.util.Scanner;

//Define the class

public class ConcertPromoter

{

//Declare the required variables

private String bandName;

private int capacity;

private int ticketsSold;

private double costPhone;

private double costVenue;

private double totalSales;

private boolean salesAreByPhone;

//Define the sellTickets() method

public void sellTickets(int number)

{

/*Check whether the number is inbetween "0" and ticket left. */

if (number > 0 && number <= getTicketsLeft())

{

//Add the ticket sold number

ticketsSold += number;

/*Call getSaleCost() method to calculate the total sales...

Explanation of Solution

e.

List of extra methods and attributes needed for this implementation:

There is no extra attributes are needed for this implementation.

The extra methods that were used apart from the mentioned methods are,

  • public void initialize() method:
    • This method is used to initialize the declared variables.
  • public boolean phoneSalesOnly() method:
    • This method is used to return the true when user making sales through the phone. Otherwise, return false.
  • public String getSalesReport() method:
    • This method is used to return the sales report of sold tickets count and their amount...

Explanation of Solution

f.

Implementation of class:

ConcertPromoter.java:

//Import the java package

import java.util.Scanner;

//Define the class

public class ConcertPromoter

{

//Declare the required variables

private String bandName;

private int capacity;

private int ticketsSold;

private double costPhone;

private double costVenue;

private double totalSales;

private boolean salesAreByPhone;

//Define the initialize() method

public void initialize(String band, int max, double costOverPhone, double costAtVenue)

{

//Initialize the declared variables

bandName = band;

capacity = max;

ticketsSold = 0;

costPhone = costOverPhone;

costVenue = costAtVenue;

totalSales = 0.0;

salesAreByPhone = true;

}

//Define the doTicketSale() method

public void doTicketSale()

{

//Read the maximum ticket to sell from user

System.out.println("How many tickets to sell? (Maximum " + getTicketsLeft() + ")");

Scanner reader = new Scanner(System.in);

int toSell = reader.nextInt();

//Call sellTickets() method to initialize the flag

boolean saleCompleted = sellTickets(toSell);

//Check whether the flag is "true"

if (saleCompleted)

/*Call getSaleCost() method to calculate the ticket cost and then display it. */

System.out.println("The cost of the tickets is " + getSaleCost(toSell));

//Otherwise, display the error message

else

System.out.println("Sorry, unable to complete that sale");

}

//Define the sellTickets() method

public boolean sellTickets(int number)

{

/*Check whether the number is in between "0" and ticket left. */

if (number > 0 && number <= getTicketsLeft())

{

//Add the ticket sold count

ticketsSold += number;

/*Call getSaleCost() method to calculate the total sales. */

totalSales += getSaleCost(number);

//Return the true

return true;

}

//Otherwise, return the false

else

return false;

}

//Define the getSaleCost() method

public double getSaleCost(int number)

{

//Declare the variable

double saleCost = number;

//Check whether sales by phone is "true"

if (salesAreByPhone)

//Calculate the sale cost with cost phone

saleCost *= costPhone;

/*Otherwise, calculate the sale cost with cost venue. */

else

saleCost *= costVenue;

//Return the sale cost

return saleCost;

}

//Define the phoneSalesOver() method

public void phoneSalesOver()

{

//Set the flag as "false"

salesAreByPhone = false;

}

//Define the getTicketsSold() method

public int getTicketsSold()

{

//Return the ticket sold

return ticketsSold;

}

//Define the getTicketsLeft() method

public int getTicketsLeft()

{

//Return the remaining ticket

return capacity - ticketsSold;

}

//Define the getTotalSales() method

public double getTotalSales()

{

//Return the total sales

return totalSales;

}

//Define the phoneSalesOnly() method

public boolean phoneSalesOnly()

{

//Return the phone sales

return salesAreByPhone;

}

//Define the getSalesReport() method

public String getSalesReport()

{

//Return the sales report

return "Sales for " + bandName + ": Tickets sold: " + ticketsSold + " for " + totalSales;

}

//Define the main() method

public static void main(String[] args)

{

//Create an object for ConcertPromoter

ConcertPromoter con = new ConcertPromoter();

//Call initialize () method

con...

Blurred answer
Students have asked these similar questions
Draw out an example of 3 systems using Lamport’s logical clock and explain the steps in words.
"Systems have become very powerful and sophisticated, providing quality information fordecisions that enable the firm to coordinate both internally and externally."With reference to the above statement compare the operations of any three data gatheringsystems today’s organisations use to aid decision making.
labmas Course Home XDocument courses/13810469/menu/a2c41aca-b4d9-4809-ac2e-eef29897ce04 There are three ionizable groups (weak acids and/or bases) in glutamic acid. Label them on the structure below Drag the appropriate labels to their respective targets. OOH [] CH3N CH CH2 CH2 IC HO Reset Help

Chapter 5 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Chapter 5.1, Problem 11STQ Chapter 5.1, Problem 12STQ Chapter 5.2, Problem 13STQ Chapter 5.2, Problem 14STQ Chapter 5.2, Problem 15STQ Chapter 5.2, Problem 16STQ Chapter 5.2, Problem 17STQ Chapter 5.2, Problem 18STQ Chapter 5.2, Problem 19STQ Chapter 5.2, Problem 20STQ Chapter 5.2, Problem 21STQ Chapter 5.2, Problem 22STQ Chapter 5.2, Problem 23STQ Chapter 5.3, Problem 24STQ Chapter 5.3, Problem 25STQ Chapter 5.3, Problem 26STQ Chapter 5.3, Problem 27STQ Chapter 5.3, Problem 28STQ Chapter 5.3, Problem 29STQ Chapter 5.3, Problem 30STQ Chapter 5.3, Problem 31STQ Chapter 5.3, Problem 32STQ Chapter 5.4, Problem 33STQ Chapter 5, Problem 1E Chapter 5, Problem 2E Chapter 5, Problem 3E Chapter 5, Problem 4E Chapter 5, Problem 5E Chapter 5, Problem 6E Chapter 5, Problem 7E Chapter 5, Problem 8E Chapter 5, Problem 9E Chapter 5, Problem 10E Chapter 5, Problem 1P Chapter 5, Problem 2P Chapter 5, Problem 3P Chapter 5, Problem 4P Chapter 5, Problem 5P Chapter 5, Problem 1PP Chapter 5, Problem 2PP Chapter 5, Problem 3PP Chapter 5, Problem 4PP Chapter 5, Problem 5PP Chapter 5, Problem 6PP Chapter 5, Problem 7PP Chapter 5, Problem 8PP Chapter 5, Problem 9PP Chapter 5, Problem 10PP Chapter 5, Problem 11PP Chapter 5, Problem 12PP

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
One class is derived from another class. The subclass is the derived class, which means the subclass contains m...

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Find the voltage v in the given circuit.

Electric Circuits. (11th Edition)

Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Programming with Microsoft Visual Basic 2017
    Computer Science
    ISBN:9781337102124
    Author:Diane Zak
    Publisher:Cengage Learning
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Text book image
    C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    Text book image
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE; License: Standard Youtube License