* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uts1;
/**
*
* @author Acer 4745g
*/
public class Student {
private String name;
private String email;
private String nim;
private double ipk;
public Student(){
}
public Student (String name, String email, String nim,double ipk){
this.name=name;
this.email= email;
this.name=nim;
this.ipk=ipk;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public String getEmail(){
return email;
}
public void setEmail(String email){
this.email=email;
}
public String getNim(){
return nim;
}
public void setNim(String nim){
this.nim=nim;
}
public double getIpk(){
return ipk;
}
public void setIpk(double ipk) throws Exception{
if(ipk >= 0.0 && ipk <=4.0){
this.ipk=ipk;
System.out.println("input berupa angka :"+ipk);
}
else{
System.out.println("nilai tidak sesuai");
}
}
public void setIpk(String ipk){
try {
setIpk(Double.parseDouble(ipk));
System.out.println("input berupa String :"+ipk);
}catch (Exception ex){
System.out.println("error:"+ex.getMessage());
}
}/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uts1;
/**
*
* @author Acer 4745g
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Student test= new Student();
test.setIpk("3.00");
// test.setIpk("3.0");
test.setIpk("5.00");
// test.setIpk("6.0");
// test.setIpk("tiga");
}
}
kelas main
Tidak ada komentar:
Posting Komentar