[solved]-Class Ticketmachine Describes Ticketmachine Destination Corresponding Price Also Moneycoll Q39010960
The class TicketMachine describes a TicketMachine that has adestination and a corresponding price. It also has moneyCollectionsand balance where money collections is the money collected based onticket purchases and balance is the amount of money the customerhas inserted in the ticket machine.
The TicketMachine class also has a constructor that is used tomake the ticket machine object. Please inspect it to understand itsfunctioning. There are several methods insertMoney, printTicket andprintCollections.
The insertMoney method is used to provide the TicketMachine withmoney so that users can subsequently print tickets. TheprintCollections method is used to print out the money collected bythe TicketMachine. The printTicket method prints out a ticket afterchecking if the balance in the machine is greater than the price.The printBooklet method accepts a parameter n and prints outmultiple tickets based on certain conditions including theparameter n. You have to complete this method
The class TicketPrinter has a main method that creates aTicketPrinter object. The constructor of TicketPrinter keeps takinguser input till the user types in ‘no’. It prints out a messageindicating the destination and price of the tickets. If the usertypes in ‘yes’ the purchaseTickets() method is invoked.
The purchaseTickets method is partially completed where it asksthe user the number of tickets they would like to purchase and alsothe amount of money they would like to put into the machine.
Your task in this assignment is as follows:
A. Start working in the purchaseTickets method inthe TicketPrinter class to complete it.
After the existing code and accepting the user inputs, firstcheck if the user wants to print out only 1 ticket. If they do thenthen call the printTicket() method of the TicketMachine object toprint out a ticket. If they wish to print out more than one ticketthen call the printBooklet method of the TicketMachine object andprovide the number of tickets as an argument.
If the number of tickets is less than zero then please printout
Please enter a number greater than 0.
B. Work in the printBookletmethod.
Use a loop to print out tickets based on the parameter input tothe method. Within the loop:
Check if the balance of the TicketMachine is greater than orequal to the price of the ticket. If it is then invoke theprintTicket method. Subsequently print out a message indicatingwhich number of ticket is being printed out such as
Printed out 4 tickets out of 5.
If balance is not greater than price then inform the user thatthe remainder of balance does not allowed for the continuedprintout of tickets.
Your remainder of balance does not allow the continued printoutof tickets.
Ensure that the loop does not continue trying to print outtickets.
—————– Ticket Machine.java.—
public class TicketMachine { //class signature, name of theclass
private int price;
private String destination;
private int moneyCollections;
private int balance;
/**
* @return the price
*/
public int getPrice() {
return price;
}
/**
* @return the destination
*/
public String getDestination() {
return destination;
}
/**
* @param destination the destination to set
*/
public void setDestination(String destination) {
this.destination =destination;
}
/**
* @param price the price to set
*/
public void setPrice(int price) {
this.price = price;
}
public TicketMachine(int price, Stringdestination)
{
this.price = price;
this.destination =destination;
moneyCollections = 0;
balance = 0;
}
/**
* @return the moneyCollections
*/
public int getMoneyCollections() {
return moneyCollections;
}
/**
* @return the balance
*/
public int getBalance() {
return balance;
}
/**
* Insert money methods takes amount and add’s it tobalance
* @param amount
*/
public void insertMoney(int amount)
{
if(amount > 0)
{
balance =balance + amount;
}
else
{
System.out.println(“Insert a positive value for money.”);
}
}
/**
* Takes a parameter destinationNumber and prints aticket to the right destination
* after making sure that the right amount is presentfor the ticket.
* @param destinationNumber
*/
public void printTicket() //method signature, methodname, public – accessibility
// of the method from external classes
{
if(balance >=price)
{
System.out.println(“************************”);
System.out.println(“********MARTA********”);
System.out.println(“******REDLINE******”);
System.out.println(“****Cost : ” + price + “dollars ****”);
System.out.println(“****Destination :”+destination+” ****”);
System.out.println(“*************************”);
moneyCollections = moneyCollections +price;
balance = balance – price;
}
else
{
System.out.println(“Not enough money to printtickets. n Please insert ” + (price – balance) + ” moredollars.”);
}
}
/**
* Prints out the collections of the ticketmachine.
*/
public void printCollections()
{
System.out.println(“Money Collected: ” + moneyCollections);
}
/**
* print a booklet of tickets
*/
public void printBooklet(int n)
{
// CODE HERE
}
}
—————TicketPrinter.java ———
import java.util.Scanner;
public class TicketPrinter {
private Scanner scan;
private TicketMachine tm;
public TicketPrinter() {
scan = newScanner(System.in);
tm = new TicketMachine(50,”Atlanta”);
System.out.println(“**********Welcome to the Srinivasan ticketing terminal. **********”);
System.out.println(“**********Please employ this terminal to make ticket putchases**********”);
System.out.println(” **********Destination : ” + tm.getDestination() + ” Price : ” + tm.getPrice()+ ” ********** “);
boolean finished = false;
while(!finished)
{
System.out.println(“Would you like to purchase tickets (yes/no)?”);
String response= scan.next();
if(response.toLowerCase().equals(“no”))
{
finished = true;
}
else
{
purchaseTickets();
}
}
System.out.println(“Thank you forusing this ticket machine. Please let us serve you in thefuture.”);
}
public static void main(String[] args) {
TicketPrinter tp = newTicketPrinter();
}
public void purchaseTickets()
{
System.out.println(“How manytickets would you like to purchase? >”);
int number = scan.nextInt();
System.out.println(“Please entermoney for the ticket purchases >”);
int money = scan.nextInt();
tm.insertMoney(money);
//CODE HERE
}
}
Expert Answer
Answer to The class TicketMachine describes a TicketMachine that has a destination and a corresponding price. It also has moneyCol… . . .
OR

