Posted by : Octo The Azura Selasa, 17 Maret 2015

MODUL 1 : CLASS
NAME
RAHMATUL MAHDALINA
STUDENT NUMBER
L200134004
CLASS
X

EXERCISE

A.    Objective
To Understand what is class and make student can create class it self.

B.     Basic Teory
Class is blueprint from object. Some object can created from project that called class. Basic on this definition, then a sufficient class made just one part of the class and can be created / unloaded several objects (tens or even hundreds) that have the same properties

C.     Tools and Materials
·         Laptop
·         Software NetBeans IDE 8.0.2
·         Java Development Kit (JDK) 1.8

D.    Work Step
This is some implementation of bicycle class :
public class bicycle {
    int cadence;
    int speed;
    int gear;
    
    void changeCadence (int newValue){
        cadence = 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+", "+"Cadence = "+cadence);
    }
    
}
Class Bicycle abovedo nothave amainfunction(mainmethod)becausethisclassis not anapplication programbut merelya blueprint tocreate.Torunan application program, it mustbe givenaclassthathasaprimaryfunction.

public class BicycleDemo {
    public static void main(String []args){
        bicycle bike1 = new bicycle();
        bicycle bike2 = new bicycle();
        
        bike1.changeCadence(50);
        bike1.speedUp(10);
        bike1.changeGear(2);
        bike1.printStates();
        
        bike2.changeCadence(50);
        bike2.speedUp(10);
        bike2.changeGear(2);
        bike2.changeCadence(40);
        bike2.speedUp(10);
        bike2.changeGear(3);
        bike2.printStates();
    }
}
A.    Analysis
To make class we must have blueprint and main method to run some java program.
Ern4t
B.     Assignment
1.      Createaclassthatcan present thepropertiesof the objectcat. Thisobjecthasthe form{umur, warnabulu}andfunction ofthe form{meow, ulang tahun}.
Code :
public class kucing {
    int umur;
    String warnabulu;
    
    void changeUmur (int newValue){
        umur = newValue;
    }
    
    void changeWarnabulu (String color){
        warnabulu = color;
    }
    void printStates(){
        System.out.println("Kucingku yang berwarna "+warnabulu+" "+"berumur "+umur+" "+"tahun,");
    }
}
public class kucingku {
    public static void main(String[]args){
        kucing pretty = new kucing ();
        kucing togo = new kucing ();
        
        pretty.changeUmur (2);
        pretty.changeWarnabulu("Putih");
        pretty.printStates();
        
        togo.changeUmur (3);
        togo.changeWarnabulu("Hitam");
        togo.printStates();
    }
    
}
2.   One of the application PBO isa verycommonform offinancial applications. Bank Account isone of the thingsthatcanbe usedasan objectinthe PBO.
                                                              i.      Createaclassthatcanpresenttheaccountobject. variablesofthisobjectis {saldo, no rek, nama} and function ofthe form {cek saldo, menabung, menarik, and transfer}.
                                                            ii.      Create a class that has a main function that is used to demonstrate the making of the object.
Code :
public class Bank {
    int saldo;
    int noRek;
    String nama;
    
    void norek(int newValue){
        noRek = newValue;
    }
    
    void nama(String newName){
        nama = newName;
    }
    
    void cekSaldo(int newValue){
        saldo = newValue;
    }
    
    void menabung(int increment){
        saldo = saldo+increment;
    }
    
    void menarik(int decrement){
        saldo = saldo-decrement;
    }
    
    void transfer(int transfer){
        saldo = saldo-transfer;
    }
   
    void printStates(){
        System.out.println("Saldo Terakhir Nomor Rekening "+noRek+" atas nama "+nama+
        " adalah sebesar "+saldo+" rupiah.");
        
    }
    public static void main(String []args){
        Bank person1 = new Bank();
        
        person1.cekSaldo(1000);
        person1.nama("Mahda");
        person1.norek(260894);
        person1.menabung(20000);
        person1.menarik(3000);
        person1.transfer(4000);
    
        
        person1.printStates();
    }
}
Homework :
1.      CreateaclassKalimat is an application programtocount the number oflettersofasentenceand alsocanconvertthe sentenceintoasentencewitha capital letter.
Code :
public class kalimat {
    String x;

   void changeword (String newword){
       x = newword;
       System.out.println("Please write a sentence: \n"+x);
   }
   void counting (){
       System.out.println("The amount of characters are = "+x.length());
   }
   void enlarge (){
       System.out.println(x.toUpperCase());
   }
    
}
public class demokalimat { 
    public static void main(String []args){
        kalimat kalimat1 = new kalimat();
       
        kalimat1.changeword("Teknik Informatika UMS");
        kalimat1.counting();
        kalimat1.enlarge();
    }
}





Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Popular Post

Blogger templates

Pengikut

Diberdayakan oleh Blogger.

Arsip Blog

- Copyright © Mahdalina -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -