Start New Discussion within our Software Development Community

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).
//display an error message 
System.out.println("Value out of range!");
//end the program

Hope it helps.

This question has already been answered. Start a new discussion instead.