Created
December 12, 2018 09:01
-
-
Save fahmifan/6f25507d1a321e7fa3860a63def39977 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: Muhammad Fahmi I. | |
* Github: github.com/miun173 | |
* Year: 2018 | |
*/ | |
interface GeometriObject{ | |
double getPerimeter(); | |
double getArea(); | |
// ini juga bisa | |
// public double getPerimeter(); | |
// public double getArea(); | |
} | |
/** | |
* Circle: accept radius | |
*/ | |
class Circle implements GeometriObject { | |
protected Double radius = 1.0; | |
public Circle(double radius) { | |
this.radius = radius; | |
} | |
@Override | |
public double getPerimeter() { | |
return 2*3.14*this.radius; | |
} | |
@Override | |
public double getArea() { | |
return 3.14*(this.radius*this.radius); | |
} | |
} | |
interface Resizable{ | |
public void resize(int percent); | |
// ini juga bisa | |
// void resize(int percent); | |
} | |
/** | |
* Circle that can be resize based on it's raidus | |
*/ | |
class ResizableCircle extends Circle implements Resizable { | |
public ResizableCircle(Double radius) { | |
super(radius); | |
} | |
// Resize the circle radius by percentage | |
@Override | |
public void resize(int percentage) { | |
super.radius = super.radius * percentage/100.0; | |
} | |
} | |
class Test { | |
public static void main(String[] args) { | |
ResizableCircle rc = new ResizableCircle(10.0); | |
System.out.println("Keliling gelang = " + rc.getPerimeter()); | |
System.out.println("Luas gelang = " + rc.getArea()); | |
System.out.println("====setealah resize 20%===="); | |
rc.resize(20); | |
System.out.println("Keliling gelang = " + rc.getPerimeter()); | |
System.out.println("Luas gelang = " + rc.getArea()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment