Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class University {
- public String UniversityName;
- public Club[] club;
- public int countClub; //นับจำนวนชมรม มีได้ไม่เกิน20ชมรม
- public University(String UniversityName, int clubSize, int countClub) {
- this.UniversityName = UniversityName;
- if(clubSize>20){
- clubSize = 20; //ถ้าจำนวนชมรมมากกว่า20ชมรมละก็ บังคับให้มีแค่20ชมรม
- }
- this.club = new Club[clubSize];
- this.countClub = 0;
- }
- public String getUniversityName() {
- return UniversityName;
- }
- public int getCountClub() {
- return countClub;
- }
- public boolean numberOfClubIsFull(){
- return countClub == club.length;
- }
- public boolean addClub(Club newC){ //การเปิดชมรมใหม่
- if( newC == null || numberOfClubIsFull()){ //ถ้าชมรมที่จะเปิดใหม่เป็นnull และจำนวนclubในมหาวิทยาลัยเต็ม20ชมรมแล้ว
- return false; //add club ไม่ได้ return false
- }
- newC = club[countClub++]; //ถ้ายังสามารถเพิ่มชมรมได้ ก็จะสามารถสร้างชมรมได้ โดยเพิ่มจำนวนชมรมในมหาวิทยาลัยเพิ่มอีก 1 ชมรม
- return true;
- }
- //CHECK♥
- @Override
- public String toString() {
- return "University >> UniversityName: " + UniversityName + ", club: " + club + ", countClub:" + countClub;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement