I have this code so far:

//Carolina Dominguez
//Assignment 7

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()
    {
        String name = lname + ", " + fname;
        return name;
    }
}

Now I need to create a mutator method that lets the client change the gpa. It must verify the gpa is in the range 0.0 to 4.0 (inclusive). If it is not valid, display an error message indicating the problem and end the program.

Your mutator sould look like:

public void setGpa(double studentGpa)
{
if((studentGpa>=0.0) && (studentGpa<=4.0) {
//gpa is in the range 0.0 to 4.0 (inclusive).
gpa=studentGpa;
}else{
//display an error message 
System.out.println("Value out of range!");
//end the program
System.exit(0);
}
}

Hope it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.