Sabtu, 17 April 2010

Cpp seqqfile6

import java.io.*;

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

NilaiMatKul(){
}
}

class SeqFile6{

public static void main(String[] args) {

NilaiMatKul rekaman1 = new NilaiMatKul();

NilaiMatKul rekaman2 = new NilaiMatKul();

File arsipMatKul1;

File arsipMatKul2;

File fArsipMatKul;

arsipMatKul1 = new File("ArsipMatKul1.dat");

arsipMatKul2 = new File("ArsipMatKul2.dat");

fArsipMatKul = new File("ArsipMatKul4.dat");

if(!fArsipMatKul.exists()){
try{
new File("ArsipMatKul4.dat").
createNewFile();
}catch(Exception e){
}
}

try{
PrintWriter arsipMatKul3 = new PrintWriter(new FileWriter("ArsipMatKul4.dat", false));

System.out.println("mulai proses menyalin file");


FileReader fr1 = new FileReader (arsipMatKul1);
BufferedReader in1 = new BufferedReader( fr1 );

FileReader fr2 = new FileReader (arsipMatKul2);
BufferedReader in2 = new BufferedReader( fr2 );

String line1 = in1.readLine();

String[] rekList = line1.split("\\s+", 3);
rekaman1.nim = rekList[0];
rekaman1.nama = rekList[1];
rekaman1.nilai = rekList[2];

String line2 = in2.readLine();

rekList = line2.split("\\s+", 3);
rekaman2.nim = rekList[0];
rekaman2.nama = rekList[1];
rekaman2.nilai = rekList[2];
while((rekaman1.nim.compareTo("XXXXXXXX") != 0)&&( rekaman2.nim.compareTo("XXXXXXXX") != 0)){ if(rekaman1.nim.compareTo(rekaman2.nim) < 1){
arsipMatKul3.println(
rekaman1.nim + " " + rekaman1.nama + " " + rekaman1.nilai);

line1 = in1.readLine();
rekList = line1.split("\\s+", 3);
rekaman1.nim = rekList[0];
rekaman1.nama = rekList[1];
rekaman1.nilai = rekList[2];
}
else{
arsipMatKul3.println(
rekaman2.nim + " " + rekaman2.nama + " " + rekaman2.nilai);

line2 = in2.readLine();
rekList = line2.split("\\s+", 3);
rekaman2.nim = rekList[0];
rekaman2.nama = rekList[1];
rekaman2.nilai = rekList[2];

}
}

while(rekaman1.nim.compareTo("XXXXXXXX") != 0){
arsipMatKul3.println(
rekaman1.nim + " " + rekaman1.nama + " " + rekaman1.nilai);

line1 = in1.readLine();
rekList = line1.split("\\s+", 3);
rekaman1.nim = rekList[0];
rekaman1.nama = rekList[1];
rekaman1.nilai = rekList[2];
}

while(rekaman2.nim.compareTo("XXXXXXXX") != 0){
arsipMatKul3.println(
rekaman2.nim + " " + rekaman2.nama + " " + rekaman2.nilai);

line2 = in2.readLine();
rekList = line2.split("\\s+", 3);
rekaman2.nim = rekList[0];
rekaman2.nama = rekList[1];
rekaman2.nilai = rekList[2];
}

arsipMatKul3.println(
"XXXXXXXX XXX X");

arsipMatKul3.flush();
in1.close();
in2.close();
}catch(Exception e){
}
System.out.println("proses menyalin file selesai");

}
}