Source code terdiri dari :
- Main
- Circle
- Rectangle
- Square
- Triangle
- Rhombus
- Parallelogram
1) Source code Main
2) Source code Circle
/**
* Write a description of class Circle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Circle
{
private double radius;
private double centerx;
private double centery;
public Circle()
{
radius = 1;
centerx = 0;
centery = 0;
}
public void SetRadius(double r)
{
radius = r;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 2*3.14*radius;
}
public double Area()
{
return 3.14*radius*radius;
}
}
3) Source code Rectangle
4) Source code Square
/**
* Write a description of class Square here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Square
{
private double side;
private double centerx;
private double centery;
public Square()
{
side = 1;
centerx = 0;
centery = 0;
}
public void SetSide(double s)
{
side = s;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 4 * side;
}
public double Area()
{
return side * side;
}
}
5) Source code Triangle
6) Source code Rhombus
7) Source code Parallelogram
/**
* Write a description of class Parallelogram here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Parallelogram
{
private double longside;
private double height;
private double hypo;
private double centerx;
private double centery;
public Parallelogram()
{
longside = 4.0;
height = 2.0;
hypo = 3.0;
centerx = 0;
centery = 0;
}
public void SetLongSide(double l)
{
longside = l;
}
public void SetHeight(double h)
{
height = h;
}
public void SetHypo(double hy)
{
hypo = hy;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 2 * longside + 2 * hypo;
}
public double Area()
{
return 0.5 * longside * height;
}
}
Workspace
- Main
- Circle
- Rectangle
- Square
- Triangle
- Rhombus
- Parallelogram
1) Source code Main
import static java.lang.Math.sqrt;
import java.awt.*;
/**
* Write a description of class Main here.
*
* @author Satria Ade Veda Karuniawan
* @version 09/10/2018
*/
public class Main
{
public static void main(String args[])
{
//Circle definition
Circle testCircle;
testCircle = new Circle();
testCircle.SetRadius(3.0);
testCircle.SetCenter(2.0,2.0);
double LuasLingkaran = testCircle.Area();
double KelilingLingkaran = testCircle.Circumference();
//Rectangle definition
Rectangle testRectangle;
testRectangle = new Rectangle();
testRectangle.SetSide(4.0,3.0);
testRectangle.SetCenter(2.0,2.0);
double LuasPersegiPanjang = testRectangle.Area();
double KelilingPersegiPanjang = testRectangle.Circumference();
//Square definition
Square testSquare;
testSquare = new Square();
testSquare.SetSide(4.0);
testSquare.SetCenter(2.0,2.0);
double LuasPersegi = testSquare.Area();
double KelilingPersegi = testSquare.Circumference();
//Triangle definition
Triangle testTriangle;
testTriangle = new Triangle();
testTriangle.SetBottom(4.0);
testTriangle.SetCenter(2.0,2.0);
double LuasSegitiga = testTriangle.Area();
double KelilingSegitiga = testTriangle.Circumference();
//Rhombus definition
Rhombus testRhombus;
testRhombus = new Rhombus();
testRhombus.SetDiagonal(2.0,1.5);
testRhombus.SetCenter(2.0,2.0);
double LuasBelahKetupat = testRhombus.Area();
double KelilingBelahKetupat = testRhombus.Circumference();
//Parallelogram definition
Parallelogram testParallelogram;
testParallelogram = new Parallelogram();
testParallelogram.SetLongSide(4.0);
testParallelogram.SetHeight(2.0);
testParallelogram.SetHypo(3.0);
double LuasJajarGenjang = testParallelogram.Area();
double KelilingJajarGenjang = testParallelogram.Circumference();
System.out.println("Luas lingkaran adalah " + LuasLingkaran + " cm^2");
System.out.println("Keliling lingkaran adalah " + KelilingLingkaran + " cm");
System.out.println("Luas persegi-panjang adalah " + LuasPersegiPanjang + " cm^2");
System.out.println("Keliling persegi-panjang adalah " + KelilingPersegiPanjang + " cm");
System.out.println("Luas persegi adalah " + LuasPersegi + " cm^2");
System.out.println("Keliling persegi adalah " + KelilingPersegi + " cm");
System.out.println("Luas segitiga adalah " + LuasSegitiga + " cm^2");
System.out.println("Keliling segitiga adalah " + KelilingSegitiga + " cm");
System.out.println("Luas belah-ketupat adalah " + LuasBelahKetupat + " cm^2");
System.out.println("Keliling belah-ketupat adalah " + KelilingBelahKetupat + " cm");
System.out.println("Luas lingkaran adalah " + LuasJajarGenjang + " cm^2");
System.out.println("Keliling lingkaran adalah " + KelilingJajarGenjang + " cm");
}
}
import java.awt.*;
/**
* Write a description of class Main here.
*
* @author Satria Ade Veda Karuniawan
* @version 09/10/2018
*/
public class Main
{
public static void main(String args[])
{
//Circle definition
Circle testCircle;
testCircle = new Circle();
testCircle.SetRadius(3.0);
testCircle.SetCenter(2.0,2.0);
double LuasLingkaran = testCircle.Area();
double KelilingLingkaran = testCircle.Circumference();
//Rectangle definition
Rectangle testRectangle;
testRectangle = new Rectangle();
testRectangle.SetSide(4.0,3.0);
testRectangle.SetCenter(2.0,2.0);
double LuasPersegiPanjang = testRectangle.Area();
double KelilingPersegiPanjang = testRectangle.Circumference();
//Square definition
Square testSquare;
testSquare = new Square();
testSquare.SetSide(4.0);
testSquare.SetCenter(2.0,2.0);
double LuasPersegi = testSquare.Area();
double KelilingPersegi = testSquare.Circumference();
//Triangle definition
Triangle testTriangle;
testTriangle = new Triangle();
testTriangle.SetBottom(4.0);
testTriangle.SetCenter(2.0,2.0);
double LuasSegitiga = testTriangle.Area();
double KelilingSegitiga = testTriangle.Circumference();
//Rhombus definition
Rhombus testRhombus;
testRhombus = new Rhombus();
testRhombus.SetDiagonal(2.0,1.5);
testRhombus.SetCenter(2.0,2.0);
double LuasBelahKetupat = testRhombus.Area();
double KelilingBelahKetupat = testRhombus.Circumference();
//Parallelogram definition
Parallelogram testParallelogram;
testParallelogram = new Parallelogram();
testParallelogram.SetLongSide(4.0);
testParallelogram.SetHeight(2.0);
testParallelogram.SetHypo(3.0);
double LuasJajarGenjang = testParallelogram.Area();
double KelilingJajarGenjang = testParallelogram.Circumference();
System.out.println("Luas lingkaran adalah " + LuasLingkaran + " cm^2");
System.out.println("Keliling lingkaran adalah " + KelilingLingkaran + " cm");
System.out.println("Luas persegi-panjang adalah " + LuasPersegiPanjang + " cm^2");
System.out.println("Keliling persegi-panjang adalah " + KelilingPersegiPanjang + " cm");
System.out.println("Luas persegi adalah " + LuasPersegi + " cm^2");
System.out.println("Keliling persegi adalah " + KelilingPersegi + " cm");
System.out.println("Luas segitiga adalah " + LuasSegitiga + " cm^2");
System.out.println("Keliling segitiga adalah " + KelilingSegitiga + " cm");
System.out.println("Luas belah-ketupat adalah " + LuasBelahKetupat + " cm^2");
System.out.println("Keliling belah-ketupat adalah " + KelilingBelahKetupat + " cm");
System.out.println("Luas lingkaran adalah " + LuasJajarGenjang + " cm^2");
System.out.println("Keliling lingkaran adalah " + KelilingJajarGenjang + " cm");
}
}
2) Source code Circle
/**
* Write a description of class Circle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Circle
{
private double radius;
private double centerx;
private double centery;
public Circle()
{
radius = 1;
centerx = 0;
centery = 0;
}
public void SetRadius(double r)
{
radius = r;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 2*3.14*radius;
}
public double Area()
{
return 3.14*radius*radius;
}
}
3) Source code Rectangle
import java.awt.*;
import java.awt.Canvas;
/**
* Write a description of class Rectangle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rectangle
{
private double aside;
private double bside;
private double centerx;
private double centery;
private boolean isVisible;
private String color;
public Rectangle()
{
aside = 2;
bside = 1;
centerx = 0;
centery = 0;
isVisible = true;
color = "black";
}
public void SetSide(double l, double s)
{
aside = l;
bside = s;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 2*aside + 2*bside;
}
public double Area()
{
return aside * bside;
}
}
import java.awt.Canvas;
/**
* Write a description of class Rectangle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rectangle
{
private double aside;
private double bside;
private double centerx;
private double centery;
private boolean isVisible;
private String color;
public Rectangle()
{
aside = 2;
bside = 1;
centerx = 0;
centery = 0;
isVisible = true;
color = "black";
}
public void SetSide(double l, double s)
{
aside = l;
bside = s;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 2*aside + 2*bside;
}
public double Area()
{
return aside * bside;
}
}
4) Source code Square
/**
* Write a description of class Square here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Square
{
private double side;
private double centerx;
private double centery;
public Square()
{
side = 1;
centerx = 0;
centery = 0;
}
public void SetSide(double s)
{
side = s;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 4 * side;
}
public double Area()
{
return side * side;
}
}
5) Source code Triangle
import static java.lang.Math.sqrt;
/**
* Write a description of class Triangle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Triangle
{
private double bottom;
private double height;
private double hypo;
private double centerx;
private double centery;
public Triangle()
{
bottom = 1;
height = 1;
centerx = 0;
centery = 0;
}
public void SetBottom(double s)
{
bottom = s;
}
public void SetHeight(double h)
{
height = h;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
hypo = Math.sqrt(0.5*bottom*0.5*bottom + height*height);
return 2*hypo + bottom;
}
public double Area()
{
return 0.5 * bottom * height;
}
}
/**
* Write a description of class Triangle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Triangle
{
private double bottom;
private double height;
private double hypo;
private double centerx;
private double centery;
public Triangle()
{
bottom = 1;
height = 1;
centerx = 0;
centery = 0;
}
public void SetBottom(double s)
{
bottom = s;
}
public void SetHeight(double h)
{
height = h;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
hypo = Math.sqrt(0.5*bottom*0.5*bottom + height*height);
return 2*hypo + bottom;
}
public double Area()
{
return 0.5 * bottom * height;
}
}
6) Source code Rhombus
import static java.lang.Math.sqrt;
/**
* Write a description of class Rhombus here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rhombus
{
private double firstdiagonal;
private double seconddiagonal;
private double side;
private double centerx;
private double centery;
public Rhombus()
{
firstdiagonal = 1;
seconddiagonal = 1;
centerx = 0;
centery = 0;
}
public void SetDiagonal(double d1, double d2)
{
firstdiagonal = d1;
seconddiagonal = d2;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
side = Math.sqrt(0.5 * firstdiagonal * 0.5 * firstdiagonal + 0.5 * seconddiagonal * 0.5 * seconddiagonal);
return 4 * side;
}
public double Area()
{
return 0.5 * firstdiagonal * seconddiagonal;
}
}
/**
* Write a description of class Rhombus here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rhombus
{
private double firstdiagonal;
private double seconddiagonal;
private double side;
private double centerx;
private double centery;
public Rhombus()
{
firstdiagonal = 1;
seconddiagonal = 1;
centerx = 0;
centery = 0;
}
public void SetDiagonal(double d1, double d2)
{
firstdiagonal = d1;
seconddiagonal = d2;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
side = Math.sqrt(0.5 * firstdiagonal * 0.5 * firstdiagonal + 0.5 * seconddiagonal * 0.5 * seconddiagonal);
return 4 * side;
}
public double Area()
{
return 0.5 * firstdiagonal * seconddiagonal;
}
}
7) Source code Parallelogram
/**
* Write a description of class Parallelogram here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Parallelogram
{
private double longside;
private double height;
private double hypo;
private double centerx;
private double centery;
public Parallelogram()
{
longside = 4.0;
height = 2.0;
hypo = 3.0;
centerx = 0;
centery = 0;
}
public void SetLongSide(double l)
{
longside = l;
}
public void SetHeight(double h)
{
height = h;
}
public void SetHypo(double hy)
{
hypo = hy;
}
public void SetCenter(double x, double y)
{
centerx = x;
centery = y;
}
public double Circumference()
{
return 2 * longside + 2 * hypo;
}
public double Area()
{
return 0.5 * longside * height;
}
}
Workspace
Comments
Post a Comment