NRP: 05111740000097
Kelas: PBO-A
Ini adalah tugas 2 PBO saya dengan mencari luas dan keliling dari bidang 2D(lingkaran persegi,segitiga,persegi panjang,belah ketupat dan jajar genjang) dengan membuat source code menggunakan bahasa Java.
Berikut merupakan formatted source code saya:
A. Class Main
/**
* @author Muhammad Naufal Refadi
* @version 10-09-2018
*/
class Mymain
{
public static void main()
{
Circle aCircle;
aCircle= new Circle();
aCircle.x=10;
aCircle.y=20;
aCircle.r=5;
double area= aCircle.area();
double circumf=aCircle.Circumference();
System.out.println("Circle:");
System.out.println("Radius="+aCircle.r+" Area="+area);
System.out.println("Radius="+aCircle.r+" Circumference= "+circumf );
System.out.println();
Square aSquare;
aSquare= new Square();
aSquare.s=10;
double areaSquare= aSquare.area();
double perimSquare=aSquare.Perimeter();
System.out.println("Square:");
System.out.println("Side="+aSquare.s+ " Area="+areaSquare);
System.out.println("Side="+aSquare.s+ " Perimeter="+perimSquare);
System.out.println();
Triangle aTriangle;
aTriangle= new Triangle();
aTriangle.a=10;
aTriangle.b=20;
aTriangle.c=30;
aTriangle.h=5;
double areaTriangle= aTriangle.area();
double perimTriangle=aTriangle.Perimeter();
System.out.println("Triangle:");
System.out.println("Side1/base="+aTriangle.a+ " Height="+aTriangle.h+" Area="+areaTriangle);
System.out.println("Side 1="+aTriangle.a+ " Side 2="+aTriangle.b+ " Side 3="+aTriangle.c+ " Perimeter="+perimTriangle);
System.out.println();
Rectangle aRectangle;
aRectangle= new Rectangle();
aRectangle.l=10;
aRectangle.w=20;
double areaRectangle= aRectangle.area();
double perimRectangle=aRectangle.Perimeter();
System.out.println("Rectangle:");
System.out.println("lenght="+aRectangle.l+ " widht="+aRectangle.w+ " Area="+areaRectangle);
System.out.println("lenght="+aRectangle.w+ " widht="+aRectangle.l+" Perimeter="+perimRectangle);
System.out.println();
Rhombus aRhombus;
aRhombus= new Rhombus();
aRhombus.s=10;
aRhombus.d1=12;
aRhombus.d2=16;
double areaRhombus= aRhombus.area();
double perimRhombus=aRhombus.Perimeter();
System.out.println("Rhombus:");
System.out.println("Side="+aRhombus.s+ " Diameter 1="+aRhombus.d1+ " Diameter 1="+aRhombus.d2+ " Area="+areaRhombus);
System.out.println("Side="+aRhombus.s+ " Perimeter="+perimRhombus);
System.out.println();
Parallelogram aParallelogram;
aParallelogram= new Parallelogram();
aParallelogram.a=16;
aParallelogram.b=12;
aParallelogram.h=13;
double areaParallelogram= aParallelogram.area();
double perimParallelogram=aParallelogram.Perimeter();
System.out.println("Parallelogram:");
System.out.println("Side 1/base="+aParallelogram.a+ " Height=" +aParallelogram.h+ " Area="+areaParallelogram);
System.out.println("Side 1="+aParallelogram.a+ " Side 2="+aParallelogram.b+ " Perimeter="+perimParallelogram );
System.out.println();
}
}
b. Public Class Circle
public class Circle
{
public double x,y;
public double r;
/**
* Constructor for objects of class Circle
*/
public double Circumference()
{
// initialise instance variables
return 2*3.14*r;
}
public double area()
{
// put your code here
return 3.14*r*r;
}
}
c. Public Class Persegi
public class Square
{
public double x,y;
public double r,s;
public double Perimeter()
{
return 4*s;
}
public double area()
{
return s*s;
}
}
d. Public Class Segitiga
public class Triangle
{
public double a,b,c,h;
public double Perimeter()
{
return a+b+c;
}
public double area()
{
return (a*h)/2;
}
}
e. Public Class Persegi Panjang
public class Rectangle
{
public double x,y;
public double r,l,w;
public double Perimeter()
{
return 2*(l+w);
}
public double area()
{
return l*w;
}
}
f. Public Class Belah Ketupat
public class Rhombus
{
public double s,d1,d2;
public double Perimeter()
{
return 4*s;
}
public double area()
{
return (d1*d2)/2;
}
}
g. Public Class Jajar Genjang public class Parallelogram
{
public double x,y;
public double a,b,h;
public double Perimeter()
{
return 2*(a+b);
}
public double area()
{
return a*h;
}
}
Berikut ini adalah screenshot bagan class dan outpunya
No comments:
Post a Comment