Tugas Mandiri
2. Buat Program Perpustakaan Mahasiswa
User memasukan data (namaMhs, nim, jumlahbukupinjam, judulbBuku, jenis, biayapinjam)
Program menampilkan :
• (namaMhs, nim, jumlahbukupinjam, judulbBuku, jenis,
biayapinjam
• Total biaya ⇨ dihitung dari penjumlahan biayapinjam per masing
buku
• Jenis ⇨ jenis buku (1. Buku Komputer, 2. Buku Non Komputer)
• biayapinjam ⇨ • ketentuan jika jenis buku komputer, biaya pinjam = 5.000/buku
• ketentuan jika jenis buku non komputer, biaya pinjam = 3.000 /buku
Source Code :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package library;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author hamba allah
*/
public class Library {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner a = new Scanner(System. in );
int nim, jenis, harga_sewa;
int total_harga=0;
String namaMHS;
System.out.println ("===========================================================");
System.out.println ("INPUT DATA PEMINJAM");
System.out.println ("===========================================================");
System.out.print ("Masukkan Nama = ");
namaMHS = a.nextLine();
System.out.print ("Masukkan Nim = ");
nim = a.nextInt();
System.out.print ("Masukan Jumlah Buku = ");
jenis = a.nextInt();
System.out.println ("==========================================================");
//tentukan jumlah arfraynya sebanyak nilai jenis
int jenis_arr[] = new int[jenis];
String judul_arr[] = new String[jenis];
//lakukan pengulangan
for (int b = 0; b < jenis; b++) {
System.out.print("Masukan Judul Buku : ");
judul_arr[b] = a.next();
System.out.print("Jenis Buku : 1. Komputer | 2. Non Komputer \nMasukan pilihan buku : ");
jenis_arr[b] = a.nextInt();
if(jenis_arr[b]==1){//"komputer"){ —---> Letak kesalahan
harga_sewa = 5000;
total_harga = total_harga+harga_sewa;
}else if(jenis_arr[b]==2){//"non komputer"){ —-> Letak kesalahan
harga_sewa = 3000;
total_harga = total_harga+harga_sewa;
}
}
System.out.println("");
System.out.println ("==========================================================");
System.out.println ("DATA PEMINJAM");
System.out.println ("==========================================================");
System.out.println ("Nama Mahasiswa = "+namaMHS);
System.out.println ("Nim Mahasiswa = "+nim);
System.out.println ("Total Biaya Pinjam = "+total_harga);
System.out.println ("==========================================================");
System.out.println ("DAFTAR BUKU YANG DIPINJAM");
System.out.println ("==========================================================");
for (int b = 0;b<jenis;b++){
System.out.println ("Judul Buku Ke : " + b +": " + judul_arr [b]);
}
}
}
Contoh program ketika di jalankan :
di bagian judul_arr[b]); itu kenapa salah ya??
BalasHapus