Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point {
- float x;
- float y;
- }
- public class ADT_KelompokVandiPoint {
- static Point makePoint(float x, float y){
- Point A = new Point();
- A.x = x;
- A.y = y;
- return A;
- }
- static Point bacaPoint(){
- Point A = new Point();
- A.x = 9.3f;
- A.y = 3.6f;
- return A;
- }
- static float getAbsis(Point A){
- return A.x;
- }
- static float getOrdinat(Point A){
- return A.y;
- }
- static void setAbsis(Point A, float x){
- A.x = x;
- }
- static void setOrdinat(Point A, float y){
- A.y = y;
- }
- static void tulisPoint(Point A){
- System.out.println("Point ("+A.x+","+A.y+") dengan x = "+A.x+" dan y = "+A.y);
- }
- static Point geserKanan(Point A, float dx){
- A.x += dx;
- return A;
- }
- static Point geserAtas(Point A, float dy){
- A.y += dy;
- return A;
- }
- static Point cerminX(Point A){
- A.y = -A.y;
- return A;
- }
- static Point cerminY(Point A){
- A.x = -A.x;
- return A;
- }
- public static void main(String[] args){
- Point P1 = makePoint(4,6);
- Point P2 = bacaPoint();
- tulisPoint(P1);
- tulisPoint(P2);
- float x = getAbsis(P1);
- float y = getOrdinat(P1);
- setAbsis(P1,4);
- setOrdinat(P1,6);
- tulisPoint(P1);
- P1= geserKanan(P1,5);
- tulisPoint(P1);
- P1 = geserAtas(P1,7);
- tulisPoint(P1);
- P1 = cerminX(P1);
- tulisPoint(P1);
- P1 = cerminY(P1);
- tulisPoint(P1);
- }
- }
- HASIL :
- Point (4.0,6.0) dengan x = 4.0 dan y = 6.0
- Point (9.3,3.6) dengan x = 9.3 dan y = 3.6
- Point (4.0,6.0) dengan x = 4.0 dan y = 6.0
- Point (9.0,6.0) dengan x = 9.0 dan y = 6.0
- Point (9.0,13.0) dengan x = 9.0 dan y = 13.0
- Point (9.0,-13.0) dengan x = 9.0 dan y = -13.0
- Point (-9.0,-13.0) dengan x = -9.0 dan y = -13.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement