Professional Documents
Culture Documents
FY (InheritanceAndPoly)
FY (InheritanceAndPoly)
The tax for this type of land depends on its area and the type of house built on the land:
(4 marks)
b) Define method calcTax()of class Agriculture. Agricultural lands are all charged a
fixed rate of RM 3 per meter square (m2).
(2 marks)
i. store data on various types of land. The number of data to be stored and
information on each land are given by the user. The input process stops when
the users key-in a sentinel value.
iv. Determine and display the highest tax for Agriculture land.
(12 marks)
BankAccount
Saving Current
public BankAccount() {}
public BankAccount(String name, long accNum, double balance)
{ //method definition}
a) Define the Saving class that inherits from the BankAccount class. The attributes and
methods are as follows:
Methods:
Constructor with arguments
toString(), to return the string representation of the object
updateBalance(), given the formulae:
update = (interest rate X balance) + balance;
(10 marks)
b) Define the Current class that inherits from the BankAccount class. The attributes and
methods are as follows:
c) Write a Java application class called BankApp that uses the concept of polymorphism to
perform the following tasks:
Declare an array of objects to store data on various types of BankAccount.
Display the details for all bank customers.
Display the details of customer whose balance exceeding RM 100,000
Calculate and display the total balance of all Saving accounts and total balance of
all Current accounts.
.(15 marks)
QUESTION 3 (NOV 2009)
// Accessors
public String getName() {...}
public double getTest1() {...}
public double getTest2() {...}
public double getTest3() {...}
public char getGrade (){...}
public String toString (){...}
}
Suppose Undergraduate and Graduate extends Students, with no additional attributes. Using
polymorphism, write a Java application to
a. get the number of students and necessary data from the user. Store these data into an
array of students
(10 mark)
b. calculate and display the total number of students who get grade A and count how many of
these students from each subclass, Undergraduate and Graduate.
(6 mark)
c. Find and display the information of student whose name is given by the user
(4 mark)
QUESTION 4 (NOV 2009)
ThemePark
WaterPark WildlifePark
and the list of data members and methods for ThemePark, WaterPark, and WildlifePark classes:
Data member(s):
String name; // customer's name
String icNo; // customer's identification card number
boolean member; // either member or not member of the park
Methods:
ThemePark();
ThemePark(String name, String icNo, boolean member);
String getName(); // return the customer's name
String getlc(); // return the ic number
boolean getMember(); // return the membership
String toString(); // return the details of objects
abstract double calCharges(); // calculate the charges
Data member(s):
boolean surfBeach; // either true or false to surf
boolean waterRides; // either true or false to ride
Methods:
boolean getSurf();// return the surfing status
boolean getRide();// return the riding status
double calCharges();// calculate the charges
String toString();// return the details of objects
Data member(s):
String category; // category of the customers
Methods:
String getCategory();// return the category
double calCharges();// calculate the charges
a) Write the normal constructors for superclass and both subclasses.
(6 marks)
b) Given the details of ticket charges in table 5.1 and table 5.2 for both Water and Wildlife
Parks below:
Activity Cost(RM)
Surf Beach 25.00
Water Rides 20.00
Table 5.1 Details of ticket charges for Water Park
Category Cost(RM)
Adult 35.00
Child 20.00
Table 5.2 Details of ticket charges for Wildlife Park
Write abstract methods named calcharges() to calculate the charges of the activities for both
WaterPark and WildlifePark classes. The customers who are the members of the theme
park will be given a special discount of 25% for every total charges.
(9 marks)