Skip to content

Instantly share code, notes, and snippets.

@annibuliful
Created February 17, 2019 17:32
Show Gist options
  • Select an option

  • Save annibuliful/985889a48cd67982fe6a694fb5285e2a to your computer and use it in GitHub Desktop.

Select an option

Save annibuliful/985889a48cd67982fe6a694fb5285e2a to your computer and use it in GitHub Desktop.
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)");
}
}
}
}
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)");
}
}
}
}
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