Sebelumnya kita lihat:
Tampilan Input
Tampilan Output
Rata rata diproses dengan perhitungan : (10% x Nilai Absen ) + (20% x Nilai Tugas) + (30% x Nilai UTS) + (40% x Nilai UAS)
Listing Program
package lat_scanner;
import java.util.Scanner;
public class Lat_Scanner {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
//deklarasi objek baru
String nama;
int absen, uts, uas, tugas, nim;
double jml;
System.out.print("Masukkan Nama Anda : ");
nama = input.nextLine();
System.out.print("Masukkan NIM Anda : ");
nim = input.nextInt();
System.out.print("Masukkan Nilai Absen : ");
absen = input.nextInt();
System.out.print("Masukkan Nilai Tugas : ");
tugas = input.nextInt();
System.out.print("Masukkan Nilai UTS : ");
uts = input.nextInt();
System.out.print("Masukkan Nilai UAS : ");
uas = input.nextInt();
jml=(0.1*absen+0.2*tugas+0.3*uts+0.4*uas);
System.out.println("\n\nPROGRAM NILAI MAHASISWA");
System.out.println("-----------------------");
System.out.println("NIM : "+nim);
System.out.println("Nama Mahasiswa : "+nama);
System.out.println("Nilai Absen : "+absen);
System.out.println("Nilai Tugas : "+tugas);
System.out.println("Nilai UTS : "+uts);
System.out.println("Nilai UAS : "+uas);
System.out.println("-----------------------");
System.out.println("Rata - Rata : "+jml);
}
}
Kedua, membuat class dengan nama "Class_Scanner"
package lat_scanner;
import java.util.Scanner;
public class Class_Scanner {
public String nama;
public double jml;
public int nim, absen, tugas, uts, uas;
Scanner input = new Scanner (System.in);
public String getnama(){
return nama;
}
public int nim(){
return (nim);
}
public void inputScanner(){
System.out.print("Masukkan Nama Anda : ");
nama = input.nextLine();
System.out.print("Masukkan NIM Anda : ");
nim = input.nextInt();
System.out.print("Masukkan Nilai Absen : ");
absen = input.nextInt();
System.out.print("Masukkan Nilai Tugas : ");
tugas = input.nextInt();
System.out.print("Masukkan Nilai UTS : ");
uts = input.nextInt();
System.out.print("Masukkan Nilai UAS : ");
uas = input.nextInt();
}
public int getabsen(){
return (absen);
}
public int gettugas(){
return (tugas);
}
public int getuts(){
return (uts);
}
public int getuas(){
return (uas);
}
public double rata(){
return ((10/100*absen)+(20/100*tugas)+(30/100*uts)+(40/100*uas));
}
}
Dan yang terakhir kita membuat class dengan nama "Aksi_Scanner"
package lat_scanner;
import java.util.Scanner;
public class Aksi_Scanner {
public static void main(String args[])
{
Class_Scanner scan = new Class_Scanner();
scan.inputScanner();
System.out.println("\n\nPROGRAM NILAI MAHASISWA");
System.out.println("-------------------------");
System.out.println("NIM : "+scan.nim());
System.out.println("Nama Mahasiswa : "+scan.getnama());
System.out.println("Nilai Absen : "+scan.getabsen());
System.out.println("Nilai Tugas : "+scan.gettugas());
System.out.println("Nilai UTS : "+scan.getuts());
System.out.println("Nilai UAS : "+scan.getuas());
System.out.println("-------------------------");
System.out.println("Rata - Rata : "+scan.rata());
}
}
NB : Untuk Running kita tekan F6 ( Shift+F6 ) di Class Aksi_Scanner
SELAMAT MENCOBA...!!!
Tidak ada komentar:
Posting Komentar