Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. /**
  2.  * The Student class represents a student in a student administration system.
  3.  * It holds the student details relevant in our context.
  4.  *
  5.  * @author Michael Kölling and David Barnes
  6.  * @version 2016.02.29
  7.  */
  8. public class Student
  9. {
  10.     // the student's full name
  11.     private String name;
  12.     // the student ID
  13.     private String id;
  14.     // the amount of credits for study taken so far
  15.     private int credits;
  16.  
  17.     /**
  18.      * Create a new student with a given name and ID number.
  19.      */
  20.     public Student(String fullName, String studentID)
  21.     {
  22.         name = fullName;
  23.         id = studentID;
  24.         credits = 0;
  25.         /**
  26.          * Exercise 2.77
  27.          */
  28.         if (fullName.length() < 4) {
  29.             System.out.println("Please use a name that's at least 4 characters.");
  30.         }
  31.        
  32.         if (studentID.length() < 3) {
  33.             System.out.println("Please use an ID that's at least 3 characters.");
  34.         }
  35.     }
  36.  
  37.     /**
  38.      * Return the full name of this student.
  39.      */
  40.     public String getName()
  41.     {
  42.         return name;
  43.     }
  44.  
  45.     /**
  46.      * Set a new name for this student.
  47.      */
  48.     public void changeName(String replacementName)
  49.     {
  50.         name = replacementName;
  51.     }
  52.  
  53.     /**
  54.      * Return the student ID of this student.
  55.      */
  56.     public String getStudentID()
  57.     {
  58.         return id;
  59.     }
  60.  
  61.     /**
  62.      * Add some credit points to the student's accumulated credits.
  63.      */
  64.     public void addCredits(int additionalPoints)
  65.     {
  66.         credits += additionalPoints;
  67.     }
  68.  
  69.     /**
  70.      * Return the number of credit points this student has accumulated.
  71.      */
  72.     public int getCredits()
  73.     {
  74.         return credits;
  75.     }
  76.  
  77.     /**
  78.      * Return the login name of this student. The login name is a combination
  79.      * of the first four characters of the student's name and the first three
  80.      * characters of the student's ID number.
  81.      */
  82.     public String getLoginName()
  83.     {
  84.         return name.substring(0,4) + id.substring(0,3);
  85.     }
  86.    
  87.     /**
  88.      * Print the student's name and ID number to the output terminal.
  89.      */
  90.     public void print()
  91.     {
  92.         System.out.println(name + ", student ID: " + id + ", credits: " + credits);
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement