toString() Method question

Posted by cdominguez13 on Stack Overflow See other posts from Stack Overflow or by cdominguez13
Published on 2010-05-08T00:46:04Z Indexed on 2010/05/08 0:58 UTC
Read the original article Hit count: 234

Filed under:
|

I've been working on this assignemnt here's code:

public class Student
{
 private String fname;
 private String lname;
 private String studentId;
 private double gpa;

 public Student(String studentFname,String studentLname,String stuId,double studentGpa)
 {
  fname     = studentFname;
  lname     = studentLname;
  studentId = stuId;
  gpa       = studentGpa;
 }

 public double getGpa()
 {
  return gpa;
 }

 public String getStudentId()
 {
  return studentId;
 }

 public String getName()
 {
  return lname + ", " + fname;
 }
 public void setGpa(double gpaReplacement)
 {
  if (gpaReplacement >= 0.0 && gpaReplacement <= 4.0)
   gpa = gpaReplacement;
  else
   System.out.println("Invalid GPA! Please try again.");
  System.exit(0);
 }
}

Now I need to create a toString() method that returns a String formatted something like this:

Name: Wilson, Mary Ann
ID number: 12345
GPA: 3.5

© Stack Overflow or respective owner

Related posts about java

Related posts about homework