Disimpan dalam kelas Mahasiswa.java
import java.util.*;
public class Mahasiswa {
String NIM;
String nama;
String jurusan;
String MK;
public Mahasiswa() {
}
public Mahasiswa(String NIM, String nama, String jurusan) {
this.NIM = NIM;
this.nama = nama;
this.jurusan = jurusan;
}
public void info() {
System.out.println("NIM = "+NIM);
System.out.println("Nama = "+nama);
System.out.println("Jurusan = "+jurusan);
}
}
Disimpan dengan nama file Spp.java
import java.util.Scanner;
public class Spp extends Mahasiswa{
int sppTetap;
int jumlahSks;
public Spp(String Nim, String nama, String jurusan, int sppTetap, int jumlahSks) {
super.nama = nama;
super.NIM = Nim;
super.jurusan = jurusan;
this.sppTetap = sppTetap;
this.jumlahSks = jumlahSks;
}
public int sppVariable(){
return jumlahSks*120000;
}
public int totalSpp(){
return sppTetap+sppVariable();
}
public void info(){
System.out.println("NIM :"+NIM);
System.out.println("Nama : "+nama);
System.out.println("Jurusan :"+jurusan);
System.out.println("Jumlah SKS :"+jumlahSks);
System.out.println("Spp Tetap :"+sppTetap);
System.out.println("Spp Variable :"+sppVariable());
System.out.println("Total :"+totalSpp());
}
public static void main(String[] args){
Scanner masuk = new Scanner(System.in);
System.out.print("Masukkan NIM :");
String nim = masuk.nextLine();
System.out.print("Masukkan Nama : ");
String nama = masuk.nextLine();
System.out.print("Masukkan Jurusan :");
String jurusan = masuk.nextLine();
System.out.print("Masukkan Jumlah SKS :");
int sks = masuk.nextInt();
System.out.print("Masukkan Spp Tetap :");
int spp = masuk.nextInt();
System.out.println("======Hasil=======");
Spp coba = new Spp( nim, nama, jurusan, spp, sks);
coba.info();
System.out.println("======Finish=======");
}
}
Jika ingin Langsung mencoba tanpa mengetik ulang silahkan download file Disini
0 komentar:
Posting Komentar