What is wrong with the following class design? import java.sql.Connection; impor
ID: 3830172 • Letter: W
Question
What is wrong with the following class design?
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
public class Employee {
private Integer id;
private String name;
private Connection con = null;
//getters and setters for above attributes go here.
public boolean validate() {
return id! = null && id > 0 && StringUtils.isNotBlank(name);
}
public void saveEmployee() throws SQLException {
//save Employee to database using SQL
//goes here...
}
publiv boolean validateEmployee() {
//logic to validate an employee
}
}
Explanation / Answer
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
public class Employee {
private Integer id;
private String name;
private Connection con = null;
//getters and setters for above attributes go here.
public boolean validate() {
return id! = null && id > 0 && StringUtils.isNotBlank(name);
}
public void saveEmployee() throws SQLException {
//saving the Employee details to the database using SQL
}
public boolean validateEmployee() {
// your logic to validate an employee
}
}
- only you were missing the public keyword in this statement i.e. publiv boolean validateEmployee() i correct that please try it.
Thanks...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.