Professional Documents
Culture Documents
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.
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.
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:
}
void printStates(){
System.out.println("my fur color is "+fur_color+","
+"my current age is "+ages);
}
}
2.
}
b. Create class which has man function to demonstrate those object creation.
Solution:
}
}
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: