Tugas Enkapsulasi
ENCAPSULATION
Assigment 1
Jawaban :
Class Mahasiswa :
//Irham Iswanda Duhair
//19316018
public class mahasiswa {
//membuat atribut
class
private String NPM;
private String
NAMA;
private String
Alamat;
private String
NoHP;
private String
Email;
private String
Instagram;
public String
getNPM(){
return NPM;
}
public void
setNPM(String NPM){
this.NPM = NPM;
}
public String
getNAMA(){
return NAMA;
}
public void
setNAMA(String NAMA){
this.NAMA =
NAMA;
}
public String
getAlamat(){
return Alamat;
}
public void
setAlamat(String Alamat){
this.Alamat =
Alamat;
}
public String
getNoHP(){
return NoHP;
}
public void
setNoHP(String NoHP){
this.NoHP =
NoHP;
}
public String
getEmail(){
return
Email;
}
public void
setEmail(String Email){
this.Email = Email;
}
public String
getInstagram(){
return
Instagram;
}
public void
setInstagram(String Instagram){
this.Instagram
= Instagram;
}
}
Class main_mahasiswa :
//Irham Iswanda Duhair
//19316018
public class mahasiswa {
//membuat atribut
class
private String NPM;
private String
NAMA;
private String
Alamat;
private String
NoHP;
private String
Email;
private String
Instagram;
public String
getNPM(){
return NPM;
}
public void setNPM(String
NPM){
this.NPM = NPM;
}
public String
getNAMA(){
return NAMA;
}
public void
setNAMA(String NAMA){
this.NAMA =
NAMA;
}
}
Java main class
//Irham Iswanda Duhair
//19316018
import java.util.Scanner;
public class mhs_mahasiswa {
public static void
main(String[] args) {
//membuat
objek
mahasiswa mhs
= new mahasiswa();
Scanner input
= new Scanner (System.in);
//mengisi
atribut untuk objek mhs
System.out.print("Inputkan
NPM : ");
mhs.setNPM(input.nextLine());
System.out.print("Inputkan NAMA
: ");
mhs.setNAMA(input.nextLine());
//membuat
method
System.out.println("NPM
: "+mhs.getNPM());
System.out.println("NAMA
: "+mhs.getNAMA());
}
private static
class Mahasiswa {
public
Mahasiswa() {
}
}
}
Outputnya :
//Irham Iswanda Duhair
//19316018
import java.util.Scanner;
public class mhs_mahasiswa {
public static void
main(String[] args) {
//membuat
objek
mahasiswa mhs
= new mahasiswa();
Scanner input
= new Scanner (System.in);
//mengisi
atribut untuk objek mhs
System.out.print("Inputkan NPM
: ");
mhs.setNPM(input.nextLine());
System.out.print("Inputkan NAMA
: ");
mhs.setNAMA(input.nextLine());
System.out.print("Inputkan
Alamat : ");
mhs.setAlamat(input.nextLine());
System.out.print("Inputkan NoHP
: ");
mhs.setNoHP(input.nextLine());
System.out.print("Inputkan Email
: ");
mhs.setEmail(input.nextLine());
System.out.print("Inputkan Instagram : ");
mhs.setInstagram(input.nextLine());
//membuat
method
System.out.println("NPM
: "+mhs.getNPM());
System.out.println("NAMA
: "+mhs.getNAMA());
System.out.println("Alamat
: "+mhs.getAlamat());
System.out.println("NoHP
: "+mhs.getNoHP());
System.out.println("Email
: "+mhs.getEmail());
System.out.println("Instagram : "+mhs.getInstagram());
}
private static
class Mahasiswa {
public
Mahasiswa() {
}
}
}
Class main_mahasiswa :
//Irham Iswanda
Duhair
//19316018
public class mahasiswa {
//membuat atribut
class
private String NPM;
private String
NAMA;
private String
Alamat;
private String
NoHP;
private String
Email;
private String
Instagram;
public String
getNPM(){
return NPM;
}
public void
setNPM(String NPM){
this.NPM = NPM;
}
public String
getNAMA(){
return NAMA;
}
public void
setNAMA(String NAMA){
this.NAMA =
NAMA;
}
public String
getAlamat(){
return Alamat;
}
public void
setAlamat(String Alamat){
this.Alamat =
Alamat;
}
public String
getNoHP(){
return NoHP;
}
public void
setNoHP(String NoHP){
this.NoHP =
NoHP;
}
public String
getEmail(){
return
Email;
}
public void
setEmail(String Email){
this.Email = Email;
}
public String
getInstagram(){
return
Instagram;
}
public void
setInstagram(String Instagram){
this.Instagram
= Instagram;
}
}
Outputnya :
Nama : Irham Iswanda Duhair
NPM : 19316018
Kelas : TK 19 A
Komentar
Posting Komentar