Advertisement
panaewboi

university 23Oct2019

Oct 23rd, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. public class University {
  2.     public String UniversityName;
  3.     public Club[] club;
  4.     public int countClub; //นับจำนวนชมรม มีได้ไม่เกิน20ชมรม
  5.  
  6.     public University(String UniversityName, int clubSize, int countClub) {
  7.         this.UniversityName = UniversityName;
  8.        
  9.         if(clubSize>20){
  10.             clubSize = 20; //ถ้าจำนวนชมรมมากกว่า20ชมรมละก็ บังคับให้มีแค่20ชมรม
  11.         }
  12.         this.club = new Club[clubSize];
  13.        
  14.         this.countClub = 0;
  15.     }
  16.  
  17.     public String getUniversityName() {
  18.         return UniversityName;
  19.     }
  20.  
  21.     public int getCountClub() {
  22.         return countClub;
  23.     }
  24.    
  25.     public boolean numberOfClubIsFull(){
  26.         return countClub == club.length;
  27.     }
  28.    
  29.     public boolean addClub(Club newC){ //การเปิดชมรมใหม่
  30.         if( newC == null || numberOfClubIsFull()){ //ถ้าชมรมที่จะเปิดใหม่เป็นnull และจำนวนclubในมหาวิทยาลัยเต็ม20ชมรมแล้ว
  31.             return false; //add club ไม่ได้ return false
  32.         }
  33.        
  34.         newC = club[countClub++]; //ถ้ายังสามารถเพิ่มชมรมได้ ก็จะสามารถสร้างชมรมได้ โดยเพิ่มจำนวนชมรมในมหาวิทยาลัยเพิ่มอีก 1 ชมรม
  35.         return true;
  36.     }
  37.  
  38.     //CHECK♥
  39.     @Override
  40.     public String toString() {
  41.         return "University >> UniversityName: " + UniversityName + ", club: " + club + ", countClub:" + countClub;
  42.     }
  43.    
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement