You are on page 1of 5

MODUL 1 : CLASS

A. Purpose
1. The students are able to understand how to create an object of class and function.
2. The students are able to understand and use the NetBeans application.

B. Basic Teory
A class is a blueprint of the object. So what is meant here is the Class of an object can be
created or derived from a model of design before. Based on this definition, then a class simply
made only one for one and from the class can be created or derived some objects (tens or
hundreds of) that have the same properties.
This program is used in the making of an application to NetBeans. The NetBeans IDE is a
development environment for an application programmerin the write, compile, and deploy the
program fault finding. NetBeans IDE written in Java, but be able to support other
programming languanges.

C. Tools and Materials


1. Computer with windows operating system.
2. NetBeans IDE 8.0.2 application.
3. Module teaching object-oriented programming.

D. Work Steps
make an object of bicycle in Obeject Oriented Programming by implementation to class of
Bicycle.
1. Open NetBeans IDE 8.0.2
2.
3.

Click on new project


Select Java -> Java Class Library -> Next.

4.

After that, change Project Name as oop and change Project Location as you wish

5.

Right-click Source Packages -> New -> Java Packages. A new window will pop up
and change Packages Name to Modul1.
Make new java class by right-click on Modul1 -> New -> Java Class, set the name
by Bicycle.java and input this scripts :
public class Bicycle {
int cadance;
int speed;
int gear;
void changeCadance (int newValue){
cadance=newValue;
}
void changeGear (int newValue){
gear=newValue;
}
void speedUp (int accelerate){
speed=speed+accelerate;
}
void applyBreak (int decelerate){
speed=speed-decelerate;
}
VoidprintStates(){
System.out.println("Speed="+speed+","+"Gear="+gear+","+"Cadanc
e="+cadance);
}
}
Make a main function of the Bicycle.java, named it as BicycleDemo.java and input this
scripts
public class BicycleDemo {
public static void main(String []args){
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();

6.

7.

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();
8.
9.

}
}
Next run the program by pressing Shift + F6 or click on Run -> Run File.
If the scripts is fine, there will be notification that BUILD SUCCESSFUL (total time: 1
second) as following picture

E. Analysis
Class Bicycle has no main method because this class is only blueprint to create bicycle
object that why we create class bicycleDemo with main method to run class Bicycle.
F. Assignment
1. Practice
1.

Create class which can presenting the characters of cats object. This object has
veriable such as {ages, fur color} and function such as {meong, birthday}
Solution:

public class cat {


int ages;
String fur_color;
void meong(String newValue){
fur_color=newValue;
}
void birthday(int newValue){
ages=newValue+1;

}
void printStates(){
System.out.println("my fur color is "+fur_color+","
+"my current age is "+ages);
}
}
2.

Bank account is one thing which can be an object in OOP.


a. Create class which can presenting those bank account Objects. The variables are
{saldo, no_rek, name} and the functions are {check saldo, saving, drawing,
transfer}.
Solution:

public class bank {


int saldo;
int no_rek;
String name;
void changeName(String value){
name=value;
}
void cekSaldo(){
saldo=saldo;
}
void save(int value){
saldo=saldo+value;
}
void withdraw(int value){
saldo=saldo-value;
}
void transfer(int value){
saldo=saldo-value;
}
void printStates(){
System.out.println("name="+name+"\t\tno_rek="+no_rek
+"\nsaldo="+saldo);
}

}
b. Create class which has man function to demonstrate those object creation.
Solution:

public class bankDemo {


public static void main (String []args){
bank x= new bank();
x.changeName("DK");
x.save(1000);
x.withdraw(100);
x.transfer(500);
x.printStates();

}
}
3.

Take a look at class string located in java library. Mention the variables and functions
of the class string
Solution : in class Bicycle the variables are {cadance, speed, gear} while the
methods are {applyBreak, speedUp, changeGear, printStates,
changeCandance}

2. Homework
create a Sentence which is the class application program to count the number of
letters from a sentence and can change the sentence into a sentence with a capital
letter. The result of execution of the program shall be in accordance with the following
image.
run:
write a sentence
information technology ums
the sentence length is 22 characters
INFORMATION TECHNOLOGY UMS
BUILD SUCCESFUL (total time: 21 seconds)
Solution:

1. Scripts to create object letter


public class letter {
String letters;
void letter(String value){
letters=value;
}
void print(){
System.out.println("the sentences lenght is "+letters.length()
+" characters\n"+letters.toUpperCase());
}
}
2. Scripts to demostrate object
public class letterDemo {
public static void main(String []args){
letter x= new letter();
x.letter("information technology ums");
x.print();
}
}

You might also like