Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.2 kB
33
Indexable
Never
import java.util.Scanner;
import java.util.Arrays;

public class PerhitunganIndeksPrestasi {
    static Scanner scanner = new Scanner(System.in);

    static String lineBreak(String notation){
        return notation.repeat(70);
    }

    static String centeredText(String text){
        return (" ".repeat((lineBreak(" ").length() - text.length()) / 2)) + text;
    }

    public static void main(String[] args) {
        double[] indeksPrestasi = new double[3];

        System.out.println();
        
        System.out.println(lineBreak("="));
        System.out.println("NPM\t\t: 202343502053");
        System.out.println("Nama\t\t: Ahmad Hidayat");
        System.out.println("Telepon\t\t: 087899967849");
        System.out.println(lineBreak("=") + "\n");
        
        System.out.println(lineBreak("="));
        System.out.println(centeredText("Perhitungan Nilai Indeks Prestasi"));
        System.out.println(lineBreak("=") + "\n");

        for (int i = 0; i < 3; i++) {
            double kehadiran,tugas,uts,uas,rataRata;
            int totalKehadiran = 15, sks;
            double presentaseKehadiran = 0.1F,
                presentaseTugas = 0.2F,
                presentaseUts = 0.3F,
                presentaseUas = 0.4F;

            System.out.println(lineBreak("-"));
            System.out.println(centeredText("Semester-" + (i + 1)));
            System.out.println(lineBreak("-"));
            
            System.out.print("[>] Masukkan Total Kehadiran\t: ");
            kehadiran = scanner.nextInt();

            System.out.print("[>] Masukkan Nilai Tugas\t: ");
            tugas = scanner.nextDouble();

            System.out.print("[>] Masukkan Nilai UTS\t\t: ");
            uts = scanner.nextDouble();

            System.out.print("[>] Masukkan Nilai UAS\t\t: ");
            uas = scanner.nextDouble();

            System.out.print("[>] Masukkan Jumlah SKS\t\t: ");
            sks= scanner.nextInt();

            System.out.println(lineBreak("-"));

            rataRata = ((kehadiran / totalKehadiran) * presentaseKehadiran * 100) + (tugas * presentaseTugas) + (uts * presentaseUts) + (uas * presentaseUas);
            System.out.println("[>] Rata-Rata Nilai\t\t: " + String.format("%.2f", rataRata));

            if(rataRata > 80) indeksPrestasi[i] = 4;
            else if(rataRata > 68) indeksPrestasi[i] = 3;
            else if(rataRata > 50) indeksPrestasi[i] = 2;
            else indeksPrestasi[i] = 1;

            System.out.println("[>] Indeks Prestasi Semester\t: " + String.format("%.2f", indeksPrestasi[i]));
            System.out.println(lineBreak("-") + "\n");
        }

        System.out.println(lineBreak("-"));
        System.out.println(centeredText("Akumulasi Semester-1 s/d Semester-3"));
        System.out.println(lineBreak("-"));
        System.out.println("[>] Indeks Prestasi Kumulatif\t: " + String.format("%.2f", Arrays.stream(indeksPrestasi).sum() / indeksPrestasi.length));
        System.out.println(lineBreak("-") + "\n");
        System.out.println(lineBreak("=") + "\n\n");

        scanner.close();
    }
}
Leave a Comment