Last active
March 19, 2020 22:57
-
-
Save ychennay/ae3e66087b2703080b01516ce6c160b2 to your computer and use it in GitHub Desktop.
Example of Person class in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.yuchen; | |
public class Student { | |
public String name; | |
public float gpa; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public float getGpa() { | |
return gpa; | |
} | |
public void setGpa(float gpa) { | |
if (gpa < 0.0) { | |
throw new ArithmeticException("GPA must be a non-negative decimal."); | |
} | |
this.gpa = gpa; | |
} | |
Student(String name, float gpa) { | |
this.name = name; | |
this.gpa = gpa; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment