example class in java

hi pal this time we will membbuat Develop a program using java language, and time

We will try menerapkn wear class, before we implement

souerce his code we should know his syntak class in java,

on this occasion we will try to create a program to find area and volume of the circle.

syntak class in java language

public class NiceGuy {

private string name;

public NiceGuy(String name) {

system.out.println(“Instantion of NiceGuy named “ + name) ;

this.name=name;

}

public void sayHello() {

system.out.println(“Hello Object ……….…!!!“ ) ;

}

public sayHelloOutLoud() {

system.out.println(“HELLLOOOO OBJECT ORIENTED WORLD!!!”) ;

}

Public String getName() {

Return name;

}

}


and that following its example source code for the search area and volume of the circle:

import java.util.Scanner;
public class GlobalMembers
{
public static void main( String[] args )
{
Awal X = new Awal();
X.masukan();
X.proses();
X.keluaran();
}
}
public class Awal
{
public final void masukan()
{
System.out.print(“Masukkan bilangan input : “);
Scanner input = new Scanner(System.in);

System.out.print(“Masukkan nilai r : “);
r = input.nextInt();
}
public final void proses()
{
luas = (float)3.14*r*r;
volume =(float)4/3* (float)3.14*r*r*r;

}
public final void keluaran()
{
System.out.print(“Hasil keluaran untuk LUAS : “);
System.out.print(luas);
System.out.print(“Hasil keluaran untuk VOLUMe: “);
System.out.print(volume);
}
private int r;
private double luas;
private double volume;
}


0 comments:

Twitter Delicious Facebook Digg Favorites More