Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kuis2_1941720127_Arham Izza S #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Arham/Circle.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 17 additions & 0 deletions Arham/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
51 changes: 51 additions & 0 deletions Arham/Rectangle.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
38 changes: 38 additions & 0 deletions Arham/Shape.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
38 changes: 38 additions & 0 deletions Arham/Square.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions Arham/Test.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}