Thursday, December 27, 2012
Tuesday, December 4, 2012
CSC438 - DATA STRUCTURE - LAB BINARY TREE
package LAB_9_TREE;
class BinaryTreeNode {
int data;
BinaryTreeNode right;
BinaryTreeNode left;
BinaryTreeNode(int a)
{
this.data = a;
}
}
public class BinaryTree {
protected BinaryTreeNode root;
// DEFAULT CONSTRUCTOR
public BinaryTree()
{
root = null;
}
// DESTROY THE BINARY TREE
public void destroyTree ()
{
root = null;
}
//DETERMINE WHETER THE BINARY TREE IS EMPTY
public boolean isEmpty()
{
return ( root == null );
}
// DETERMINE THE HEIGHT OF THE BINARY TREE
public int treeHeight()
{
return height(root);
}
// A RECURSIVE FUNCTION TO GET THE HEIGHT OF THE BINARY TREE
public int height( BinaryTreeNode p )
{
if ( p == null )
return 0;
else
return 1 + max(height(p.left),height(p.right) );
}
// COMPARE THE TWO VALUE FROM THE LEFT AND THE RIGHT NODE
public int max( int x,int y)
{
if ( x >= y )
return x;
else
return y;
}
//INSERT A NEW NODE INTO THE BINARY TREE
public void insertNode(int item)
{
BinaryTreeNode current;
BinaryTreeNode trailCurrent = null;
BinaryTreeNode newNode;
newNode = new BinaryTreeNode(0);
newNode.data = item;
newNode.left = null;
newNode.right = null;
if(root == null)
root = newNode;
else
{
current = root;
while(current != null)
{
trailCurrent = current;
if(current.data == item)
{
System.err.print("The insert item is already in the list. Duplicate item are not allowed");
return;
}
else
if(current.data < item)
current = current.left;
else
current = current.right;
}
if(trailCurrent.data < item)
trailCurrent.left = newNode;
else
trailCurrent.right = newNode;
}
}
}
============================================================
package LAB_9_TREE;
import javax.swing.*;
public class TestBinaryTree
{
public static void main(String[] args)
{
BinaryTree tree = new BinaryTree();
int value;
System.out.println("Inserting the following values : ");
for ( int i = 0; i < 10 ; i++)
{
value = (int) (Math.random()*100);
System.out.print(value + " ");
tree.insertNode(value);
}
}
}
/*
The output :
Inserting the following values :
45 60 63 72 67 20 1 28 99 30
*/
prefix and postfix the easy ways
Find the prefix and postfix notation for the
following infix expression:
|
|
|
|
(a + b – c) * (e / f) – ( g – h/i)
There is a quick way to
convert from one notation to another. You start by inserting all the implicit brackets/parentheses
that determine the order of evaluation, regardless of what notation the
expression is already in. So, taking the expression above and adding these
implicit brackets gives:
Now, in order to
convert from one notation to another using the bracketed form, you would move
the operator in each bracketed expression. Where you move the operator
depends on the notation that you want to convert to.
|
Postfix vs. Prefix Notation
If you want to convert to
postfix notation, you would move the operator to the end of the bracketed
expression, right before the closing brace. To convert to prefix notation, you
would move the operator to the beginning of the bracketed expression, right after
the opening brace. So, (h/i) in postfix notation would look like (h i /), and
in prefix notation would look like (/ h i ). Do this for every operator in a
bracket. So, converting the expression above to prefix notation will give you:
Moving all the operators to the beginning of the
bracketed expression for prefix notation gives us:
( - ( * ( - ( + a b) c) ( / e f)) ( - g ( / h i ) ) )
|
And finally, removing all the
parentheses gives us our final prefix notation:
- * - + a b c / e f - g / h i
|
Try figuring out how to get
the postfix notation on your own using the rules given above. You should get
this as your answer:
a b + c - e f / * g h i / - -
|
Thursday, October 18, 2012
Hari Raya Aidiladha dan Qurban.
Sempena Hari Raya Qurban 2012 kami sekeluarga sepakat untuk membuat qurban 2 bhg lembu sempena hari yang mulia ini.
Dizaman yang maju ini, mudah aje skrg nak buat qurban. bayar online sahaja dan buat akad untuk dilaksanakan qurban di kawasan yang amat memerlukan bantuan lebih lebih lagi saudara seislam di luar negara disana.
Harga Untuk satu bhg lembu hanyalah RM230 dan qurban hanya boleh dibuat pada Hari Raya Aidiladha dan Hari Tasyrik iaitu 11, 12 dan 13 Zulhijjah dengan tujuan untuk beribadah atau menghampirkan diri kepada Allah SWT.
sama samalah kita membudgetkan diri sekali setahun untuk perkara yang sangat sangat dituntut bagi umat islam.
untuk tempahan boleh lah ke laman web eQurban.com disini
FAQ
Soalan 1 :
Apakah yang dimaksudkan dengan Korban?
Soalan 2 :
Apakah hukum melaksanakan ibadah korban?
Soalan 3 :
Apakah binatang yang disyariatkan untuk korban?
Soalan 4 :
Berapakah bilangan minimum haiwan yang digalakkan untuk ibadah korban?
Soalan 5 :
Saya telah melaksanakan ibadah korban sebelum ini, bolehkah saya melaksanakannya lagi?
Soalan 6 :
Jika saya menyertai program ibadah korban ini dengan pihak eQurban, apakah bukti yang menunjukkan ibadah korban tersebut telah dilaksanakan.
Soalan 7 :
Apakah kelebihan menyertai ibadah korban dengan pihak eQurban?
Apakah yang dimaksudkan dengan Korban?
Korban bermaksud hampir. Dari segi istilah bermaksud menyembelih binatang tertentu pada Hari Raya Aidiladha dan Hari Tasyrik iaitu 11, 12 dan 13 Zulhijjah dengan tujuan untuk beribadah atau menghampirkan diri kepada Allah SWT.
Soalan 2 :
Apakah hukum melaksanakan ibadah korban?
Hukum korban ialah Sunat Muakkad (ibadah sunat yang sangat-sangat dituntut ke atas umat Islam yang berkemampuan. Namun begitu ia dihukumkan wajib apabila seseorang itu bernazar.
Soalan 3 :
Apakah binatang yang disyariatkan untuk korban?
Binatang yang hendak dikorbankan mestilah mempunyai ciri-ciri tidak cacat, tidak sakit, tidak buta, tidak berkurap dan tidak kurus. Binatang yang sah untuk dikorbankan adalah seperti berikut :
- Kambing biri-biri – berusia satu tahun dan ke atas.
- Kambing biasa - berusia dua tahun dan ke atas.
- Unta – berusia lima tahun dan ke atas.
- Lembu atau kerbau – berusia dua tahun dan ke atas.
Soalan 4 :
Berapakah bilangan minimum haiwan yang digalakkan untuk ibadah korban?
Bagi haiwan seperti lembu, kerbau atau untuk bilangan minimum untuk ibadah korban adalah 1 bahagian. Manakala kambing bilangan minimum adalah satu ekor.
Soalan 5 :
Saya telah melaksanakan ibadah korban sebelum ini, bolehkah saya melaksanakannya lagi?
Boleh, ibadah korban boleh dilaksanakan seberapa banyak sekiranya berkemampuan.
Soalan 6 :
Jika saya menyertai program ibadah korban ini dengan pihak eQurban, apakah bukti yang menunjukkan ibadah korban tersebut telah dilaksanakan.
Pihak eQurban akan mengeluarkan sijil aku janji sebagai wakil melaksanakan ibadah korban tersebut kepada semua peserta dan menghantar gambar-gambar berkaitan yang menunjukkan ibadah tersebut telah dilaksanakan.
Soalan 7 :
Apakah kelebihan menyertai ibadah korban dengan pihak eQurban?
Kami menternak sendiri lembu-lembu untuk Korban ini di ladang kami di Stungstreng, Kemboja dengan usahasama Koperasi Muslim Kemboja. Bekalan lembu ini cukup untuk bekalan Qurban dan Aqiqah sepanjag tahun
Tuesday, August 28, 2012
Selamat Hari Raya Aidilfitri
"Selamat Hari Raya untuk semua rakan rakan
dan
semua umat manusia seantero dunia...
dan
semua umat manusia seantero dunia...
Dari Kami Seisi Keluarga....
Jemput Datang Ke Rumah pada sepanjang Syawal tahun ini ke Syawal tahun depan...
terutama pada Hari Sabtu,1 September 2012
terutama pada Hari Sabtu,1 September 2012
Di Alamat :
No 3, Jalan Meranti 9C/KU 10,
Taman Desa Permai,
Meru Klang
Thursday, August 16, 2012
coldfusion tutorial
for those who want to learn coldfusion... alot of site is available for your reference...
i found that this 2 site is very useful and got a lot of stuff you can learn as a beginner or intermediate level cf programmer...
- Adobe Coldfusion i usually refer to this site... coz it compile alot of site with great resources for cf10...
http://www.akbarsait.com/cf10tutorials.cfm - Adobe Coldfusion or this site...
http://learncf.com/tutorials
Friday, August 3, 2012
Coldfusion Hosting
I Love Coldfusion.
It is simple, easy and user friendly.
i mean whut more you want if you want to develop a web base application.
check this out, a promotion from http://www.efree2net.com/free-domain-hosting.cfm
it's comes with a 20 GB space and bla bla as usual features.
and it also give you a free domain name just for US 25.
now i have my own coldfusion 9 hosting.
Result Exam Sem 20122
Syukur Alhamdulillah, result aku untuk semester ini kira cemerlang jugak la.. dpt AD keseluruhannya.
kiranya taktik aku dengan mengambil kursus yang senang senang aje pada semester ini berbaloi la rasanya. harap harap semester depan dpt macam nie kan bagus, tapi yang penting usaha, dan teknik belajar. smart study la kata org jerman.
Thursday, August 2, 2012
Monday, July 23, 2012
Batman VS ‘The Joker’ dalam The Dark Knight Rises
Aku dah tgk dan crita batman yang baru tu... kira kira memang best jugak la, takde la kartun sgt macam masa zaman val kilmer dan george clooney tu. ada la realitinya kalau nak jadi superhero ikut masa sekarang nie.
Sempena tayangan filem Batman-The Dark Knight Rises yang baru nie, satu kejadian tembakan telah berlaku di sebuat panggung wayang di Denver ( bukan di gotham sebab kat sana ada batman original ). ikut ceritanya, banyak jugak penonton yang pakai costume Batman, tapi tidak sempat buat apa apa, sebab "The Joker" telah bertindak lebih pantas.
banyak motif tembakan ini dilakukan, dan mengikut sumber yang tidak boleh dipercayai adalah disebabkan tiada lagi character "the joker" dalam The Dark Knight Rises dan ini mengakibatkan kebosanan tahap gaban peminat dengan villain villain yang dipaparkan dalam filem yang baru ini.
nasib la ini adalah final installment dari trilogi batman ini, jika tidak anda perlu pakai baju kalis peluru untuk menonton wayang nanti, hanya di US, bukan di Gotham City.
James Holmes ikut manifesto serangan Anders Behring Breivik
AURORA: Pembunuh 12 penonton di sebuah panggung wayang Denver dan menggelar dirinya ‘The Joker’ dilaporkan mengikut nasihat penyerang Norway, Anders Behring Breivik, apabila melakukan serangan ketika tayangan filem Batman: The Dark Knight Rises di sini, Jumaat lalu. James Holmes mengikut manifesto Breivik menyarankan penggunaan raifal, senapang patah, bom asap, senapang AR15 yang mampu melepaskan 100 kali tembakan, senapang Remington dan dua pistol Glock.
Holmes juga mengikut apa yang disuruh Breivik dengan memakai pelindung leher, badan dan topeng gas mengikut manifesto 1,500 muka surat itu.
Malah, Holmes, 24, menjadi ahli sebuah laman web dewasa mengikut cadangan Breivik supaya kerap melakukan hubungan seks sebelum serangan.
Pasang bom di rumah
Baca Seterusnya disini...
Peringatan Mesra - Potensi lebih 'boroi'
Nampaknya proses pemboroian telah bermula dengan adanya promosi dan diskaun untuk buffet ramadhan yang menyelerakan. aku pun macam dah tergoda nie dan dah berkira nak pi buffet mana la tahun nie... paling kurang at least sekali la kan, bukan selalu pun.
hajat di hati nak dpt pinggang saiz 33 or 32 masa syawal nanti, akibat ketidak serasian seluar dengan saiz 35++ yang amat ketara. apa nak buat potensi boroi ini di sumbangkan oleh McD dan KFc dan nasi kukus kak nora seksyen 7 tu laaa... dah la sedap, boleh dpt hari hari plak tu...
ingatan untuk semua, jauhi boroi untuk hidup bahagia, katakan tidak pada makan berlebihan.
credit to utusan malaysia
hajat di hati nak dpt pinggang saiz 33 or 32 masa syawal nanti, akibat ketidak serasian seluar dengan saiz 35++ yang amat ketara. apa nak buat potensi boroi ini di sumbangkan oleh McD dan KFc dan nasi kukus kak nora seksyen 7 tu laaa... dah la sedap, boleh dpt hari hari plak tu...
Potensi lebih 'boroi'
KUALA LUMPUR 22 Julai - Bagi sesetengah individu, kedatangan Ramadan dianggap sebagai peluang terbaik untuk menguruskan badan, sesuai dengan sifat amalan tersebut yang memerlukan umat Islam menahan lapar dan dahaga di siang hari.
Namun jangan terkejut sekiranya impian itu gagal dicapai sebaliknya perut anda kian 'menonjol' ketika syawal menjelma ekoran kegagalan menahan nafsu sewaktu berbuka puasa.
Menurut Pakar Pemakanan Hospital Pakar Ampang Pantai Puteri, Rose Hanizan Mat Hassan perkara itu tidak mustahil berlaku kerana pengambilan makanan secara berlebihan dan mengejut ketika perut kosong menyebabkan anggota badan itu cepat mengembang.
"Secara tidak langsung, ia menyebabkan perut seseorang ittu menjadi buncit. Justeru, umat Islam tidak sepatutnya makan seolah-olah 'melepas geram' ketika berbuka puasa," katanya.
Sunday, July 22, 2012
SELAMAT MENYAMBUT BULAN RAMADHAN AL-MUBARAK
SELAMAT MENYAMBUT BULAN RAMADHAN AL-MUBARAK..
Semoga kita dapat menjalani ibadah puasa dengan khusyuk, diberkati dan dirahmati Allah S.W.T, insyaallah
Friday, July 20, 2012
Wednesday, July 11, 2012
CSC435 - PAST EXAM QUESTION AND ANSWER
this is the past year question and the answer. have fun!
QUESTION 5 (APRIL 2008)
Given the following program
segment:
public class Land
{ protected String owner;
protected double area;
abstract double calcTax();
abstract void display();
public Land( String own, double
area)
{
//method definition
}
}
public class Housing extends Land
{
private char houseType;
private double tax_rate;
public Housing(String
own,double area,char Hsetype)
{
//method definition
}
public double calcTax()
{
//method definition
}
public void display()
{
//method definition
}
}
public class Agriculture extends Land
{
private double fixed_tax_rate =
3.00;
public Agriculture(String
own,double area)
{
//method definition
}
public double calcTax()
{
//method definition
}
public void display()
{
//method definition
} }
a) Define the method calcTax()of class Housing based on the
following:
The tax for this type
of land depends on its area and the type of house built on the land:
House Type
|
Description
|
Tax Rate (RM/m2)
|
T
|
Terrace
|
10
|
S
|
Semi-Detached
|
15
|
B
|
Bungalow
|
20
|
C
|
Condominium
|
5
|
(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)
b)
Write an application program that uses the concept of
polymorphism to
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.
ii. Display the total Tax for all lands.
iii. Display the Tax amount
for Housing lands only.
iv. Determine and display the highest tax for
Agriculture land.
(12
marks)
APRIL 2008
a)
Answer:
public double calcTax()
{
double tax=0.0;
->0.5 mark
if (houseType == 'T')
{
tax_rate = 5;
tax = area * tax_rate;
} ->0.5 mark
else if (houseType == 'S')
{
tax_rate = 10;
tax = area * tax_rate;
} -> 0.5 mark
else if (houseType == 'B')
{
tax_rate = 15;
tax = area * tax_rate;
} ->0.5 mark
else if (houseType == 'C')
{
tax_rate = 20;
tax = area * tax_rate;
}
-> 0.5 mark
return tax;
-> 0.5 mark
}note : 1 mark if program
correct
b) Answer:
private double fixed_tax_rate = 3.00;
->0.5 mark
public double calcTax()
{
double tax = fixed_tax_rate * area; -> 1 mark
return tax; -> 0.5 mark }
c) Answer:
public class TestLand
{
static Scanner console = new
Scanner(System.in);
public static void main(String[] args)
{
String
owner,type;
double
area;
char
hsetype;
double
taxRate;
char
input = 'Y';
int
count =0;
Land[]
L = new Land[20];
while(input != 'N')
{
System.out.print("Enter the land owner
: ");
owner = console.next();
System.out.print("\nEnter the land area
: ");
area
= console.nextDouble();
System.out.print("Enter the land type:
H-Housing,A-
Agriculture ");
type = console.next();
switch(type.charAt(0))
{
case 'H' : System.out.println("Enter house type :
");
hsetype =
console.next().charAt(0);
//taxRate =
console.nextDouble();
L[count] = new
Housing(owner,area,hsetype);
break;
case 'A' : L[count] = new Agriculture(owner,area);
break;
default : System.out.println( "Wrong land
type");
}
count++;
System.out.println("Do you want to
continue ?(Y or N) : ");
input = console.next().charAt(0);
}
System.out.println("length
="+L.length);
for(int k=0; k<count;k++)
{
L[k].Display();
}
System.out.println("Count
="+count);
double totalTax=0.0;
for(int k=0; k<count;k++)
{
totalTax = totalTax + L[k].calcTax();
}
System.out.println("Total tax =
"+totalTax);
for (int k=0; k < count; k++)
{
if (L[k] instanceof
Housing)
{
System.out.print("Tax amount for
Housing land = ");
System.out.println(L[k].calcTax());
}
}
double highest = 0.0;
for (int k=0; k <
count; k++)
{
if (L[k] instanceof
Agriculture)
if (L[k].calcTax()
> highest)
highest =
L[k].calcTax();
}
System.out.println("Highest
tax for agriculture land = "+highest);
}
QUESTION 3 (APRIL
2009)
Given
the following inheritance hierarchy
And
the definition for the BankAccount
class:
abstract class BankAccount
{
private
String name;
private
long accNum;
private
double balance;
public BankAccount() {}
public BankAccount(String name, long accNum, double balance)
{ //method definition}
public
String getName()
{ //method definition }
public long
getAcc()
{ //method definition }
public double
getBalance()
{ //method definition }
public String
toString()
{ //method definition }
//method to update
the balance for the account
public abstract
double updateBalance();
}
a) Define the Saving class
that inherits from the BankAccount class. The attributes and methods are as
follows:
Attributes: interest rate
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:
Attributes: interest rate and transaction
fee
Methods:
·
Constructor
with arguments
·
toString(),
to return the string
representation of the object
·
updateBalance(),
given the formulae:
update = (interest rate X balance) + balance
– transaction fee;
(10 marks)
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)
APRIL 2009
a)
public
class Saving extends BankAccount
{
private
double rate;
public Saving(String name, long accNum,
double balance,
double rate)
{
super(name, accNum, balance);
this.rate = rate;
}
public String toString()
{
return
super.toString() + " Interest rate: " + rate;
}
public double updateBalance()
{
double
update = (rate * super.getBalance()) +
super.getBalance();
return update;
}
}
b) public
class Current extends BankAccount
{
private double rate;
private double fee;
public Current(String name, long accNum,
double balance,
double
rate, double fee)
{
super(name, accNum, balance);
this.rate = rate;
this.fee = fee;
}
public
String toString()
{ return super.toString() + " Interest
rate: " + rate + " Fee:"
+ fee;
}
public double updateBalance()
{
double update = (rate *
super.getBalance()) +
super.getBalance() - fee;
return update;
}
}
c)
import javax.swing.*;
public
class BankApp
{
public static void main(String args[])
{
int n =
Integer.parseInt(JOptionPane.showInputDialog(" Number
of
customers: "));
BankAccount[]
acct = new BankAccount[n];
for(int i = 0; i < acct.length; i++)
{
String
nm = JOptionPane.showInputDialog("Customer's Name: ");
long
accNo = Long.parseLong(JOptionPane.showInputDialog
("
Account #: "));
double
bal = Double.parseDouble(JOptionPane.showInputDialog
("
Balance: "));
String type =
JOptionPane.showInputDialog("Type - (S)aving/"
+ "(C)hecking ");
char
accType = type.toUpperCase().charAt(0);
if (accType == 'S')
{
double rt =
Double.parseDouble(JOptionPane.showInputDialog
("
Interest rate: "));
acct[i] = new Saving(nm, accNo, bal,
rt);
}
if (accType == 'C')
{
double irate = Double.parseDouble
(JOptionPane.showInputDialog (" Interest
rate: "));
double tfee =
Double.parseDouble(JOptionPane.showInputDialog
(" Transaction fee: "));
acct[i] = new Current(nm, accNo, bal,
irate, tfee);
}
}
for (int i = 0; i < acct.length; i++)
{
System.out.println(" The details
of customers : " +
acct[i].toString());
if (acct[i].updateBalance() > 100000)
System.out.println(" The customers
with balance > 100000:"
+
acct[i].toString());
}
double saveBalance = 0, currBalance = 0;
for(int i = 0; i < acct.length; i++)
{
if(acct[i] instanceof Saving)
saveBalance +=
acct[i].updateBalance();
if(acct[i] instanceof Current)
currBalance +=
acct[i].updateBalance();
}
System.out.println(" Total Balance
for Saving account: " +
saveBalance);
System.out.println(" Total Balance
for Current account: " +
currBalance);
}
}
QUESTION 3 (NOV
2009)
Given
the following definition
public abstract class Student
{
private String name;
private double test1;
private double test2;
private double test3;
protected char grade;
public
Student(String n, double tl, double t2, double t3)
{ . . . }
public abstract char
computeGrade();
// 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 3 (Nov 2009)
import javax.swing.*;
public class StudentApp
{
public static void main(String args[])
{
int n =
Integer.parseInt(JOptionPane.showInputDialog
("
Number of Students: "));
Student[] stu = new Student[n];
int under = grad = 0;
for(int
i = 0; i < acct.length; i++)
{
String nm =
JOptionPane.showInputDialog("Student's Name: ");
double t1 =
Double.parseDouble(JOptionPane.showInputDialog
("
Test 1: "));
double t2 =
Double.parseDouble(JOptionPane.showInputDialog
("
Test 2: "));
double t3 =
Double.parseDouble(JOptionPane.showInputDialog
("
Test 3: "));
String type = JOptionPane.showInputDialog
("Type
- (U)ndergraduate/" + "(G)raduate ");
char stuType = type.toUpperCase().charAt(0);
if
(stuType == 'U')
{
stu[i] = new Undergraduate(nm, t1, t2, t3);
}
if
(stuType == 'G')
{
stu[i] = new Undergraduate(nm, t1, t2, t3);
} }
for (int i = 0; i <
stu.length; i++)
{
if( stu[i].getGrade() == ‘A’)
{
if(stu[i] instanceof Undergraduate)
under++;
if(stu[i] instanceof Graduate)
grad++;
}
}
System.out.println(" Total A student
from Undergraduate: " +
under);
System.out.println(" Total A student
from Graduate: " + grad);
String input = JOptionPane.showInputDialog
("Search
Student's Name: ");
for (int i = 0; i < stu.length; i++)
{
if(input.equalsIgnoreCase(stu[i].getName())
System.out.println(“Found
“ + stu[i].toString());
} } }
QUESTION 4 (NOV
2009)
Given
the following inheritance hierarchy
and the list of
data members and methods for ThemePark, WaterPark, and WildlifePark classes:
Superclass : abstract class
ThemePark
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
Subclass
:
class
WaterPark
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
Subclass
:
class
WildlifePark
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)
QUESTION 4 (Nov 2009)
a)
public ThemePark(String name, String ic,
boolean member)
{
this.name = name;
this.icNo = ic;
this.member = member;
}
public
WaterPark(String name, String ic, boolean member, boolean surf,
boolean ride)
{
super(name, ic, member);
this.surfBeach = surf;
this.waterRides = ride;
}
public
WildlifePark(String name, String ic, boolean member,
String
category)
{
super(name, ic, member);
this.category = category;
}
b)
public double calCharges() // waterpark
{
double total = 0;
if( getSurf() == true)
total = total + 25;
if(getRide == true)
total = total + 20;
if(getMember() == true)
total = total – (total * 0.25);
return total;
}
public double calCharges() // wildlifepark
{
double total = 0;
if( getCategory().equalsIgnoreCase(“Adult”))
total = total + 35;
else if(getCategory().equalsIgnoreCase(“Child”))
total = total + 20.00;
if(getMember() == true)
total = total – (total * 0.25);
return total;
}
Subscribe to:
Posts (Atom)