Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain what abstract classes and methods are and know when to use these in coding a Java application; Explain why Java implements only single inheritance;

Explain what abstract classes and methods are and know when to use these in coding a Java application;

Explain why Java implements only single inheritance;

Explain what an interface is and know how and when it should be used;

Background: The TicketSales.Com website sells tickets to a range of entertainment events. The following are some examples: A single-use ticket to attend a sporting match A multi-use ticket to attend some fixed number of matches by a single team throughout an entire season of the sport. A single-use ticket to gain entry to the Zoo, or to a Theme Park, or other tourist attraction. A multi-use ticket to watch sport games In this lab we will write a program to simulate the selling and usage of some tickets by the website. Read through all tasks before you begin, to get an idea of what is expected to be completed.

Task 1: Create Interface definitions Create a new package for this weeks activities called lab10. First we need to define some interfaces, which we will later implement. 1. Create an Interface named SingleUseTicketing. It will need to define the following methods: use( ) this method will be called to signify that the ticket is to be used. The method should return true if the ticket is valid for use, and false if it is not valid for use because of having already been used. The effect of the method should be to change the ticket from useable (i.e. valid), to being no longer valid in the future. 2. Create an interface named MultiUseTicketing. It will need to define the following methods: loadUp( amount ) this method will be called to add a specified amount of uses to the ticket (each is called a use-entitlement). For example if the parameter is 3, this means the ticket can be used 3 times more than it previously could. Thus if the ticket had been fully used-up, it would again be available to be used.

useOnce( ) this method will be called to signify that the ticket is to be used one more time. The method should return true if the ticket is valid for use, and false if it is not valid for use because of having expired, i.e. having been fully used-up. The effect of the method should be to decrease the number of uses that remain for the ticket. For example, if 3 uses had been loaded onto the ticket, then the first call to useOnce will reduce the number to 2. getLoadUpCost( amount ) returns the price required to increase the number of remaining uses of the ticket, for the number of uses specified.

Task 2: Create abstract class definition 3. Define an abstract class named Ticket. It should provide the following methods, possibly as abstract methods: getPurpose( ) returns a String describing the purpose for which the ticket may be used, e.g. to attend a sport match, to attend multiple sport matches, to enter the Zoo, etc. getCost( ) returns an amount signifying the cost of obtaining the ticket. Note that for single-use ticketing types, this is the same cost as obtaining the physical ticket; but for multi-use ticketing types, it is the cost of obtaining the physical ticket that can be used on multiple occasions and is separate from the cost of entry. isValid( ) returns a boolean value indicating if the ticket is valid for use, or not.

Task 3: Create other class definitions 4. Create a concrete subclass of Ticket named TouristTicket that implements the SingleUseTicketing interface. One attribute should be the name of the tourist attraction (e.g. Zoo, Water World, etc.) Another attribute should be the price of entry to the attraction These attributes should be set in the constructor, from parameters. Ensure that the object has a suitable initial state. Ensure that all required methods as specified by the interface or superclass are implemented (with bodies). 5. Create a concrete subclass of Ticket named SportSeasonTicket that implements the MultiUseTicketing interface. It will need to ensure that the following information is stored in attributes: The cost of the ticket itself, without any use-entitlements. The cost for each use-entitlement (each entry/admittance to a match), i.e. to load 4 admittances onto the ticket may cost $17 each when pre- purchased, whereas the base cost of the ticket itself may be just $5 and is charged just once for the whole year. How many times it may be used (the initial number of pre-paid admittances the person will be entitled to before needing to load more onto their smart ticket). Make sure that you implement the methods required by the MultiUseTicketing interface, so that you check how many uses remain and check the tickets validity.

Task 4: Write a driver class You may prefer to do this part gradually as you work through the other tasks. 6. Write a driver which creates objects of the concrete class types, and calls methods on the objects.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mysql Examples Explanations Explain Examples

Authors: Harry Baker ,Ray Yao

1st Edition

B0CQK9RN2J, 979-8872176237

More Books

Students also viewed these Databases questions

Question

=+8. Are there any disadvantages with this tactic?

Answered: 1 week ago