Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TicketMachine
- {
- public int balance;
- private int price;
- /**
- * Constructor for ticket machine that
- * takes in the price of the ticket as parameter
- */
- public TicketMachine(int ticketCost)
- {
- balance=0;
- price=ticketCost;
- }
- /**
- * Method for Ticket Machine
- * Balance, Price, Insert Money
- */
- public int getBalance()
- {
- return balance;
- }
- /**
- * get method for price of ticket
- */
- public int getPrice()
- {
- return price;
- }
- /**
- * method when user inserts money to ticket machine
- */
- public void insertMoney(int money)
- {
- balance = balance + money;
- }
- /**
- * Prints the ticket if the user has inserted sufficient
- * money into the machine.
- */
- public void printTicket()
- {
- if(price<=balance){
- System.out.println(".----------------------");
- System.out.println("| Ticket CommuterTrain ");
- System.out.println("| Price : " + price);
- System.out.println(";______________________");
- balance = balance - getPrice();
- } else {
- System.out.println("Insufficent Money");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement