lukmanunindra

Home » PBO » Pertemuan 1 PBO

Pertemuan 1 PBO

Pemograman non OOP

class AritmatikanonOOP{
public static  void main(String[]args)
{
int a=10,b=2;
System.out.println(“operasi kali “+(a*b));
System.out.println(“operasi Bagi “+(a/b));
System.out.println(“operasi tambah “+(a+b));
System.out.println(“operasi kurang “+(a-b));
}
}

 

Pemograman OOP

class AritmatikaOOP{
int a;
int b;

public int kali(int a, int b){
int c = a*b;
return c;
}
public int bagi(int a, int b){
int c = a/b;
return c;
}
public int tambah(int a, int b){
int c = a+b;
return c;
}
public int kurang(int a,int b){
int c = a-b;
return c;
}
}

Buat class baru Program oop 2

class ProgramUtamaAritmatika
{
public static void main(String[] args){
int x=10;
int y=2;

AritmatikaOOP AOOP = new AritmatikaOOP();

System.out.println(“Operasi kali “+AOOP.kali(x,y));
System.out.println(“Operasi bagi “+AOOP.bagi(x,y));
System.out.println(“Operasi tambah “+AOOP.tambah(x,y));
System.out.println(“Operasi kurang “+AOOP.kurang(x,y));

}

}

 

Advertisements
%d bloggers like this: