Modul 1 Class



PRAKTIKUM PEMROGRAM BERORIENTASI OBJEK
MODUL 1 CLASS




Tujuan
Melengkapi laporan praktikum Pemrograman Berorientasi Objek modul 1.
Landasan Teori
Modul praktikum Pemrograman Berorientasi Objek.
Class adalah cetak biru (blue print) dari objek. Dengan kata lain, suatu objek dapat dibuat/diturunkan dari suatu model rancangan yang disebut class.
Alat dan Bahan
1 Unit PC
OS windows
Netbeans
Modul praktikum PBO
Langkah – Langkah Pratikum
Contoh Class
Bicycle.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package praktikumpbo;

/**
 *
 * @author irwan
 */
public class Bicycle {
    int cadance;
    int speed;
    int gear;
   
    void changeCadance (int newValue){
        cadance = newValue;
    }
   
    void changeGear (int newValue){
        gear = newValue;
    }
   
    void speedUp (int increment){
        speed = speed+increment;
    }
   
    void applyBreak (int decrement){
        speed = speed - decrement;
    }
   
    void printStates(){
        System.out.println("Speed = "+speed+" "+ "Gear = "+gear+", "+"Cadance = "+cadance+"");
    }
}

Bicycledemo.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package praktikumpbo;

/**
 *
 * @author irwan
 */
public class BicycleDemo {
    public static void main(String []args){
        Bicycle bike1= new Bicycle();
        Bicycle bike2= new Bicycle();
       
        bike1.changeCadance(50);
        bike1.speedUp(10);
        bike1.changeGear(2);
        bike1.printStates();
       
        bike2.changeCadance(50);
        bike2.speedUp(10);
        bike2.changeGear(2);
        bike2.changeCadance(40);
        bike2.speedUp(10);
        bike2.changeGear(3);
        bike2.printStates();
    }
}

Hasil pembutan class diatas seperti gambar dibawah ini :

   
Latihan 1
Kucing.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package praktikumpbo.latihanmodul1;

/**
 *
 * @author irwan
 */
public class Kucing {
    String nama, ultah, warna;
   
    void meong (String newValue){
        nama = newValue;
    }
   
    void modelWarna (String newValue){
        warna = newValue;
    }
   
    void ulangTahun (String newValue){
        ultah = newValue;
    }
   
   
    void printStates(){
        System.out.println("nama = "+nama+" "+ "warna = "+warna+", "+"ultah = "+ultah+"");
    }
}

KucingDemo.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package praktikumpbo.latihanmodul1;

/**
 *
 * @author irwan
 */
public class KucingDemo {
    public static void main(String []args){
        Kucing cing1= new Kucing();
        Kucing cing2= new Kucing();
       
        cing1.meong("pussy");
        cing1.modelWarna("putih");
        cing1.ulangTahun("januari");
        cing1.printStates();
       
        cing2.meong("kitty");
        cing2.modelWarna("biru abu-abu");
        cing2.ulangTahun("desember");
        cing2.printStates();
    }
}

Hasil latihan 1 seperti gambar dibawah ini:


Latihan 2 a dan b
Rekening.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pbo_no2;

/**
 *
 * @author irwan
 */
public class Rekening {
    String saldo, nama, noRekening;
   
    void cekSaldo (String newValue){
        saldo = newValue;
    }
    void menabung (String newValue) {
        noRekening = newValue;
    }
    void menarik (String newValue){
        nama = newValue;
    }
    void transfer (String newValue){
        noRekening = newValue;
    }
   
    void printState (){
        System.out.println("saldo = "+saldo+", "+"noRekening = "+noRekening+" ,"+" nama= "+nama+"");
    }
}

RekeningDemo.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pbo_no2;

/**
 *
 * @author irwan
 */
public class Rekeningdemo {
    public static void main (String[]args){
        Rekening customer1 = new Rekening();
        Rekening customer2 = new Rekening();
       
        customer1.cekSaldo("Rp 189.000.000");
        customer1.menabung("Rp 12.0000,000");
        customer1.menarik("adi");
        customer1.transfer("1234567890");
        customer1.printState();
       
       
        customer2.cekSaldo("Rp 77.000.000");
        customer2.menabung("Rp 13.0000,000");
        customer2.menarik("irwan");
        customer2.transfer("0123456789");
        customer2.printState();
    }
}
Hasil latihan 2 seperti gambar dibawah ini :




Analisa
Berdasarkan percobaan yang  telah dilakukan maka suatu class cukup dibuat hanya satu buah saja dan dari class tersebut dapat dibuat/diturunkan beberapa objek (puluhan atau bahkan ratusan) yang memiliki sifat yang sama.

Tugas

Pekerjaan Rumah
Tugas_modul1.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Tugas;

import java.util.Scanner;

/**
 *
 * @author irwan
 */
public class Tugas_modul1 {
   
   
    public static void main(String[]args){
        String B = "Teknik Informatika UMS";
        String Besar = B.toUpperCase();
        int nB = B.length();
       
        Scanner inputan = new Scanner (System.in);
        System.out.println("Tuliskan Sebuah Kalimat");
        String nama=inputan.next();
        System.out.println("Jumlah karakter pada kalimat=" +nB);
        System.out.println(""+Besar);
    }
}

Hasil pekerjaan rumah seperti gambar dibawah ini :

 



0 komentar:

Posting Komentar