From 297748cf2974479b98e2d1699938a5e5ec4f1d2d Mon Sep 17 00:00:00 2001 From: arhamizza Date: Wed, 2 Dec 2020 16:03:19 +0700 Subject: [PATCH] ArhamIzzaSyany_1941720127 --- Arham/Circle.java | 38 +++++++++++++++++++++++++++++++++ Arham/Main.java | 17 +++++++++++++++ Arham/Rectangle.java | 51 ++++++++++++++++++++++++++++++++++++++++++++ Arham/Shape.java | 38 +++++++++++++++++++++++++++++++++ Arham/Square.java | 38 +++++++++++++++++++++++++++++++++ Arham/Test.java | 23 ++++++++++++++++++++ 6 files changed, 205 insertions(+) create mode 100644 Arham/Circle.java create mode 100644 Arham/Main.java create mode 100644 Arham/Rectangle.java create mode 100644 Arham/Shape.java create mode 100644 Arham/Square.java create mode 100644 Arham/Test.java diff --git a/Arham/Circle.java b/Arham/Circle.java new file mode 100644 index 0000000..f8bc908 --- /dev/null +++ b/Arham/Circle.java @@ -0,0 +1,38 @@ +public class Circle extends Shape { + + protected double radius; + public Circle() { + + } + public Circle(double radius, String color, Boolean filled) { + super(color,filled); + this.radius=radius; + } + + public Circle(double radius) { + this.radius=radius; + } + + public double getRadius() { + return radius; + } + + public void setRadius(double radius) { + this.radius = radius; + } + + @Override + public double getArea() { + return radius*radius*Math.PI; + } + @Override + public double getPerimeter() { + return 2*Math.PI*radius; + } + @Override + public String getToString() { + String info = super.getToString()+"\n"; + info += "Radius"+radius +"\n luas"+this.getArea()+"\n luas"+getPerimeter(); + return info; + } +} diff --git a/Arham/Main.java b/Arham/Main.java new file mode 100644 index 0000000..e9bf1d6 --- /dev/null +++ b/Arham/Main.java @@ -0,0 +1,17 @@ +public class Main { + public static void main(String[] args) { + Test tes = new Test(); + Circle cil = new Circle(10.0, "Biru", true); + tes.hitung(cil); + + Rectangle wow = new Rectangle(2,5, "merah", true); + tes.hitung(wow); + + Square sq = new Square(); + if (wow.width==wow.length) { + tes.kotak(sq); + } else { + tes.kotak(wow); + } + } +} diff --git a/Arham/Rectangle.java b/Arham/Rectangle.java new file mode 100644 index 0000000..dd0c7ba --- /dev/null +++ b/Arham/Rectangle.java @@ -0,0 +1,51 @@ +public class Rectangle extends Shape { + protected double width; + protected double length; + + public Rectangle() { + + } + + public Rectangle(double width, double length) { + this.width=width; + this.length=length; + } + + public Rectangle(double width, double length,String color,Boolean filled) { + super(color, filled); + this.width=width; + this.length=length; + } + + public double getWidth() { + return width; + } + + public void setWidth(double width) { + this.width = width; + } + + public double getLength() { + return length; + } + + public void setLength(double length) { + this.length = length; + } + + @Override + public double getArea() { + return width*length; + } + @Override + public double getPerimeter() { + return (2*width)+(2*length); + } + + @Override + public String getToString() { + String info = super.getToString()+"\n"; + info += "width"+width +"length"+length+"\n luas"+this.getArea()+"\n Keliling"+getPerimeter(); + return info; + } +} diff --git a/Arham/Shape.java b/Arham/Shape.java new file mode 100644 index 0000000..f04ca2d --- /dev/null +++ b/Arham/Shape.java @@ -0,0 +1,38 @@ +/** + * shape + */ +public abstract class Shape { + protected String color; + protected Boolean filled = true; + + public Shape() { + + } + + public Shape(String color, boolean filled) { + this.filled = filled; + this.color = color; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public Boolean isiFilled() { + return filled; + } + + public void setFilled(Boolean filled) { + this.filled = filled; + } + + public abstract double getArea(); + public abstract double getPerimeter(); + public String getToString() { + return "color ="+color; + } +} \ No newline at end of file diff --git a/Arham/Square.java b/Arham/Square.java new file mode 100644 index 0000000..526229d --- /dev/null +++ b/Arham/Square.java @@ -0,0 +1,38 @@ +public class Square extends Rectangle { + protected double side; + + public Square() { + } + public Square(double side) { + this.side=side; + } + + public Square(double side,String color,boolean filled, double width,double length) { + super(width, length); + this.side=side; + } + + public double getSide() { + return side; + } + + public void setSide(double side) { + this.side = side; + } + + @Override + public void setWidth(double width) { + super.setWidth(width); + } + + @Override + public void setLength(double length) { + super.setLength(length); + } + @Override + public String getToString() { + String info = super.getToString()+"\n"; + info += "lebar="+super.width+"panjang="+super.length; + return info; + } +} diff --git a/Arham/Test.java b/Arham/Test.java new file mode 100644 index 0000000..dfc39f3 --- /dev/null +++ b/Arham/Test.java @@ -0,0 +1,23 @@ +public class Test { + public void hitung(Shape s) { + if (s instanceof Circle) { + Circle eb = (Circle) s; + System.out.println("----------------lingkaran-------------"); + System.out.println(""+eb.getToString()); + } + else if (s instanceof Rectangle){ + Rectangle pe = (Rectangle) s; + System.out.println("----------------Segi Empat-------------"); + System.out.println(""+pe.getToString());} + } + + public void kotak(Rectangle e) { + System.out.println("DIBAWah INI ADALAH UNTUK MENGECEK APAKAH PERSEGI PANJANG ATAU PERSEGI"); + if (e instanceof Square) { + System.out.println("Ini adalah Persegi karena lebar=" + e.width+"panjang ="+e.length); + + } else { + System.out.println("Ini bukan persegi karena lebar=" + e.width+"panjang ="+e.length); + } + } +}