BAB : CLASS DAN OBJECT
NAMA : MOH. ARIF ANDRIAN
NIM : 156150600111002
TANGGAL : 02032016
ASISTEN : - REZA SAPURTA
- REZKY DERMAWAN A. DEFINISI MASALAH
Buatlah sebuah sistem sederhana yang menyerupai Sistem Informasi Akademik Mahasiswa SIAM, dengan ketentuan user menginputkan Nama, Nim, IP serta
jurusan. Selain itu mahasiswa juga dapat memasukkan kode Mata kuliah, Nama Mata kuliah
dan jumlah sks mata kuliah tersebut. Jumlah sks yang di ambil harus sesuai dengan IP yang didapat pada semester lalu. Buat skenario dengan banyak mahasiswa minimal 3
orang.
B. SOURCE CODE
Class Siam.java
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 package Praktikum1;
public class Siam { private String nama, nim, jurusan, kodeTerambil;
private double ip; String[] namaMk = new String[10];
String[] kode = new String[10]; int[] sks = new int[10];
int sksMaks = 0; int[] hasil = new int[100];
int index = 0; membuat method bernama setNama dengan parameter String
public void setNamaString s { nama = s;
} membuat method bernama setNim dengan parameter String
public void setNimString s { nim = s;
} membuat method bernama setJurusan dengan parameter String
public void setJurusanString s { jurusan = s;
} membuat method bernama setIp dengan parameter double
public void setIpdouble d { ip = d;
} membuat method bernama kodeMk dengan instruksi didalamnya
public void kodeMk { for int i = 0; i kode.length; i++ {
30 31
32 33
34 35
36 37
38 39
40 41
42 43
44 45
46 47
48 49
50 51
52 53
54 55
56 57
58 59
60 61
62 63
64 65
66 67
68 69
70 71
72 73
74 75
76 if i == 9 {
kode[i] = MK0 + i + 1; } else {
kode[i] = MK00 + i + 1; }
} }
membuat method yang menginisialisasi array namaMk public void namaMatkul {
namaMk[0] = Matematika Komputasi; namaMk[1] = Pemrograman Basis Objek;
namaMk[2] = Arsitektur Organisasi Komputer; namaMk[3] = Teori Belajar dan Pembelajaran;
namaMk[4] = Bahasa Inggris; namaMk[5] = Sistem Operasi;
namaMk[6] = Sistem Digital; namaMk[7] = Perkembangan Peserta Didik;
namaMk[8] = Filsafat Ilmu Pendidikan; namaMk[9] = Pendidikan Agama;
} membuat method yang menginisialisasi array sks
public int besarSKS { sks[0] = 4;
sks[1] = 5; sks[2] = 4;
sks[3] = 4; sks[4] = 3;
sks[5] = 4; sks[6] = 3;
sks[7] = 4; sks[8] = 3;
sks[9] = 3; return 0;
} membuat method yang menampilkan sebuah output
public void header { kodeMk;
namaMatkul; besarSKS;
System.out.printlnDaftar mata kuliah yang dapat diambil :;
System.out.printf-2s -5s -10s -47s -2s \n, , No., KODE, NAMA MATA KULIAH, JUMLAH SKS;
for int i = 0; i sks.length; i++ { System.out.printf-2s -5s -10s -47s -2s \n,
, i + 1, kode[i], namaMk[i], sks[i]; }
} membuat method untuk menentukan jumlah SKS yang dapat
diambil public int setSks {
77 78
79 80
81 82
83 84
85 86
87 88
89 90
91 92
92 94
95 96
97 98
99 10
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
11 11
1 11
if ip = 1 { sksMaks = 12;
} else if ip = 2 { sksMaks = 15;
} else if ip = 3 { sksMaks = 18;
} else if ip = 4 { sksMaks = 24;
} else { System.out.printlnERROR : IP maksimal adalah 4;
System.exit0; }
return sksMaks; }
membuat method yang menampilkan pesan error public String setKodeAmbilString kodeTerambil {
if inputGandakodeTerambil == true { System.out.printlnERROR : Mata kuliah sudah
dipilih; } else if sksMaks sksFromKodekodeTerambil {
System.out.printlnERROR : Tidak bisa melebihi jumlah maksimal SKS;
System.out.println Sisa SKS adalah + sksMaks;
} else { this.kodeTerambil = kodeTerambil;
proseskodeTerambil; }
return kodeTerambil; }
public String getNama { return nama;
} method untuk mengembalikan or memanggil nilai nim
public String getNim { return nim;
} method untuk mengembalikan or memanggil nilai jurusan
public String getJurusan { return jurusan;
} method untuk mengembalikan or memanggil nilai ip
public double getIp { return ip;
} method untuk mengembalikan or memanggil nilai sksMaks
public int getSKSMaks { return sksMaks;
} method untuk menghitung sisa SKS yang dpt diambil
public int prosesString kodeTerambil {
2 11
3 11
4 11
5 11
6 11
7 11
8 11
9 12
12 1
12 2
12 3
12 4
12 5
12 6
12 7
12 8
12 9
13 13
1 13
2 13
3 13
4 13
5 13
6 13
7 if kodeTerambil.equalskode[0] {
sksMaks -= sks[0]; hasil[index] = 0;
index++; } else if kodeTerambil.equalskode[1] {
sksMaks -= sks[1]; hasil[index] = 1;
index++; } else if kodeTerambil.equalskode[2] {
sksMaks -= sks[2]; hasil[index] = 2;
index++; } else if kodeTerambil.equalskode[3] {
sksMaks -= sks[3]; hasil[index] = 3;
index++; } else if kodeTerambil.equalskode[4] {
sksMaks -= sks[4]; hasil[index] = 4;
index++; } else if kodeTerambil.equalskode[5] {
sksMaks -= sks[5]; hasil[index] = 5;
index++; } else if kodeTerambil.equalskode[6] {
sksMaks -= sks[6]; hasil[index] = 6;
index++; } else if kodeTerambil.equalskode[7] {
sksMaks -= sks[7]; hasil[index] = 7;
index++; } else if kodeTerambil.equalskode[8] {
sksMaks -= sks[8]; hasil[index] = 8;
index++; } else if kodeTerambil.equalskode[9] {
sksMaks -= sks[9]; hasil[index] = 9;
index++; } else {
System.out.printlnKode salah; }
return sksMaks; }
method untuk menentukan nilai sks dari input kode matkul public int sksFromKodeString kodeTerambil {
int pilihSks = 0; if kodeTerambil.equalskode[0] {
pilihSks = sks[0]; } else if kodeTerambil.equalskode[1] {
13 8
13 9
14 14
1 14
2 14
3 14
4 14
5 14
6 14
7 14
8 14
9 15
15 1
15 2
15 3
15 4
15 5
15 6
15 7
15 8
15 9
16 16
1 16
2 16
pilihSks = sks[1]; } else if kodeTerambil.equalskode[2] {
pilihSks = sks[2]; } else if kodeTerambil.equalskode[3] {
pilihSks = sks[3]; } else if kodeTerambil.equalskode[4] {
pilihSks = sks[4]; } else if kodeTerambil.equalskode[5] {
pilihSks = sks[5]; } else if kodeTerambil.equalskode[6] {
pilihSks = sks[6]; } else if kodeTerambil.equalskode[7] {
pilihSks = sks[7]; } else if kodeTerambil.equalskode[8] {
pilihSks = sks[8]; } else if kodeTerambil.equalskode[9] {
pilihSks = sks[9]; } else {
System.out.printlnERROR : Kode salah. Mata kuliah tidak tersedia;
} return pilihSks;
} method untuk menampilkan pesan kode sudah dimasukkan
public boolean inputGandaString kodeTerambil { boolean tentukan = false;
for int i = 0; i index; i++ { if kodeTerambil.equalsIgnoreCasekode[hasil[i]]{
tentukan = true; } else {
tentukan = false; }
} return tentukan;
} method untuk menampilkan hasil final pilihan SKS
public void
output { System.out.println=====================================
=====================================; System.out.printf-2s -5s -10s -47s -2s \n, ,
No., Kode, Nama Mata Kuliah, SKS; System.out.println-----------------------------------
---------------------------------------; int jumS = 0;
for int i = 0; i index; i++ { System.out.printf-2s -5s -10s -47s -2s \n,
, i + 1, kode[hasil[i]], namaMk[hasil[i]], sks[hasil[i]]; jumS += sks[hasil[i]];
} System.out.println-----------------------------------
---------------------------------------;
3 16
4 16
5 16
6 16
7 16
8 16
9 17
17 1
17 2
17 3
17 4
17 5
17 6
17 7
17 8
17 9
18 18
1 18
2 18
3 18
4 18
5 18
6 18
7 18
8 System.out.printf-2s -5s -10s -47s -2s \n, , , ,
Jumlah SKS : , jumS; int maks = jumS + sksMaks;
System.out.printf-2s -5s -10s -47s -2s \n, , , , Jumlah maksimal SKS : , maks;
} }
18 9
19 19
1 19
2 19
3 19
4
19 5
19 6
19 7
19 8
19 9
20 20
1 20
2 20
3 20
4 20
5 20
6 20
7 20
8 20
9 21
21 1
21 2
21
3 21
4 21
5 21
6 21
7
21 8
21 9
22
22 1
22 2
22 3
22 4
22 5
Class MainSiam.java
1 2
3 4
5 6
7 8
9 1
1 1
1 2
1 package Praktikum1;
import java.io.; public class MainSiam {
public static void mainString[] args throws IOException { BufferedReader in = new BufferedReadernew
InputStreamReaderSystem.in; String nama, nim, prodi, kode;
double ip; String pilih = Y;
Siam[] mhs = new Siam[3]; for int j = 0; j 3; j++ {
mhs[j] = new Siam; mhs[j].header;
System.out.println; System.out.println;
System.out.printlnMahasiswa ke- + j + 1; System.out.println;
System.out.printNama\t: ;
3 1
4 1
5 1
6 1
7 1
8 1
9 2
2 1
2 2
2 3
2 4
2 5
2 6
2 8
2 9
3 3
1 3
2 3
3 3
4 3
5 3
6
3 7
3 8
nama = in.readLine; mhs[j].setNamanama;
System.out.printNIM\t: ; nim = in.readLine;
mhs[j].setNimnim; System.out.printJurusan\t: ;
prodi = in.readLine; mhs[j].setJurusanprodi;
System.out.printIP\t: ; ip = Double.parseDoublein.readLine;
mhs[j].setIpip; mhs[j].setSks;
System.out.println; do {
System.out.printMasukkan kode mata kuliah :; kode = in.readLine;
mhs[j].setKodeAmbilkode; if mhs[j].getSKSMaks == 0 {
System.out.printJumlah maksimal SKS sudah terpenuhi. Tetap di sini? Yn : ;
} else { System.out.printTambah mata kuliah?
Yn : ; }
pilih = in.readLine; } while pilih.equalsIgnoreCasen;
System.out.println; System.out.println============================================
==============================; System.out.println;
System.out.printlnNama\t\t: + mhs[j].getNama; System.out.printlnNIM\t\t: + mhs[j].getNim;
System.out.printlnJurusan\t\t: + mhs[j].getJurusan;
System.out.printlnIP\t\t: + mhs[j].getIp; System.out.println;
mhs[j].output; System.out.printf-2s -5s -10s -47s -2s
\n\n\n\n,
, ,
, ======================================================, ;
} }
}
3 9
4 4
1 4
2 4
3
4 4
4 5
4 6
4 7
4 8
4 9
5 5
1
5 2
5 3
5 4
C. PEMBAHASAN