1 day ago
Thursday, November 26, 2009
Program Menghitung Nilai Akhir ( Constructor Overloading )
Class yang pertama
class tugas
{
private int uts,uas,absen,tugaskul,nil_akhir;
tugas(int uts1,int uas1,int absen1,int tugaskul1)
{
uts=uts1;
uas=uas1;
absen=absen1;
tugaskul=tugaskul1;
}
public int cariakhir()
{
nil_akhir=uts+uas+tugaskul+absen;
return nil_akhir;
}
public String ket()
{
String grade;
if (nil_akhir>=300)
grade="A";
else if(nil_akhir>=250)
grade="B";
else if(nil_akhir>=200)
grade="C";
else if(nil_akhir>=100)
grade="D";
else
grade="E";
return grade;
}
}
Class yang kedua
import java.util.*;
import java.io.*;
class hasil
{
public static void main(String[]args)throws Exception
{
String nama;
int uts1,uas1,tugaskul1,absen1;
Scanner input=new Scanner(System.in);
InputStreamReader key=new InputStreamReader(System.in);
BufferedReader laika=new BufferedReader(key);
System.out.println("Proses Penghitungan Nilai Akhir Mahasiswa");
System.out.println("Matakuliah Pemprograman JAVA ");
System.out.println("-----------------------------------------");
System.out.print("Masukan Nama Mahasiswa :");
nama=laika.readLine();
System.out.print("Masukan Nilai UTS :");
uts1=input.nextInt();
System.out.print("Masukan Nilai UAS :");
uas1=input.nextInt();
System.out.print("Masukan Nilai Tugas :");
tugaskul1=input.nextInt();
System.out.print("Masukan Absensi :");
absen1=input.nextInt();
tugas TUGAS=new tugas(uas1,uts1,absen1,tugaskul1);
System.out.println("------------------------------------------ ");
System.out.println("Nama Mahasiswa :"+nama);
System.out.println("Nilai Akhir Yang Didapat:"+TUGAS.cariakhir());
System.out.println("Grade :"+TUGAS.ket());
}
}
Labels:
kuliah
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment