Skip to content

Instantly share code, notes, and snippets.

@ychennay
Last active March 19, 2020 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ychennay/ae3e66087b2703080b01516ce6c160b2 to your computer and use it in GitHub Desktop.
Save ychennay/ae3e66087b2703080b01516ce6c160b2 to your computer and use it in GitHub Desktop.
Example of Person class in Java
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