- Objective Objectives of making this report are :
- Students are able to understand definition and method to create Java Class file.
- Students are able to operate netbeans that used to create Java Class file.
- Theoretical Basis Java Class can be defined as prototype or framework that declare variables and methods of certain objects.
- Tools and Material
- Laptop
- Java Development Kit (JDK 8)
- NetBeans IDE 8.0.2
- Work Steps
- Creating Java Project
- Firstly, JDK 8 and NetBeans IDE 8.0.2 should be installed in the Laptop.
- Opening NetBeans IDE 8.0.2
- Create a project by clicking File > New Project.
- Chosing categories of “Java” and the project of “Java Class Library”, then clicking Next.
- Selecting location of the project placed and giving name “Modul 1” of the project, then clicking Finish.
- Creating Java Packages
- Right click on “Modul 1” project, chosing new > java packages.
- Giving name “Percobaan1” of the java packages, then clicking Finish.
- Creating Java Class
- Right click on “Percobaan1” java packages, chosing new > java class.
- Giving name “Bicycle.java” of the java class, then clicking Finish.
- Typing script of java class.
package Percobaan1;
/**
*
* @author Jhonny
*/
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+", "+"Candance = "+cadance);
}
}
- Making java class file again named “BicycleDemo.java”, then typing script of java class.
package Percobaan1;
/**
*
* @author Jhonny
*/
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();
}
}
The result after running the java class :
- Analysis Based on the experiment above, we need to make 2 classes to Run the file. One class (Bicycle.java) is to make methods or parameters that have some functions. Then the other class (BicycleDemo.java) is to call the methods so that producing output as the results.
- Tasks
- Exercise
- Class that represent object characteristic of Cat. This object has variables (age, color of feather) and functions (meong, birthday). Creating java class named "SifatKucing.java" :
- One of PBO applications that mostly used is Accounting Application. Account Bank is one of matters able as an object in PBO.
- Creating a java class that represent the Bill Object. Variables of them are balance, bill number, and name. The functions are check balance, deposit, withdraw, and transfer. Creating java class named "Keuangan.java" :
- Creating a java class that has a main function to demonstrate the object created. Creating java class named "KeuanganDemo.java" :
- Taking care to Class String in Java Library. Mentioning list of variable and functions that Class String have.
- Homework Making a java class named "Kalimat" that is application program to count amount of vowel of a sentence and also able to chang all of the vowal become capital vowel. Creating java class named "Kalimat.java" :
“A Java Class file is produced by Java Compiler from Java programming language source files (.java files) containing java classes.” (Source : www.en.wikipedia.org)
“NetBeans is a software development platform written in Java. The NetBeans Platform allows applications to be developed from a set of modular software components called modules.” (Source : www.en.wikipedia.org)
package Percobaan1;
/**
*
* @author Jhonny
*/
public class SifatKucing {
int umur;
int tahun;
String warnabulu;
void tahunLahir(int newValue){
tahun = newValue;
}
void umurKucing(){
umur = 2015 - tahun;
}
void warna(String newValue){
warnabulu = newValue;
}
void cetak(){
System.out.println("Kucing berwarna "+ warnabulu +". Ucapkan selamat ulang tahun "+ "umur ke-"+umur );
}
}
/**
*
* @author Jhonny
*/
public class SifatKucing {
int umur;
int tahun;
String warnabulu;
void tahunLahir(int newValue){
tahun = newValue;
}
void umurKucing(){
umur = 2015 - tahun;
}
void warna(String newValue){
warnabulu = newValue;
}
void cetak(){
System.out.println("Kucing berwarna "+ warnabulu +". Ucapkan selamat ulang tahun "+ "umur ke-"+umur );
}
}
Creating java class named "SifatKucingDemo.java" to call java class of "SifatKucing.java".
package Percobaan1;
/**
*
* @author Jhonny
*/
public class SifatKucingDemo {
public static void main (String []args){
SifatKucing cat1 = new SifatKucing();
cat1.tahunLahir(2007);
cat1.umurKucing();
cat1.warna("blue");
cat1.cetak();
}
}
/**
*
* @author Jhonny
*/
public class SifatKucingDemo {
public static void main (String []args){
SifatKucing cat1 = new SifatKucing();
cat1.tahunLahir(2007);
cat1.umurKucing();
cat1.warna("blue");
cat1.cetak();
}
}
The result after running the java class :
package Percobaan1;
/**
*
* @author Jhonny
*/
public class Keuangan {
int saldo;
int noRek;
String name;
void menabung(int newValue){
saldo = newValue;
System.out.println("Anda Menabung sebesar Rp "+saldo);
}
void cekSaldo(){
System.out.println("Saldo anda sebesar Rp "+saldo);
}
void menarik(int newValue){
int sisa = saldo - newValue;
System.out.println("Anda menarik uang sebesar Rp "+newValue);
saldo = sisa;
}
void transfer(int newValue){
int sisa = saldo - newValue;
System.out.println("Anda mentransfer uang sebesar Rp "+ newValue);
saldo = sisa;
}
}
/**
*
* @author Jhonny
*/
public class Keuangan {
int saldo;
int noRek;
String name;
void menabung(int newValue){
saldo = newValue;
System.out.println("Anda Menabung sebesar Rp "+saldo);
}
void cekSaldo(){
System.out.println("Saldo anda sebesar Rp "+saldo);
}
void menarik(int newValue){
int sisa = saldo - newValue;
System.out.println("Anda menarik uang sebesar Rp "+newValue);
saldo = sisa;
}
void transfer(int newValue){
int sisa = saldo - newValue;
System.out.println("Anda mentransfer uang sebesar Rp "+ newValue);
saldo = sisa;
}
}
package Percobaan1;
/**
*
* @author Jhonny
*/
public class KeuanganDemo {
public static void main (String []args){
Keuangan uang1 = new Keuangan();
uang1.menabung(2000000);
uang1.cekSaldo();
uang1.menarik(500000);
uang1.cekSaldo();
uang1.transfer(600000);
uang1.cekSaldo();
}
}
/**
*
* @author Jhonny
*/
public class KeuanganDemo {
public static void main (String []args){
Keuangan uang1 = new Keuangan();
uang1.menabung(2000000);
uang1.cekSaldo();
uang1.menarik(500000);
uang1.cekSaldo();
uang1.transfer(600000);
uang1.cekSaldo();
}
}
The result after running the java class :
package Percobaan1;
/**
*
* @author Jhonny
*/
public class Kalimat {
String sentences;
void tulisKalimat(String newValue){
sentences = newValue;
}
void cetakKalimat(){
System.out.println(sentences);
}
void hitungHuruf(){
int jumlah = sentences.length();
System.out.println("Jumlah karakter pada kalimat = "+jumlah);
}
void hurufBesar(){
sentences = sentences.toUpperCase();
System.out.println(sentences);
}
}
/**
*
* @author Jhonny
*/
public class Kalimat {
String sentences;
void tulisKalimat(String newValue){
sentences = newValue;
}
void cetakKalimat(){
System.out.println(sentences);
}
void hitungHuruf(){
int jumlah = sentences.length();
System.out.println("Jumlah karakter pada kalimat = "+jumlah);
}
void hurufBesar(){
sentences = sentences.toUpperCase();
System.out.println(sentences);
}
}
Creating java class named "KalimatDemo.java" to call java class of "SifatKucing.java".
package Percobaan1;
/**
*
* @author Jhonny
*/
public class kalimatDemo {
public static void main (String []args){
Kalimat kalimat1 = new Kalimat();
System.out.println("Tuliskan Sebuah Kalimat");
kalimat1.tulisKalimat("Teknik Informatika UMS");
kalimat1.cetakKalimat();
kalimat1.hitungHuruf();
kalimat1.hurufBesar();
}
}
/**
*
* @author Jhonny
*/
public class kalimatDemo {
public static void main (String []args){
Kalimat kalimat1 = new Kalimat();
System.out.println("Tuliskan Sebuah Kalimat");
kalimat1.tulisKalimat("Teknik Informatika UMS");
kalimat1.cetakKalimat();
kalimat1.hitungHuruf();
kalimat1.hurufBesar();
}
}
The result after running the java class :
No comments:
Post a Comment