PROGRAM MENGHITUNG SUDUT VEKTOR PADA JAVA DENGAN NETBEANS

PROGRAM MENGHITUNG SUDUT VEKTOR PADA JAVA DENGAN NETBEANS



Program Menghitung Sudut Vektor Pada Java Dengan Netbeans
1. DASAR TEORI MENGHITUNG SUDUT VEKTOR :




 2. CONTOH PENERAPAN RUMUS :




3. FLOWCHART PROGRAM MENGHITUNG SUDUT VEKTOR





4. PROGRAM DAN HASILNYA :
SOURCE CODE PROGRAM :

package program.menghitung.sudut.vektor;
/*Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 */
import java.util.Scanner;

class vektor{
double x1,  x2, x3, x4, y1, y2, y3, y4;
double a31, a42, b31, b42;
double uxv, uu, vv, cos;
public void setvektor1(double a,double b){
    x1=a;
    y1=b; 
}

public void setvektor2(double c, double d){
    x2=c;
    y2=d;
}

public void setvektor3(double e, double f){
    x2=e;
    y3=f;
}

public void setvektor4(double g, double h){
    x4=g;
    y4=h;
}

public void hitungvektorposisi(){
    uxv = (x1*x2)+(y1*y2);
    uu = Math.sqrt(((x1*x1)+(y1*y1)));
    vv = Math.sqrt((x2*x2)+(y2*y2));
    cos = Math.toDegrees(Math.acos(uxv / (uu*vv)));
    System.out.println("X1 = "+x1+" Y1 = "+y1);
    System.out.println("X2 = "+x2+" Y2 = "+y2);
    System.out.println("U.V = "+uxv);
    System.out.println("|U| : "+uu);
    System.out.println("|V| : "+vv);
    System.out.println("Sudut Vektor = (U.V) / (|U|.|V|)");
    System.out.println("Sudut Vektornya : "+cos);
}

public void hitungvektorbukanposisi(){
    a31 = x2-x1;
    a42 = y2-y1;
    b31 = x4-x3;
    b42 = y4-y3;
   
    // vektor1 = (a31, a42)
    // vektor2 = (b31, b42)
    uxv = (a31*b31)+(a42*b42);
    uu = Math.sqrt(((a31*a31)+(a42*a42)));
    vv = Math.sqrt((b31*b31)+(b42*b42));
    cos = Math.toDegrees(Math.acos(uxv / (uu*vv)));
    System.out.println("X1 = "+x1+" Y1 = "+y1);
    System.out.println("X2 = "+x2+" Y2 = "+y2);
    System.out.println("X3 = "+x3+" Y3 = "+y3);
    System.out.println("X4 = "+x4+" Y4 = "+y4);
    System.out.println("U.V = "+uxv);
    System.out.println("|U| : "+uu);
    System.out.println("|V| : "+vv);
    System.out.println("Sudut Vektor = (U.V) / (|U|.|V|)");
    System.out.println("Sudut Vektornya : "+cos);
}
}

public class ProgramMenghitungSudutVektor {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        vektor main = new vektor();
        double x1, x2, x3, x4, y1, y2, y3, y4;
        int pil1=1, pil2;
               
        while (pil1==1){
            System.out.println("============PROGRAM START============");
            System.out.print("Apakah vektor posisi(1=YA ATAU 2=TIDAK)? : ");
            pil2 = input.nextInt();
           
            if(pil2 == 1){
                System.out.print("Masukkan x1 : ");
                x1=input.nextDouble();
                System.out.print("Masukkan y1 : ");
                y1=input.nextDouble();
                System.out.print("Masukkan x2 : ");
                x2=input.nextDouble();
                System.out.print("Masukkan y2 : ");
                y2=input.nextDouble();
                main.setvektor1(x1,y1);
                main.setvektor2(x2,y2);
                main.hitungvektorposisi();
            }
            else if(pil2 == 2){
                System.out.print("Masukkan x1 : ");
                x1=input.nextDouble();
                System.out.print("Masukkan y1 : ");
                y1=input.nextDouble();
                System.out.print("Masukkan x2 : ");
                x2=input.nextDouble();
                System.out.print("Masukkan y2 : ");
                y2=input.nextDouble();
                System.out.print("Masukkan x3 : ");
                x3=input.nextDouble();
                System.out.print("Masukkan y3 : ");
                y3=input.nextDouble();
                System.out.print("Masukkan x4 : ");
                x4=input.nextDouble();
                System.out.print("Masukkan y4 : ");
                y4=input.nextDouble();
                main.setvektor1(x1,y1);
                main.setvektor2(x2,y2);
                main.setvektor3(x3,y3);
                main.setvektor4(x4,y4);
                main.hitungvektorbukanposisi();
            }
            else{
                System.out.println("Pilihan Anda Tidak Tersedia!!!");
            }
            System.out.println("");
            System.out.println("HITUNG LAGI ?? MASUKKAN 1=YA ATAU 2=TIDAK");
            System.out.print("Pilihan anda : ");
            pil1 = input.nextInt();
        }
        System.out.println("----------////==========");
        System.out.println("Program dihentikan!!!");
    }
   
}


HASIL PROGRAM SETELAH DIJALANKAN :



6. CARA COPY PROGRAM SUPAYA BERJALAN

1. buat project baru pada netbeanst dan beri nama "vektor project" atau boleh bebas.
2. Penting, jangan rubah apapun pada tulisan "package.....bla bla bla" dan "public class ... bla bla"
3. copy script dibawah ini pada baris bawah setelah "package ..bla bla bla".

/*Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 */
import java.util.Scanner;

class vektor{
double x1,  x2, x3, x4, y1, y2, y3, y4;
double a31, a42, b31, b42;
double uxv, uu, vv, cos;
public void setvektor1(double a,double b){
    x1=a;
    y1=b;   
}

public void setvektor2(double c, double d){
    x2=c;
    y2=d;
}

public void setvektor3(double e, double f){
    x2=e;
    y3=f;
}

public void setvektor4(double g, double h){
    x4=g;
    y4=h;
}

public void hitungvektorposisi(){
    uxv = (x1*x2)+(y1*y2);
    uu = Math.sqrt(((x1*x1)+(y1*y1)));
    vv = Math.sqrt((x2*x2)+(y2*y2));
    cos = Math.toDegrees(Math.acos(uxv / (uu*vv)));
    System.out.println("X1 = "+x1+" Y1 = "+y1);
    System.out.println("X2 = "+x2+" Y2 = "+y2);
    System.out.println("U.V = "+uxv);
    System.out.println("|U| : "+uu);
    System.out.println("|V| : "+vv);
    System.out.println("Sudut Vektor = (U.V) / (|U|.|V|)");
    System.out.println("Sudut Vektornya : "+cos);
}

public void hitungvektorbukanposisi(){
    a31 = x2-x1;
    a42 = y2-y1;
    b31 = x4-x3;
    b42 = y4-y3;
    
    // vektor1 = (a31, a42)
    // vektor2 = (b31, b42)
    uxv = (a31*b31)+(a42*b42);
    uu = Math.sqrt(((a31*a31)+(a42*a42)));
    vv = Math.sqrt((b31*b31)+(b42*b42));
    cos = Math.toDegrees(Math.acos(uxv / (uu*vv)));
    System.out.println("X1 = "+x1+" Y1 = "+y1);
    System.out.println("X2 = "+x2+" Y2 = "+y2);
    System.out.println("X3 = "+x3+" Y3 = "+y3);
    System.out.println("X4 = "+x4+" Y4 = "+y4);
    System.out.println("U.V = "+uxv);
    System.out.println("|U| : "+uu);
    System.out.println("|V| : "+vv);
    System.out.println("Sudut Vektor = (U.V) / (|U|.|V|)");
    System.out.println("Sudut Vektornya : "+cos);
}
}

4. Copy script dibawah ini pada baris bawah setelah "public static void main(String[] args) {"

        Scanner input = new Scanner(System.in);
        vektor main = new vektor();
        double x1, x2, x3, x4, y1, y2, y3, y4;
        int pil1=1, pil2;
                
        while (pil1==1){
            System.out.println("============PROGRAM START============");
            System.out.print("Apakah vektor posisi(1=YA ATAU 2=TIDAK)? : ");
            pil2 = input.nextInt();
            
            if(pil2 == 1){
                System.out.print("Masukkan x1 : ");
                x1=input.nextDouble();
                System.out.print("Masukkan y1 : ");
                y1=input.nextDouble();
                System.out.print("Masukkan x2 : ");
                x2=input.nextDouble();
                System.out.print("Masukkan y2 : ");
                y2=input.nextDouble();
                main.setvektor1(x1,y1);
                main.setvektor2(x2,y2);
                main.hitungvektorposisi();
            }
            else if(pil2 == 2){
                System.out.print("Masukkan x1 : ");
                x1=input.nextDouble();
                System.out.print("Masukkan y1 : ");
                y1=input.nextDouble();
                System.out.print("Masukkan x2 : ");
                x2=input.nextDouble();
                System.out.print("Masukkan y2 : ");
                y2=input.nextDouble();
                System.out.print("Masukkan x3 : ");
                x3=input.nextDouble();
                System.out.print("Masukkan y3 : ");
                y3=input.nextDouble();
                System.out.print("Masukkan x4 : ");
                x4=input.nextDouble();
                System.out.print("Masukkan y4 : ");
                y4=input.nextDouble();
                main.setvektor1(x1,y1);
                main.setvektor2(x2,y2);
                main.setvektor3(x3,y3);
                main.setvektor4(x4,y4);
                main.hitungvektorbukanposisi();
            }
            else{
                System.out.println("Pilihan Anda Tidak Tersedia!!!");
            }
            System.out.println("");
            System.out.println("HITUNG LAGI ?? MASUKKAN 1=YA ATAU 2=TIDAK");
            System.out.print("Pilihan anda : ");
            pil1 = input.nextInt();
        }
        System.out.println("----------////==========");
        System.out.println("Program dihentikan!!!");
 
5. Program Siap Dijalankan!!... Selamat mencoba.

note : jika masih ada kendala silahkan komentar dibawah ini ya...



Related Posts

Previous
Next Post »