Created
February 17, 2019 17:32
-
-
Save annibuliful/985889a48cd67982fe6a694fb5285e2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FreeMember extends Member { | |
| public int FREE_PRIVATE_REPOS = 3; | |
| public int numPrivateRepo = 0; | |
| FreeMember(String email, String password) { | |
| super(email, password); | |
| } | |
| @Override | |
| public Boolean addRepository(Repository repo) { | |
| if (repo.isPrivate()) { | |
| if (this.getNumPrivateRepo() == this.FREE_PRIVATE_REPOS) { | |
| System.out.println("Name: " + repo.getName() | |
| + " (PRIVATE) cannot be added because the number of private repository is reaching the limit"); | |
| return false; | |
| } else { | |
| this.repoList.add(repo); | |
| this.numPrivateRepo++; | |
| return true; | |
| } | |
| } else { | |
| this.repoList.add(repo); | |
| return true; | |
| } | |
| } | |
| public int getNumPrivateRepo() { | |
| return this.numPrivateRepo; | |
| } | |
| @Override | |
| public Boolean removeRepository(Repository repo) { | |
| for (int i = 0; i < this.repoList.size(); i++) { | |
| if (this.repoList.get(i).isPrivate() && this.repoList.get(i).isEqual(repo)) { | |
| this.repoList.remove(i); | |
| this.numPrivateRepo--; | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| @Override | |
| public void printMemberInfo() { | |
| System.out.println("--- FREE MEMBER ---"); | |
| System.out.println("Email" + this.email + "(pwd: " + this.password + ")"); | |
| for (Repository repo : this.repoList) { | |
| if (repo.isPrivate()) { | |
| System.out.println("Name: " + repo.getName() + "(Private)"); | |
| } else { | |
| System.out.println("Name: " + repo.getName() + "(Public)"); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class Member { | |
| public String email; | |
| public String password; | |
| public ArrayList<Repository> repoList; | |
| Member(String email, String password){ | |
| this.email = email; | |
| this.password = password; | |
| this.repoList = new ArrayList<Repository>(); | |
| } | |
| public Boolean addRepository(Repository repo){ | |
| if(repo != null) { | |
| this.repoList.add(repo); | |
| return true; | |
| } | |
| return false; | |
| } | |
| public Boolean removeRepository(Repository repo) { | |
| for(int i = 0 ; i < this.repoList.size();i++) { | |
| if(this.repoList.get(i).isEqual(repo)) { | |
| this.repoList.remove(i); | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| public void printMemberInfo() { | |
| System.out.println("--- Member ---"); | |
| System.out.println("Email" + this.email + "(pwd: " + this.password + ")" ); | |
| for(Repository repo: this.repoList) { | |
| if(repo.isPrivate()) { | |
| System.out.println("Name: " + repo.getName() + "(Private)"); | |
| }else { | |
| System.out.println("Name: " + repo.getName() + "(Public)"); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class ProMember extends Member{ | |
| public double fee; | |
| public double COLLABORATOR_FREE = 80.0; | |
| public ArrayList<String> collaborators; | |
| public ProMember(String email, String password, int fee) { | |
| super(email,password); | |
| this.fee = fee; | |
| this.collaborators = new ArrayList<String>(); | |
| } | |
| public boolean addCollaborator(String username) { | |
| if(!username.isEmpty()) { | |
| this.collaborators.add(username); | |
| return true; | |
| } | |
| return false; | |
| } | |
| public boolean removeCollaborator(String username) { | |
| for(int i = 0; i < this.collaborators.size();i++) { | |
| if(this.collaborators.get(i).equals(username)) { | |
| this.collaborators.remove(i); | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| public double getMonthlyBill() { | |
| double sum = this.fee + (this.COLLABORATOR_FREE* this.collaborators.size()); | |
| return sum; | |
| } | |
| public void printMemberInfo() { | |
| System.out.println("--- PRO MEMBER ---"); | |
| System.out.println("Email" + this.email + "(pwd: " + this.password + ")" ); | |
| for(Repository repo: this.repoList) { | |
| if(repo.isPrivate()) { | |
| System.out.println("Name: " + repo.getName() + "(Private)"); | |
| }else { | |
| System.out.println("Name: " + repo.getName() + "(Public)"); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment