MyMain
public class MyMain
{
public static void main()
{
circle acircle; // creating reference
acircle = new circle(); // creating object
acircle.x = 10; // assigning value to data field
acircle.y = 20;
acircle.r = 5;
double area = acircle.area(); // invoking method
double circumf = acircle.circumference();
System.out.println("--Circle--");
System.out.println("Radius="+acircle.r+"Area="+area);
System.out.println("Radius="+acircle.r+" Circumference ="+circumf);
square asquare; // creating reference
asquare = new square(); // creating object
asquare.s = 20; // assigning value to data field
double luas = asquare.area(); // invoking method
double keliling = asquare.circumference();
System.out.println("--Square--");
System.out.println("Sisi="+asquare.s+"Area="+luas);
System.out.println("Sisi="+asquare.s+" Circumference ="+keliling);
rectangle arectangle; // creating reference
arectangle = new rectangle(); // creating object
arectangle.p = 20; // assigning value to data field
arectangle.l = 10;
double Luas = arectangle.area(); // invoking method
double Keliling = arectangle.circumference();
System.out.println("--Rectangle--");
System.out.println("Area="+luas);
System.out.println("Circumference ="+keliling);
triangle atriangle; // creating reference
atriangle = new triangle(); // creating object
atriangle.a = 20; // assigning value to data field
atriangle.b = 20;
atriangle.c = 20;
double Area = atriangle.area(); // invoking method
double Circumference = atriangle.circumference();
System.out.println("--Triangle--");
System.out.println("Area="+Area);
System.out.println("Circumference ="+Circumference);
belahketupat abelahketupat; // creating reference
abelahketupat = new belahketupat(); // creating object
abelahketupat.d1 = 20; // assigning value to data field
abelahketupat.d2 = 20;
Area = abelahketupat.area(); // invoking method
Circumference = abelahketupat.circumference();
System.out.println("--Belah Ketupat--");
System.out.println("Area="+Area);
System.out.println("Circumference ="+Circumference);
jajargenjang ajajargenjang; // creating reference
ajajargenjang = new jajargenjang(); // creating object
ajajargenjang.a = 20; // assigning value to data field
ajajargenjang.b = 40;
ajajargenjang.t = 50;
Area = ajajargenjang.area(); // invoking method
Circumference = ajajargenjang.circumference();
System.out.println("--Jajaran Genjang--");
System.out.println("Area="+Area);
System.out.println("Circumference ="+Circumference);
}
}
Circle
/**
* Write a description of class circle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class circle
{
public double x,y; // centre coordinate
public double r ; // radius of the circle
//Methods to return circumference and area
public double circumference(){
return 2*3.14*r;
}
public double area(){
return 3.14*r*r;
}
}
Square
/**
* Write a description of class segitiga here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class square
{
public double s;
public double circumference(){
return 4*s;
}
public double area(){
return s*s;
}
}
Rectangle
/**
* Write a description of class segitiga here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class square
{
public double s;
public double circumference(){
return 4*s;
}
public double area(){
return s*s;
}
}
Triangle
/**
* Write a description of class triangle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class triangle
{
public double a,b,c,d;
public double circumference(){
return a+b+c;
}
public double d(){
return circumference()/2;
}
public double area(){
return Math.sqrt(d()*(d()-a)*(d()-b)*(d()-c));
}
}
Belah Ketupat
/**
* Write a description of class belahketupat here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class belahketupat
{
public double d1,d2;
public double s(){
return Math.sqrt((d1/2)*(d1/2) + (d2/2)*(d2/2));
}
public double circumference(){
return 4*s();
}
public double area(){
return 0.5*d1*d2;
}
}
Jajar Genjang
/**
* Write a description of class belahketupat here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class belahketupat
{
public double d1,d2;
public double s(){
return Math.sqrt((d1/2)*(d1/2) + (d2/2)*(d2/2));
}
public double circumference(){
return 4*s();
}
public double area(){
return 0.5*d1*d2;
}
}
Gambar
Comments
Post a Comment