Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point2 {
- float x;
- float y;
- }
- class Line {
- Point2 awal;
- Point2 akhir;
- }
- public class ADTGaris {
- static Point2 makePoint(float x, float y){
- Point2 temp = new Point2();
- temp.x = x;
- temp.y = y;
- return temp;
- }
- static Line makeLine(Point2 a, Point2 b){
- Line temp = new Line();
- temp.awal = a;
- temp.akhir = b;
- return temp;
- }
- static float distanceX(Point2 a, Point2 b){
- return b.x - a.x;
- }
- static float distanceY(Point2 a, Point2 b){
- return b.y - a.y;
- }
- static float gradient(Point2 a, Point2 b){
- return (b.y - a.y)/(b.x - a.x);
- }
- static void writeLine(Line a){
- System.out.println("Point awal : "+a.awal.x+" , "+a.awal.y+"\nPoint akhir : "+a.akhir.x+" , "+a.akhir.y);
- }
- public static void main(String[] args){
- Point2 a = makePoint(1, 2);
- Point2 b = makePoint(3, 4);
- Line l = makeLine(a, b);
- writeLine(l);
- System.out.println("Jarak X : "+distanceX(a, b)+"\nJarak Y : "+distanceY(a, b));
- System.out.println("Gradien garis : "+gradient(a, b));
- }
- }
- HASIL :
- Point awal : 1.0 , 2.0
- Point akhir : 3.0 , 4.0
- Jarak X : 2.0
- Jarak Y : 2.0
- Gradien garis : 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement