Create a class called Student as described below: • Fields: name, id, address, cgpa • Methods: public String getName() public void setName(String n) public String getID() public void setID(String i) public String getAddress() public void setAddress(String a) public double getCGPA() public void setCGPA(double c) Write a class called StudentTester to write a main() method: • public static void main(String[] args){
} • Inside the main() method o Create 3 objects/instances of Student called john, mike and carol o Set their fields to some value using the public methods. o Print the information of each Student using System.out.println()
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package JAVA_OBJECT_ORIENTED;
/**
*
* @author ABIR
*/
public class Student {
String name;
String id;
String address;
double cgpa;
public void setName(String n){
name=n;
}
public String getName(){
return name;
}
public void setID(String i){
id=i;
}
public String getID(){
return id;
}
public void setAddress(String a){
address=a;
}
public String getAddress(){
return address;
}
public void setCGPA(double c){
cgpa=c;
}
public double getCGPA(){
return cgpa;
}
public String toString(){
return "Name = "+name+" id = "+id+" address= "+address+" cgpa = "+cgpa;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package JAVA_OBJECT_ORIENTED;
/**
*
* @author ABIR
*/
public class StudentTester {
public static void main(String[] args) {
Student john=new Student();
Student mike=new Student();
Student carol=new Student();
john.setName("JOHN");
john.setID("55");
john.setAddress("Dhaka");
john.setCGPA(3.3);
mike.setName("MIKE");
mike.setID("12301019");
mike.setAddress("Budapest");
mike.setCGPA(2.76);
carol.setName("JOHN");
carol.setID("23");
carol.setAddress("Spain");
carol.setCGPA(2.3);
System.out.println(john.getName()+" "+ john.getID()+" "+john.getAddress()+" "+john.getCGPA());
System.out.println(mike.getName()+" "+ mike.getID()+" "+mike.getAddress()+" "+mike.getCGPA());
System.out.println(carol.getName()+" "+ carol.getID()+" "+carol.getAddress()+" "+carol.getCGPA());
System.out.println(john);
System.out.println(mike);
System.out.println(carol);
}
}