Chain of Responsibility: Passing the Buck
Meet Mike the Scalper
Please examine the
If you prefer, you may download and browse the code using an IDE instead:
scoreTicket(...)
method below to see how Mike the Scalper goes about his work.
If Mike the Scalper has a
ticket
in stock for the requested concert, he
- removes it from his inventory
- adds his customary markup fee
- delivers the ticket:
public class Scalper extends TicketHolder { public Ticket scoreTicket(String concert) {
Ticket ticket;
if (inStock(concert))
ticket = removeFromInventory(concert);
else
ticket = connection.scoreTicket(concert);
ticket.markup(20.00);
return ticket;
}
}
Chain of Responsibility Scalper ExampleJava Compatibility Note: These exercises are tested
with JDK 17, a long-term support version released in 2021.
While many exercises work with earlier Java versions, some
may require JDK 17 due to library dependencies. If you
encounter issues, please use JDK 17. Should problems persist,
contact us for support.
(Reading...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |