refactoring Student class grade field

This commit is contained in:
m.raheem 2019-08-24 13:46:39 +02:00
parent 6f04980436
commit 02f3d58660

View File

@ -4,19 +4,21 @@ import java.math.BigDecimal;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date;
public class Student { public class Student {
private BigDecimal grade; //new representation private StudentGrade grade; //new data representation
// private int grade; //old data representation
private String name; private String name;
private int age; private int age;
public int getGrade() { public void setGrade(int grade) {
return grade.intValue(); //Backward compatibility this.grade = new StudentGrade(grade);
} }
public BigDecimal getBigDecimalGrade() { public int getGrade() {
return grade; return this.grade.getGrade().intValue(); //int is returned for backward compatibility
} }
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
@ -43,4 +45,23 @@ public class Student {
return this.name; return this.name;
} }
private class StudentGrade {
private BigDecimal grade = BigDecimal.ZERO;
private Date updatedAt;
public StudentGrade(int grade) {
this.grade = new BigDecimal(grade);
this.updatedAt = new Date();
}
public BigDecimal getGrade() {
return grade;
}
public Date getDate() {
return updatedAt;
}
}
} }