-
-
Save lol97/84ec2d40646d82d3b501938466148e26 to your computer and use it in GitHub Desktop.
Abstraction_Code_Example
This file contains hidden or 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
import java.util.Date; | |
public abstract class Mahasiswa { | |
protected long nomorInduk; | |
protected int nilai; | |
protected Date tanggalUjian; | |
public Mahasiswa(long nomorInduk, int nilai, Date tanggalUjian) { | |
super(); | |
this.nomorInduk = nomorInduk; | |
this.nilai = nilai; | |
this.tanggalUjian = tanggalUjian; | |
} | |
public void cetakDataMahasiswa() { | |
System.out.println("Nomor Induk \t : " + this.nomorInduk); | |
System.out.println("Nilai \t\t : " + this.nilai); | |
System.out.println("Tanggal Ujian \t : " + this.tanggalUjian); | |
} | |
public abstract void cetakNilaiAkhir(); | |
} |
This file contains hidden or 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
public class NonRemedial extends Mahasiswa{ | |
public NonRemedial(long nomorInduk, int nilai, Date tanggalUjian) { | |
super(nomorInduk, nilai, tanggalUjian); | |
// TODO Auto-generated constructor stub | |
} | |
@Override | |
public void cetakNilaiAkhir() { | |
System.out.println("Selamat " + super.nomorInduk + " Anda dinyatakan lulus"); | |
} | |
} |
This file contains hidden or 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
import java.util.Date; | |
public class Remedial extends Mahasiswa { | |
public Remedial(long nomorInduk, int nilai, Date tanggalUjian) { | |
super(nomorInduk, nilai, tanggalUjian); | |
} | |
@Override | |
public void cetakNilaiAkhir() { | |
System.out.println("Dengan nilai anda : " + super.nilai + " anda dinyatakan tidak lulus. \nSilahkan hubungi dosen terkait"); | |
} | |
} |
This file contains hidden or 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
import java.util.Date; | |
public class TestMahasiswa { | |
public static void main(String[] args) { | |
NonRemedial johny = new NonRemedial(1001l, 90, new Date(2020, 01, 20)); | |
johny.cetakDataMahasiswa(); | |
johny.cetakNilaiAkhir(); | |
System.out.println("================="); | |
Remedial johnyWish = new Remedial(1002l, 40, new Date(2020, 01, 20)); | |
johnyWish.cetakDataMahasiswa(); | |
johnyWish.cetakNilaiAkhir(); | |
/* | |
Nomor Induk : 1001 | |
Nilai : 90 | |
Tanggal Ujian : Fri Feb 20 00:00:00 ICT 3920 | |
Selamat 1001 Anda dinyatakan lulus | |
================= | |
Nomor Induk : 1002 | |
Nilai : 40 | |
Tanggal Ujian : Fri Feb 20 00:00:00 ICT 3920 | |
Dengan nilai anda : 40 anda dinyatakan tidak lulus. | |
Silahkan hubungi dosen terkait | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment