Atas permintaan salah satu saudaraku dalam Kristus, sekarang aku mau share juga jawaban untuk latihan 1 dan latihan 2 nya.. :)
Check it out! :)
----------------------------------------------------------------
Soal Latihan 1
Berikut disajikan beberapa data contoh:
void addData(double kodeProp, double tahun, double ipm)
void editDataByProp(double kodeProp, double tahun, double ipm)
void editDataByTahun(double tahun, double kodeProp, double ipm)
double getIPM(double kodeProp, double tahun)
Jawaban Latihan 1
/**----------------------------------------------------------------
*
* @author 11.6725
*/
public class Excercise1 {
static double data[][] = new double[100][3];
static int idx = 0;
public static void main(String[] args) {
addData(11, 1996, 69.40);
System.out.println(getIPM(11, 1996));
editDataByProp(11, 1996, 89.20);
System.out.println(getIPM(11, 1996));
editDataByTahun(1996, 11, 68.28);
System.out.println(getIPM(11, 1996));
}
static void addData(double kodeProp, double tahun, double ipm) {
//parameternya kode propinsi, tahun yang mau diubah, ipm yang baru
for (int i = 0; i < data.length; i++) {
if (data[i][0] == kodeProp && data[i][1] == tahun) {
System.out.println("Data sudah ada, silahkan pakai method edit");
return;
}
}
data[idx][0] = kodeProp;
data[idx][1] = tahun;
data[idx][2] = ipm;
idx++;
}
static void editDataByProp(double kodeProp, double tahun, double ipm) {
int i = 0;
for (; i < data.length; i++) {
if (data[i][0] == kodeProp && data[i][1] == tahun) {
break;
}
}
data[i][2] = ipm;
}
static void editDataByTahun(double tahun, double kodeProp, double ipm) {
int i = 0;
for (; i < data.length; i++) {
if (data[i][0] == kodeProp && data[i][1] == tahun) {
break;
}
}
if (i == 100) {
System.out.println("Data tidak ada");
return;
}
data[i][2] = ipm;
}
static double getIPM(double kodeProp, double tahun) {
int i = 0;
for (; i < data.length; i++) {
if (data[i][0] == kodeProp && data[i][1] == tahun) {
break;
} else {
return 0;
}
}
return data[i][2];
}
}
Soal Latihan 2
Berdasarkan data dan daftar interface
method-method yang ada pada Exercise 1, tuliskan syntax untuk method-method tersebut apabila digunakan array dinamis (linked list) sebagai struktur penyimpanan data, kemudian lengkapi dengan syntax untuk testing.
Jawaban Latihan 2
public class Excercise2 {//class ini dibuat dalam class yang terpisah
static Tabel baru;
public static void main(String[] args) {
addData(11, 1996, 69.40);
System.out.println(getIPM(11, 1996));
editDataByProp(11, 1996, 89.20);
System.out.println(getIPM(11, 1996));
editDataByTahun(1996, 11, 68.28);
System.out.println(getIPM(11, 1996));
}
static void addData(double kodeProp, double tahun, double ipm) {
if (baru == null) {
baru = new Tabel(kodeProp, tahun, ipm);
} else {
Tabel C = baru;
while (C.next != null) {
C = C.next;
}
C.next = new Tabel(kodeProp, tahun, ipm);
}
}
static void editDataByProp(double kodeProp, double tahun, double ipm) {
Tabel C = baru;
while (C != null) {
if (C.code == kodeProp && C.year == tahun) {
C.index = ipm;
return;
}
C = C.next;
}
System.out.println("Ga ada datany");
}
static void editDataByTahun(double tahun, double kodeProp, double ipm) {
Tabel C = baru;
while (C != null) {
if (C.code == kodeProp && C.year == tahun) {
C.index = ipm;
return;
}
C = C.next;
}
System.out.println("Ga ada datanya");
}
static double getIPM(double kodeProp, double tahun) {
Tabel C = baru;
while (C != null) {
if (C.code == kodeProp && C.year == tahun) {
return C.index;
}
C = C.next;
}
return -1;
}
}
class Tabel {
double index;
double year;
double code;
Tabel next;
Tabel(double code,double year,double index){
this.index=index;
this.year=year;
this.code=code;
}
}
done!
Berilah kemuliaan dan puji-pujian dan hormat hanya bagi TUHAN! :)
Shaloom!
***
2 komentar:
ajarin juga dung bikin syntax wira, kurang greget kalo masih lemot pas disuruh bikin program.
Ntar aku privat langsung yaa :D
ajrin bikin syntax nya juga wira, nanti aku privat langsung yaa. rasanya itu kalo disuruh buat program lemoooott bangeett mah aku, atau malah ga jalan error semua. Biar ga greget lagi hahah
Posting Komentar