#Soal
Last active
September 29, 2021 09:13
-
-
Save uluumbch/fe737d3c2715d714f16dd6fa501fd372 to your computer and use it in GitHub Desktop.
program java sederhana dengan constructor, encapsulasi, dan input.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package praktikum4.soal1; | |
public class Buku { | |
private String judul; | |
private String penulis; | |
private int tahun; | |
public Buku(String j, String p, int t) { | |
judul = j; | |
penulis = p; | |
tahun = t; | |
} | |
public void display() { | |
System.out.println("Detail Buku:"); | |
System.out.println("Judul adalah " + judul); | |
System.out.println("Penulis adalah " + penulis); | |
System.out.println("Tahun Terbit adalah " + tahun); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package praktikum4.soal1; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
String judul; | |
String penulis; | |
int tahun; | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Judul: "); | |
judul = sc.nextLine(); | |
System.out.println("Penulis: "); | |
penulis = sc.nextLine(); | |
System.out.println("Tahun terbit: "); | |
tahun = sc.nextInt(); | |
Buku buku = new Buku(judul, penulis, tahun); | |
buku.display(); | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment