Wednesday, February 15, 2012

Java

Happiness for today is:

Yess! finally i can write in this label again, hehe

Today, although at the very first i'm really lazy to attend my Java Program Class,
i can finish the script of work in my lesson (yup, usually i cannot do that, i'm too slow at computer things :p)

Hihihi,
now i want to show you the Java Script, hehe..maybe if you want to try to at your home, you can copy it from here, :D

--------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;

public class Mahasiswa {
String nama;
int nim;
String alamat;
String ttl;

Mahasiswa(){
nama="";
nim=0;
alamat="";
ttl="";
}

void InputDataMahasiswa(){
Scanner in = new Scanner(System.in);
System.out.println("Masukkan nama Mahasiswa =");
nama = in.nextLine();
System.out.println("Masukkan alamat Mahasiswa =");
alamat = in.nextLine();
System.out.println("Masukkan tanggal lahir Mahasiswa (dd-mm-yyyy)");
ttl = in.nextLine();
System.out.println("Masukkan nim Mahasiswa =");
nim = in.nextInt();
}

void DisplayDataMahasiswa(){
System.out.println("Nama Mahasiswa = "+nama);
System.out.println("Alamat Mahasiswa = "+alamat);
System.out.println("Tanggal lahir Mahasiswa = "+ttl);
System.out.println("NIM Mahasiswa = "+nim);
}

void SetAlamat(String alamatbaru){
alamat=alamatbaru;
}

String GetNama(){
return nama;
}

int GetNIM(){
return nim;
}

int CountUmur(){
int umur;
int tanggal = Integer.parseInt(ttl.substring(6,10));
umur = 2012 - tanggal;
return umur;
}

public static void main (String [] args){
//ciptakan mahasiswa baru namanya sendiri
Mahasiswa Aiti = new Mahasiswa();

Aiti.InputDataMahasiswa();
System.out.println("");
Aiti.DisplayDataMahasiswa();
System.out.println("");
String x=Aiti.GetNama();
System.out.println("Nama = "+x);
System.out.println("");
int y=Aiti.GetNIM();
System.out.println("NIM ="+y);
System.out.println("");
int z=Aiti.CountUmur();
System.out.println("Umur Mahasiswa = "+z);
}
}

0 comments: