You have been asked to develop a Student class to store, say student information
ID: 3533865 • Letter: Y
Question
You have been asked to develop a Student class to store, say student information. Student class should store the student name, current GPA, address, social security number. Constructor of the Student class should take the student name, social security number, and address as parameters at the time of object creation. The constructor set the GPA to zero. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
setGPA: take the GAP as a parameter and set it at time of object creation
changeAddress: this method takes the address as a parameter and change the current address to the new address.
toString: This method returns the name, address, and GPA.
Explanation / Answer
please rate
// Student.java
class Student {
private String name,ssn,address;
private float gpa;
public Student(String name,String ssn,String address){
this.name = name;
this.ssn = ssn;
this.address = address;
this.gpa = 0.0;
}
public void setGPA(float gpa){
this.gpa = gpa;
}
public String toString(){
return "Name: "+name
+" "+"Address: "+address
+" "+"GPA: "+gpa;
}
// Sample main
public static void main(String[] args){
Student s1("xyz","1234","abc street");
s1.setGPA(3.3);
System.out.println(s1.toString());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.