Selasa, 17 Maret 2015

MODUL 1

CLASS


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
·         Java Development Kit (JDK)

D.    Work Step
This is some implementation of bicycle class :

public class bicycle {
    int candance;
    int speed;
    int gear;
   
    void changeCandance (int newValue){
        candance = 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+", "+"Candance = "+candance);
    }
}
Class Bicycle above do not have a main function (main method) because this class is not an application program but merely a blueprint to create. To run an application program, it must be given a class that has a primary function.

public class BicycleDemo {
    public static void main(String []args){
        bicycle bike1 = new bicycle();
        bicycle bike2 = new bicycle();
       
        bike1.changeCandance(50);
        bike1.speedUp(10);
        bike1.changeGear(2);
        bike1.printStates();
       
        bike2.changeCandance(50);
        bike2.speedUp(10);
        bike2.changeGear(2);
        bike2.changeCandance(40);
        bike2.speedUp(10);
        bike2.changeGear(3);
        bike2.printStates();
    }
}

Execute :

run:
Speed = 10, Gear = 2, Candance = 50
Speed = 20, Gear = 3, Candance = 40
BUILD SUCCESSFUL (total time: 2 seconds)

E.     Analysis
To make class we must have blueprint and main method to run some java program.
Ern4t
F.      Assignment
1.      Create a class that can present the properties of the object cat. This object has the form {umur, warna bulu} and function of the form {meow, ulang tahun}.
Code :
public class cat {
    String warnabulu;
    int umur;
   
    void changeWarnabulu (String colour){
        warnabulu = colour;
    }
           
    void changeUmur (int newValue){
        umur = newValue;
    }
    void printState(){
        System.out.println("WarnaBulu = "+warnabulu+", "+"meong, "+"Ulang tahun ke = "+umur);
    }
}
public class catDemo {
    public static void main(String []args){
        cat cat1 = new cat();
        cat cat2 = new cat();
       
        cat1.changeWarnabulu("White");
        cat1.changeUmur(2);
        cat1.printState();
       
        cat2.changeWarnabulu("Black");
        cat2.changeUmur(1);
        cat2.printState();
    }
}
Execute :
run:
WarnaBulu = White, meong, Ulang tahun ke = 2
WarnaBulu = Black, meong, Ulang tahun ke = 1
BUILD SUCCESSFUL (total time: 2 seconds)

2.      One of the application PBO is a very common form of financial applications. Bank Account is one of the things that can be used as an object in the PBO.
                                                              i.      Create a class that can present the account object. variables of this object is {saldo, no rek, nama} and function of the 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 ObjectRekening {
    int saldo;
    int noRek;
    int sisa;
    int transfer;
    int menabung;
    int checksaldo;
    String nama;
   
    void changesaldo (int newValue){
        saldo = newValue;
        System.out.println("Saldo Anda = "+saldo);
    }
    void changenorek (int newValue){
        noRek = newValue;
        System.out.println("Nomer Rekening Anda = "+noRek);
    }
    void changenama (String name){
        nama = name;
        System.out.println("Nama Anda = "+nama);
    }
    void changetransfer (int newValue){
        transfer = saldo - newValue;
        checksaldo = transfer;
        System.out.println("Dana yang Di Transfer = "+newValue);
    }
    void changemenabung (int newValue){
        menabung = saldo + newValue;
        checksaldo = menabung;
        System.out.println("Anda Menabung = "+newValue);
    }
    void checksaldo (){
        saldo = checksaldo;
        System.out.println("Saldo Anda = "+saldo);
    }
   
}
public class ObjectRekeningDemo {
    public static void main(String []args){
        ObjectRekening Rekening1 = new ObjectRekening();
       
        Rekening1.changenama("Fauzan");
        Rekening1.changesaldo(10000);
        Rekening1.changenorek(123456789);
        Rekening1.changemenabung(25000);
        Rekening1.checksaldo();
        Rekening1.changetransfer(15000);
        Rekening1.checksaldo();
        Rekening1.changemenabung(5000);
        Rekening1.checksaldo();
        Rekening1.changetransfer(2000);
        Rekening1.checksaldo();
    }
}
Execute :
run:
Nama Anda = Fauzan
Saldo Anda = 10000
Nomer Rekening Anda = 123456789
Anda Menabung = 25000
Saldo Anda = 35000
Dana yang Di Transfer = 15000
Saldo Anda = 20000
Anda Menabung = 5000
Saldo Anda = 25000
Dana yang Di Transfer = 2000
Saldo Anda = 23000
BUILD SUCCESSFUL (total time: 0 seconds)

3.      Note the string class is in the java library. specify a list of variables and functions held by the string class.


Homework :
1.      Create a class Kalimat is an application program to count the number of letters of a sentence and also can convert the sentence into a sentence with a capital letter.
Code :
public class Kalimat {
    String w;

   void changeword (String newword){
       w = newword;
       System.out.println("Your words = "+w);
   }
   void counting (){
       System.out.println("The Amount Character = "+w.length());
   }
   void enlarge (){
       System.out.println(w.toUpperCase());
   }
}
public class DemoKalimat {
    public static void main(String []args){
        Kalimat kalimat1 = new Kalimat();
       
        kalimat1.changeword("Teknik Informatika UMS");
        kalimat1.counting();
        kalimat1.enlarge();
    }
}

Execute :

run:
Your words = Teknik Informatika UMS
The Amount Character = 22
TEKNIK INFORMATIKA UMS
BUILD SUCCESSFUL (total time: 0 seconds)

Minggu, 05 Oktober 2014

6 Step of Program Execution





1.      (Instruction Making)
The first step , the PC contains the numbers 300. where the 300 numbers come from the first address given command of the memory . Then , the command in hexadecimal form (1940 ) entered and stored in the IR so that the value of IR into 1940 .

2.      (Instruction Execution)
In the 2nd Step, after IR contains the value 1940, it resulted in the AC must be filled with the value at address 940. Why 940 choosen ? Not another address such as 450 , 560 or another , it happens because the value of the AC is to be filled using the value of the IR itself. In other words , the value of the AC will adjust the value contained in the IR because we will take 3 hexadecimal digits contained in the IR . In this example the value of the IR 1940, then the existing values ​​are taken at address 1940 ( 940 ).

3.      (Instruction Making)
After the contents of the PC plus one (incremented) So that it becomes 301 means that the next instruction to be fetched from memory and executed is located in memory address 301 , the instruction with code 5941. Then , the order of the address stored in the memory 301 so that the value of the IR 5941 and IR -value PC worth 301 .

4.      (Instruction Execution)
The fourth step , the AC will take the value contained at the address 941. However , the AC does not change as the PC and IR , AC will ditambkan with the previous value 0003. So the value of the AC current into 0005 ( 0002 were found in step 3 + 0003 contained in the second step ) . Why not change the absolute AC or added , because the AC own the temporary storage so that its value will be added until the program exits .



5.      (Instruction Making)
After that PC plus one , then it becomes 302 , so that the next instruction is retrieved from memory address 302 is 2941 , then the command in hexadecimal form ( 2941 ) of 302 memory address entered and stored in the IR so that the value of IR into 2941 and the PC.

6.      (Instruction Execution)
The final step is to move the AC value into memory address 941. 2941 mean is the command to copy the contents of the accumulator to memory address 941 .