Question: SUBJECT : JAVA OOP QUESTION 2 (30 MARKS) Given the following super class and subclasses: public abstract class Theme Park { String name; // customer's
SUBJECT : JAVA OOP


QUESTION 2 (30 MARKS) Given the following super class and subclasses: public abstract class Theme Park { String name; // customer's name String icNo; // customer's identification card number boolean member; // either member or nonmember of the // theme park //Methods: //default and normal constructor / /accessors //toString() public abstract double calCharges();//calculate the charges } public class Water Park extends Theme Park { String activity; // surfBeach, waterRide or other //Methods: //default and normal constructor //accessors //toString() public double calCharges() {...} public class WildlifePark extends Theme Park { String category; // child or adult boolean isTrain; //use train or not //Methods: //default and normal constructor //accessors //toString() public double calCharges() {-} } a) Write the following method definition: i) Normal constructor for both subclasses. (6 marks) ii) Processor method named calCharges () based on the abstract method in superclass to calculate the charges of the activities for both Waterpark and Wildlife Park classes for a single ticket. Customers who are members of the Theme Park will be given a special discount of 25% for every ticket charge. The details of ticket charges are given in Table 5.1 and Table 5.2: Table 5.1 Details of ticket charges for Water Park Activity Cost (RM) Surf Beach 40.00 Water Rides 30.00 Other 15.00 Table 5.2 Details of ticket charges for Wildlife Park Category Cost (RM) Adult 35.00 Child 20.00 An extra RM5 will be charged if the customer uses the train for Wildlife Park (9 marks) b) Write code fragments in the application / driver class that can perform the following tasks: (Assume all relevant methods have been defined in all classes involved) i) Declare an array of object named tp to store various types of theme park where the size of array is entered by the user. (2 marks) ii) Assuming data has been stored in this to array; calculate and display the total charges of every WaterPark and Wildlife Park ticket respectively. (5 marks) ii) Print the list of adult customers in the wildlife park and the total number of adults, followed by the list of child customers in the wildlife park and the total number of children. (8 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
