Laporan Praktikum Algoritma & Struktur Data Bab 1 Fakultas Ilmu Komputer 2017/2018
Soal :
Source code :
Class ASDBab1ReviewOOP
Class Book
Download the file here
Soal :
Buatlah program yang dapat merepresentasikan
sebuah buku dan atributnya, dimana pada program tersebut dapat mengetahui biaya
sewa dan biaya denda dari buku tersebut!
Source code :
Class ASDBab1ReviewOOP
public class ASDBab1ReviewOOP { public static void main(String[] args) { Scanner sausan = new Scanner(System.in); System.out.print("Genre ? "); String genre = sausan.nextLine(); System.out.print("Title ? "); String title = sausan.nextLine(); System.out.print("Day ? "); int day = sausan.nextInt(); Book rent = new Book(); System.out.print("Late ? "); String late = sausan.next(); sausan.nextLine(); if (late.equalsIgnoreCase("y")){ System.out.print("Day ? "); int ld = sausan.nextInt(); rent.show(genre, title); System.out.println("You rent it for "+day+" day so the fee is IDR "+rent.setRent(day)+". And you must pay IDR "+rent.setLate(ld)+" for late fees"); } else { rent.show(genre,title); System.out.println("You rent it for "+day+" day so the fee is IDR "+rent.setRent(day)); } } }
Class Book
package asdmodul1; public class Bab1Book { private String genre, title; private int rent = 5000, late = 500, tr, tl; public int setRent(int c) { tr = c * rent; return tr; } public int setLate(int c) { tl = c * late; return tl; } public void show(String a, String b) { genre = a; title = b; System.out.println("You rent " + a + " book entitled " + b); } }
Download the file here
0 comments:
Posting Komentar