refactoring Student class grade field
This commit is contained in:
		
							parent
							
								
									6f04980436
								
							
						
					
					
						commit
						02f3d58660
					
				| @ -4,19 +4,21 @@ import java.math.BigDecimal; | ||||
| import java.sql.Connection; | ||||
| import java.sql.DriverManager; | ||||
| import java.sql.SQLException; | ||||
| import java.util.Date; | ||||
| 
 | ||||
| public class Student { | ||||
| 
 | ||||
|     private BigDecimal grade; //new representation | ||||
|     private StudentGrade grade; //new data representation | ||||
| //    private int grade; //old data representation | ||||
|     private String name;    | ||||
|     private int age; | ||||
|      | ||||
|     public void setGrade(int grade) {         | ||||
|         this.grade = new StudentGrade(grade); | ||||
|     } | ||||
| 
 | ||||
|     public int getGrade() { | ||||
|         return grade.intValue(); //Backward compatibility | ||||
|     } | ||||
|      | ||||
|     public BigDecimal getBigDecimalGrade() { | ||||
|         return grade; | ||||
|         return this.grade.getGrade().intValue(); //int is returned for backward compatibility | ||||
|     } | ||||
|      | ||||
|     public Connection getConnection() throws SQLException { | ||||
| @ -43,4 +45,23 @@ public class Student { | ||||
|         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; | ||||
|         } | ||||
|          | ||||
|      } | ||||
|      | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user