Advertisement
fosterbl

Student.java

Feb 4th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. public class Student{//class header
  2.    
  3.    //Instance variables - the data that represents a student
  4.    private String name;
  5.    private int id;
  6.    private double gpa;
  7.    
  8.    //Constructor to make basic person
  9.    public Student(){
  10.       name = "John Doe";
  11.       id = 12345678;
  12.       gpa = 0.0;
  13.    }
  14.    
  15.    //Constructor to make person and pick values for instance variables at the time of creation
  16.    public Student(String n, int i, double g){
  17.       name = n;
  18.       id = i;
  19.       gpa = g;
  20.    }
  21.    //Methods
  22.    
  23.    //print a String representing the student when you print a student object
  24.    public void print(){
  25.       System.out.println( "Name: " + name + "\nID: " + id + "\nGPA: " + gpa );
  26.    }
  27.    
  28.    //print which honor roll they are a part of
  29.    public void printHonorRoll(){
  30.       if( gpa >= 3.7 ) System.out.println( "Gold Honor Roll" );
  31.       else if( gpa >= 3.4 ) System.out.println( "Silver Honor Roll" );
  32.       else System.out.println( "No Honor Roll" );
  33.    }
  34.    
  35.    //print whether or not the student is eligible for athletics
  36.    public void printEligibility(){
  37.       if( gpa >= 2.0 ) System.out.println( "Eligible for sports" );
  38.       else System.out.println( "Not eligible for sports" );
  39.    }
  40.    
  41.    //main method
  42.    public static void main(String[] args){
  43.       Student student1 = new Student("Ekalb Retsof", 91119111, 3.0);//create a student object
  44.       student1.print();//call methods on the student1 object
  45.       student1.printHonorRoll();
  46.    }
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement