Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Student{//class header
- //Instance variables - the data that represents a student
- private String name;
- private int id;
- private double gpa;
- //Constructor to make basic person
- public Student(){
- name = "John Doe";
- id = 12345678;
- gpa = 0.0;
- }
- //Constructor to make person and pick values for instance variables at the time of creation
- public Student(String n, int i, double g){
- name = n;
- id = i;
- gpa = g;
- }
- //Methods
- //print a String representing the student when you print a student object
- public void print(){
- System.out.println( "Name: " + name + "\nID: " + id + "\nGPA: " + gpa );
- }
- //print which honor roll they are a part of
- public void printHonorRoll(){
- if( gpa >= 3.7 ) System.out.println( "Gold Honor Roll" );
- else if( gpa >= 3.4 ) System.out.println( "Silver Honor Roll" );
- else System.out.println( "No Honor Roll" );
- }
- //print whether or not the student is eligible for athletics
- public void printEligibility(){
- if( gpa >= 2.0 ) System.out.println( "Eligible for sports" );
- else System.out.println( "Not eligible for sports" );
- }
- //main method
- public static void main(String[] args){
- Student student1 = new Student("Ekalb Retsof", 91119111, 3.0);//create a student object
- student1.print();//call methods on the student1 object
- student1.printHonorRoll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement