Belajar oprek-oprek Kartesian di Object Oriented Programming


import java.util.Scanner; 

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

public class point{

int dotx;

int doty;

point(int x,int y){

dotx = x;

doty = y;

}

public int getpointsbx(){

return (dotx-2*dotx);

}

public int getpointsby(){

return (doty-2*doty);

}

public int getKuadran(int x,int y){

int hasil = 0;

if (x>=0 && y>=0){hasil = 1;}

else if(x<=0 && y>=0){hasil = 2;}

else if(x<=0 && y<=0){hasil = 3;}

else if(x>=0 && y<=0){hasil = 4;}

return hasil;

}

public int getDikurangiX(int x){

Scanner sc = new Scanner(System.in);

int kr = sc.nextInt();

return x-kr;

}

public int getDikurangiY(int y){

Scanner sc = new Scanner(System.in);

int kr = sc.nextInt();

return y-kr;

}

public int getDitambahX(int x){

Scanner sc = new Scanner(System.in);

int kr = sc.nextInt();

return x+kr;

}

public int getDitambahY(int y){

Scanner sc = new Scanner(System.in);

int kr = sc.nextInt();

return y+kr;

}

public void view(){

int help;

System.out.print(“Pasangan koordinat awal : (“+dotx+”,”+doty+”) “);

System.out.println(“Ada di kuadran :”+getKuadran(dotx,doty));

System.out.print(“Jika dicerminkan terhadap sumbu x hasilnya adalah (“+getpointsbx()+”,”+doty+”) “);

System.out.println(“Ada di kuadran :”+getKuadran(getpointsbx(),doty));

System.out.print(“Jika dicerminkan terhadap sumbu y hasilnya adalah (“+dotx+”,”+getpointsby()+”) “);

System.out.println(“Ada di kuadran :”+getKuadran(dotx,getpointsby()));

System.out.print(“Jika dicerminkan terhadap sumbu x,y hasilnya adalah (“+doty+”,”+dotx+”) “);

System.out.println(“Ada di kuadran :”+getKuadran(doty,dotx));

System.out.print(“Jika dicerminkan terhadap sumbu -x,-y hasilnya adalah (“+getpointsby()+”,”+getpointsbx()+”) “);

System.out.println(“Ada di kuadran :”+getKuadran(getpointsby(),getpointsbx()));

System.out.print(“Nilai x ditambah : “); help = getDitambahX(dotx);

System.out.println(“adalah : “+help+”,”+doty+” di kuadran “+getKuadran(help,doty));

System.out.print(“Nilai y ditambah : “); help = getDitambahY(doty);

System.out.println(“adalah : “+dotx+”,”+help+” di kuadran “+getKuadran(dotx,help));

System.out.print(“Nilai x dikurangi : “); help = getDikurangiX(dotx);

System.out.println(“adalah : “+help+”,”+doty+” di kuadran “+getKuadran(help,doty));

System.out.print(“Nilai y dikurangi : “); help = getDikurangiY(doty);

System.out.println(“adalah : “+dotx+”,”+help+” di kuadran “+getKuadran(dotx,help));

}

public static void main(String[] args){

Scanner s= new Scanner(System.in);

System.out.print(“Inputkan titik x : “);

int x = s.nextInt();

System.out.print(“Inputkan titik y : “);

int y = s.nextInt();

point P= new point(x,y);

P.view();

}

}

 

Iklan

Tinggalkan Komentar

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s