Advertisement
Guest User

Abstract theater class

a guest
Nov 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. package ExampleStuff;
  2.  
  3. import java.text.NumberFormat;
  4.  
  5. public class AbstractTheaters {
  6.  
  7.     public static void main(String[] args) {
  8.         runExample();
  9.     }
  10.     private static void runExample() {
  11.         System.out.println("runExample()");
  12.        
  13.         Regular reg1 = new Regular();
  14.         reg1.describe();
  15.         reg1.seats(70);
  16.         reg1.price(8.0);
  17.         reg1.lbreak();
  18.        
  19.         IMAX imax1 = new IMAX();
  20.         imax1.describe();
  21.         imax1.seats(120);
  22.         imax1.price(15.0);
  23.         imax1.lbreak();
  24.        
  25.         Luxury lux1 = new Luxury();
  26.         lux1.describe();
  27.         lux1.seats(40);
  28.         lux1.price(12.5);
  29.         lux1.lbreak();
  30.     }
  31. }
  32.  
  33. abstract class Theater {
  34.     int j, k;
  35.     void seats(int seats) {
  36.         if (seats < 70)
  37.             System.out.println("Contains " + seats + " reclining seats");
  38.         else
  39.             System.out.println("Contains " + seats + " seats.");
  40.     }
  41.    
  42.     void price(double price) {
  43.         NumberFormat $ = NumberFormat.getCurrencyInstance();
  44.         System.out.println("Ticket price: " + $.format(price));
  45.     }
  46.    
  47.     void lbreak() {
  48.         System.out.println("-------------------------------");
  49.     }
  50.    
  51.     abstract void describe();
  52. }
  53.  
  54. class Regular extends Theater {
  55.     void describe() {
  56.         System.out.println("Regular theater room.");
  57.     }
  58.    
  59. }
  60.  
  61. class IMAX extends Theater {
  62.     void describe() {
  63.         System.out.println("IMAX theater room.");
  64.     }
  65.  
  66. }
  67.  
  68. class Luxury extends Theater {
  69.     void describe() {
  70.         System.out.println("Luxury theater room.");
  71.     }
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement