RSS Feed

Tugas Pertama PBO

1. Class

class biodata {
private static String nama;
private static String npm;
private static String kls;
public static void main(String args[]){
nama = “Yuniarty Utami” ;
npm = “11107834” ;
kls = “3KA12” ;
System.out.println(“Nama : ” + nama);
System.out.println(“NPM  : ” + npm);
System.out.println(“Kelas   : ” + kls);
}
}

Output :

Nama : Yuniarty Utami
NPM  : 11107834
Kelas   : 3KA12

2. Break

class cthBreak{
public static void main(String args[])
{
int x = 1;
while(x <= 15)

{

System.out.println (“kalimat ke- “+ x);

if (x == 7)
break;
x++;
}

System.out.println();
System.out.println(“Perulangan selesai..”);
}
}

Output :

kalimat ke- 1
kalimat ke- 2
kalimat ke- 3
kalimat ke- 4
kalimat ke- 5
kalimat ke- 6
kalimat ke- 7

3. Continue

class cthContinue{
public static void main(String args[]) {
int a = 15;

do {
a=a-2;
if (a == 9)
continue;
System.out.println (“Nilai = “+ a);
if (a == 3)
break;
}

while (a >= 0);
}
}

Output :

Nilai = 13
Nilai = 11
Nilai = 7
Nilai = 5
Nilai = 3

4. Return

class cthReturn{

public static void main(String args[]){

boolean x = true;
System.out.println(“Haaaii..”);
System.out.println(“Apa kabar?”);
if(x) return;
System.out.println(“Tidak dieksekusi.”);
}
}

Output :

Haaaii..
Apa kabar?

5. Getter dan Setter

public class cthsetget {

private String makan;
private String minum;
private int harga;

public String getFood(){
return makan;
}

public String getDrink(){
return minum;
}

public int getCost(){
return harga;
}

public void setFood(String makan){
this.makan = makan;
}

public void setDrink(String minum){
this.minum = minum;
}

public void setCost(int harga){
this.harga = harga;
}
}

public class cobasetget {
public static void main(String[] args){

setget makanan = new setget();
setget minuman = new setget();
setget harga = new setget();

makanan.setFood(“Gado-gado”);
minuman.setDrink(“Teh Manis”);
harga.setCost(16000);

System.out.println(“Makanan yang dipesan adalah ” + makanan.getFood());
System.out.println(“Minuman yang dipesan adalah ” + minuman.getDrink());
System.out.println(“Total harga : Rp ” + harga.getCost());
}
}

Output :

Makanan yang dipesan adalah Gado-gado
Minuman yang dipesan adalah Teh Manis
Total harga : Rp 16000

About Yuniarty Utami

Yuniarty Utami is a student of Information System, Faculty of Computer Science and Information Technology, Gunadarma University.

One response »

  1. masiih belum paham codingan java..😦

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: