Skip to content

Commit 4bb56eb

Browse files
committed
feat: addedBestFriend.java, BestFriendTest.java, FriendshipLevel.java, and InvalidActivityException.java and test passed for get name
1 parent 0f00edf commit 4bb56eb

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.codedifferently.lesson16.nicolejackson;
2+
import java.util.ArrayList;
3+
4+
public class BestFriend {
5+
private String name;
6+
private int age;
7+
private boolean livesNearby;
8+
private ArrayList<String> favoriteActivities;
9+
private FriendshipLevel level;
10+
private double trustScore;
11+
12+
public BestFriend(String name, int age, boolean livesNearby, FriendshipLevel level, double trustScore, ArrayList<String> favoriteActivities) {
13+
this.name = name;
14+
this.age = age;
15+
this.livesNearby = livesNearby;
16+
this.level = level;
17+
this.trustScore = trustScore;
18+
this.favoriteActivities = new ArrayList<>();
19+
}
20+
21+
public String getName(){
22+
return this.name;
23+
}
24+
25+
public int getAge (){
26+
return this.age;
27+
}
28+
29+
public boolean getLivesNearby(){
30+
return this.livesNearby;
31+
32+
}
33+
public FriendshipLevel getLevel(){
34+
return this.level;
35+
}
36+
37+
public double getTrustScore (){
38+
return this.trustScore;
39+
}
40+
public ArrayList<String> getFavoriteActivities (){
41+
return this.favoriteActivities;
42+
}
43+
44+
public boolean isTrustworthy() {
45+
return trustScore >= 75 ? true : false;
46+
}
47+
48+
public void addFavoriteActivity(String activity) throws InvalidActivityException {
49+
if(activity == null || activity.isEmpty()) {
50+
throw new InvalidActivityException("Activity cannot be empty!");
51+
}
52+
favoriteActivities.add(activity);
53+
}
54+
55+
public void showActivities() {
56+
System.out.println(name + "'s favorite activities:");
57+
for(String activity : favoriteActivities) {
58+
System.out.println("- " + activity);
59+
}
60+
}
61+
62+
public void updateLevel(FriendshipLevel newLevel) {
63+
this.level = newLevel;
64+
}
65+
66+
67+
}
68+
69+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.codedifferently.lesson16.nicolejackson;
2+
public enum FriendshipLevel {
3+
ACQUAINTANCE,
4+
FRIEND,
5+
CLOSE_FRIEND,
6+
BEST_FRIEND,
7+
FAMILY
8+
}
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codedifferently.lesson16.nicolejackson;
2+
public class InvalidActivityException extends Exception {
3+
public InvalidActivityException(String message) {
4+
super(message);
5+
}
6+
}
7+
8+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.codedifferently.lesson16;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.ArrayList;
6+
import java.util.Arrays;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
10+
import com.codedifferently.lesson16.nicolejackson.BestFriend;
11+
import com.codedifferently.lesson16.nicolejackson.FriendshipLevel;
12+
13+
public class BestFriendTest {
14+
private BestFriend bestFriend;
15+
16+
@BeforeEach
17+
public void setUp(){
18+
ArrayList<String> activities = new ArrayList<>(Arrays.asList("Baking","Movie Nights","Catching Up"));
19+
bestFriend = new BestFriend("Jennah",23,true, FriendshipLevel.FAMILY, 101.0, activities);
20+
21+
}
22+
@Test
23+
public void getNameTest(){
24+
String expected = "Jennah";
25+
assertEquals(bestFriend.getName(), expected);
26+
}
27+
}

0 commit comments

Comments
 (0)