Soalan 2 a)
class time {
double secs, mins, hours;
time(){
secs=0; mins=0; hours=0;
}
public void showdata(){
System.out.Println(“Saat =” +secs);
System.out.Println(“Minit =” +mins);
System.out.Println(“Jam =” +hours);
}
Soalan 2 b)
class rectangle {
double height,length;
date(){
height=0; length=0;
}
public void showdata(){
System.out.Println(“Tinggi =” +height);
System.out.Println(“Panjang =” + length);
}
Soalan 3
class point {
int x,y;
point(){
x=0;y=0;
}
double area(){
return 0;
}
double distance(int x1 ,int y1, int x2, int y2) {
return Math.sqrt((x2-x1)*(x2-x1)-(y2-y1)*(y2-y1));
}
}
class circle extends point {
int radius;
double area() {
return (3.14 * (radius* radius));
}
}
UML diagram for the class Point and class Circle |
No comments:
Post a Comment