CSC186 FinalDec2019
CSC186 FinalDec2019
INSTRUCTIONS TO CANDIDATES
1. This question paper consists of two (2) parts : PART A (20 Questions)
PART B (4 Questions)
3. Do not bring any material into the examination room unless permission is given by the
invigilator.
PART A
2. A constructor is
4. The values of a pr1vate attribute is made accessible to outside client programs with
the use of
a) mutator method
b) accessor method
c) processor method
d) tostring method
6. Which of the following is the CORRECT parameter type and sequence for the Ca:C
constructor?
7. Composite object is
biskid.cost[0] = 19.90;
biskid.cost[1] = 20.00,
biskid.cost[2] = 10.50;
biskid.cost[3] = 9.20;
for (int i=l; i<3; i+
+)
sum = sum + biskid.cost[i];
System.out.print("Total cost: " +
sum);
a) Total cost: 19.90
b) Total cost: 30.50
C) Total cost: 39.70
d) Total cost: 59.60
Which is the CORRECT statement to calculate the sum of three (3) Fraction instances
f1, f2 and f3?
a) polymorphism
b) overloaded method
c) overriding method
d) interfaces
a) public person (int id, String name, int dd, int mm, int yy)
{this.id = id; this.name = name; this.dd = dd; this.mm =
mm, this.yy = yy;)
b) public person (int id, String name, int dd, int mm, int yy)
{super(dd,mm,yy); this.id = id, this.name = name;}
C) public person (int id, String name, int dd, int mm, int
yy){student = new Student(id, name); date = new Date(dd, mm,
d) public person (int id, String name, int dd, int mm, int
yy){super(id, name); Date(dd, mm, yy);l
cat;
a) Siamese
b) Persian
c) Himalayan
d) Cat
19. The following diagram is the inheritance structure for pub11cTEansport , ART and
T classes:
PublicTransport
MRT LRT
class Flower {
public Flower()
{
System.out.print1n("The default constructor of Flower
is invoked”)}
(40 MARKS)
PART B
QUESTION 1
//constructor
//mutator
//accessor
//toString()
Based on the above information, write the statement for the following tasks:
public Book(){
bookCode = null;
title = null;
price = 0;
author = null;
}
b) In class application, write the statements to display publisher’s name through the
fourth character of the bookCode (e.g BKC1147 is published by Course Pubs).
If (b.getBookCode().charAt(3) == ‘1’){
author = “Course Pubs”;}
(60 MARKS)
QUESTION 2
Sedap Bak Hang Catering Services offers attractive packages for the coming school
holidays as stated in a table below. In order to provide efficient service to customer,
the company decided to develop an ordering system that consists of 2 classes;
Order and Date .
i) Method ca1cPr1ce ( ) that will calculate and return the total price based on
the selected packages and number of customers. If the number of customers is
more than 1000, a 10% discount is deducted from the total price.
(3 marks)
ii) Method ca1cPr1ce double disc) that will calculate and return the total price
based on the selected packages, number of customers and discount given
during promotion period. Discount given depends on management decision.
return disc;
}
(2 marks)
return totalPrice1>totalPrice2; }
(2 marks)
SOP(“……………”);
……………………..
Calculate and display all information and the total prices charged, for each
objects during promotion period. A 15% discount given for all sales.
netPrice = order[i].calcPrice(disc);
SOP(“Order:” + order[i].toString());
SOP(“total sale:”) + netprice; }
(5 marks)
QUESTION 3
Sewa4U Online provides rental services for terrace houses and condominium units. The
company needs a system to handle its monthly rental collections from tenants. The
following class is used to represent a house for rent.
public House(.:..)( )
public Terrace(String tenant, String ICNo, String address, String type, boolean
cornerlotStat){
super(tenant, ICNo, address);
this.type = type;
this.cornerlotStat = cornerlotStat;
The class should also have a method to calculate and return the rent based on the
following table:
(6 marks)
iii) Count and display the information of tenants for double-storey corner lots.
Count++;}
SOP(t[i].toString());}
SOP(“total double-storey corner lots:” + count);
iv) Display the total rent the company should collect for the month.
v) Display the type of house rented by a tenant named “Ali bin Abu".
Cinta Sayang Tailoring offers custom-made men’s and women’s fashion such as baju
melayu, baju kurung, coats, blazer, jackets and many more. As for the first phase, the
ordering system focuses on baju melayu and baju kurung only. The following are
classes and inheritance hierarchy for its ordering system.
TailorOrder
BajuKurun BajuMelayu
g
Given is the definition for TailorOrder, BajuKurung and BajuMelayu
classes:
Return totPrice; }
(9 marks)
(2 marks)
ii) Calculate and display the number of customer orders for Baju Kurung with
embroidery.
If(bk.getEmbroidery(){
Count++; }
(4.5 marks)
If(order[i].getDelivery()){
addCharge = 5 + payment;
SOP(order[i].getOrderNum());