Minggu, 18 April 2010

Java seqfile3

import java.io.*;

class NilaiMatKul{
String nim;
String nama;
String nilai;

NilaiMatKul(){
}
}

class SeqFile3{

public static void main(String[] args) {

NilaiMatKul rekaman = new NilaiMatKul();

File arsipMatKul;

arsipMatKul = new File("ArsipMatKul.dat");

String kata_cari = "";
try{
System.out.println("masukkan nim yang dicari :");
BufferedReader is = new BufferedReader(
new InputStreamReader(System.in));

kata_cari = is.readLine();
}catch(Exception e){
}

try{
FileReader fr = new FileReader (arsipMatKul);
BufferedReader in = new BufferedReader( fr );

String line = in.readLine();
String[] rekList = line.split("\\s+", 3);
rekaman.nim = rekList[0];
rekaman.nama = rekList[1];
rekaman.nilai = rekList[2];
if(rekaman.nim.compareTo("XXXXXXXX") == 0){
System.out.println("arsip kosong");
}
else{ if(kata_cari.compareTo("XXXXXXXX") == 0){
System.out.println("tidak ditemukan");
}
else{
while((rekaman.nim.compareTo( "XXXXXXXX") != 0)&&(rekaman.nim.compareTo(kata_cari) != 0)){
/* iterasi */
line = in.readLine();
rekList = line.split("\\s+", 3);
rekaman.nim = rekList[0];
rekaman.nama = rekList[1];
rekaman.nilai = rekList[2];
}

if(rekaman.nim.compareTo(kata_cari)== 0){
System.out.println("hasil pencarian :");
System.out.println ("nim : " + rekaman.nim);
System.out.println ("nama : " + rekaman.nama);
System.out.println ("nilai : " + rekaman.nilai);
System.out.println("------------");
}
else{
System.out.println ("tidak ditemukan");
}
}
}
in.close();
}catch(Exception e){
}


}
}