daily pastebin goal
13%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 73 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. import javax.swing.JOptionPane;
  2.  
  3. class TicketMachine{
  4.  
  5.  
  6.  
  7.     public static void main(String[] args){
  8.  
  9.         TicketMachine ticket = new TicketMachine();
  10.  
  11.         String palagtPengerLest = JOptionPane.showInputDialog("Legg pa penger");
  12.  
  13.         int palagtPenger = Integer.parseInt(palagtPengerLest);
  14.  
  15.         ticket.insertMoney(palagtPenger);
  16.  
  17.        
  18.  
  19.            
  20.  
  21.  
  22.  
  23.     }
  24.  
  25.    
  26.  
  27. // The price of a ticket from this machine.
  28.  
  29. private int price;
  30.  
  31. // The amount of money entered by a customer so far.
  32.  
  33. private int balance;
  34.  
  35. // The total amount of money collected by this machine.
  36.  
  37. private int total;
  38.  
  39. /**
  40.  
  41. * Create a machine that issues tickets of the given price.
  42.  
  43. * Note that the price must be greater than zero, and there
  44.  
  45. * are no checks to ensure this.
  46.  
  47. */
  48.  
  49. public TicketMachine(int ticketCost)
  50.  
  51. {
  52.  
  53. price = ticketCost;
  54.  
  55. balance = 0;
  56.  
  57. total = 0;
  58.  
  59. }
  60.  
  61. public TicketMachine(){
  62.  
  63. //      String prisLest = JOptionPane.showInputDialog("Hvor mye koster billetten");
  64.  
  65. //      price = Integer.parseInt(prisLest);
  66.  
  67.  
  68.  
  69.        
  70.  
  71. }
  72.  
  73. /**
  74.  
  75. * Return the price of a ticket.
  76.  
  77. */
  78.  
  79. public int getPrice()
  80.  
  81. {
  82.  
  83. return price;
  84.  
  85. }
  86.  
  87. /**
  88.  
  89. * Return the amount of money already inserted for the
  90.  
  91. * next ticket.
  92.  
  93. */
  94.  
  95. public int getBalance()
  96.  
  97. {
  98.  
  99. return balance;
  100.  
  101. }
  102.  
  103.  
  104.  
  105. /**
  106.  
  107. * Receive an amount of money in cents from a customer.
  108.  
  109. */
  110.  
  111. public void insertMoney(int amount)
  112.  
  113. {
  114.  
  115. balance = balance + amount;
  116.  
  117. }
  118.  
  119. /**
  120.  
  121. * Print a ticket.
  122.  
  123. * Update the total collected and
  124.  
  125. * reduce the balance to zero.
  126.  
  127. */
  128.  
  129. public void printTicket()
  130.  
  131. {
  132.  
  133. // Simulate the printing of a ticket.
  134.  
  135. System.out.println("##################");
  136.  
  137. System.out.println("# The BlueJ Line");
  138.  
  139. System.out.println("# Ticket");
  140.  
  141. System.out.println("# " + price + " cents.");
  142.  
  143. System.out.println("##################");
  144.  
  145. System.out.println();
  146.  
  147. // Update the total collected with the balance.
  148.  
  149. total = total + balance;
  150.  
  151. // Clear the balance.
  152.  
  153. balance = 0;
  154.  
  155. }
  156.  
  157. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top