Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ExampleStuff;
- import java.text.NumberFormat;
- public class AbstractTheaters {
- public static void main(String[] args) {
- runExample();
- }
- private static void runExample() {
- System.out.println("runExample()");
- Regular reg1 = new Regular();
- reg1.describe();
- reg1.seats(70);
- reg1.price(8.0);
- reg1.lbreak();
- IMAX imax1 = new IMAX();
- imax1.describe();
- imax1.seats(120);
- imax1.price(15.0);
- imax1.lbreak();
- Luxury lux1 = new Luxury();
- lux1.describe();
- lux1.seats(40);
- lux1.price(12.5);
- lux1.lbreak();
- }
- }
- abstract class Theater {
- int j, k;
- void seats(int seats) {
- if (seats < 70)
- System.out.println("Contains " + seats + " reclining seats");
- else
- System.out.println("Contains " + seats + " seats.");
- }
- void price(double price) {
- NumberFormat $ = NumberFormat.getCurrencyInstance();
- System.out.println("Ticket price: " + $.format(price));
- }
- void lbreak() {
- System.out.println("-------------------------------");
- }
- abstract void describe();
- }
- class Regular extends Theater {
- void describe() {
- System.out.println("Regular theater room.");
- }
- }
- class IMAX extends Theater {
- void describe() {
- System.out.println("IMAX theater room.");
- }
- }
- class Luxury extends Theater {
- void describe() {
- System.out.println("Luxury theater room.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement