In: Computer Science
In Java create a simple class named student with the following properties:
id
age
gpa
credit hours accomplished
Also, create the following methods:
Constructors
Getters and setters
public class student {
private int id;
private int age;
private double gpa;
private int creditHours;
//default constructor
public student() {
}
//parameterized constructor
public student(int id, int age, double gpa, int
creditHours) {
super();
this.id = id;
this.age = age;
this.gpa = gpa;
this.creditHours =
creditHours;
}
//getters and setters
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public int getCreditHours() {
return creditHours;
}
public void setCreditHours(int creditHours) {
this.creditHours =
creditHours;
}
public static void main(String[] args) {
// a simple main to show
functioning of getter and setter
student s = new student(1, 12, 7.8,
12);
System.out.println(s.getAge());
s.setAge(13);
System.out.println(s.getAge());
}
}