diff --git a/src/main/java/object/example/bobbymoney/AiSoftware.java b/src/main/java/object/example/bobbymoney/AiSoftware.java new file mode 100644 index 0000000..ccbc7c7 --- /dev/null +++ b/src/main/java/object/example/bobbymoney/AiSoftware.java @@ -0,0 +1,86 @@ +package object.example.bobbymoney; + +public class AiSoftware { + private String aiName; + private String coachType; + private String teachingStyle; + private double minimumTimeSpent; + private String timeFrame; + + public AiSoftware(String aiName, String coachType, String teachingStyle, + double minimumTimeSpent, String timeFrame) { + if (minimumTimeSpent < 0.5) { + throw new IllegalArgumentException("Minimum time spent must be at least 0.5 hours (30 minutes)."); + } + this.aiName = aiName; + this.coachType = coachType; + this.teachingStyle = teachingStyle; + this.minimumTimeSpent = minimumTimeSpent; + this.timeFrame = timeFrame; + } + + public String getAiName() + { + return aiName; } + + + public String getCoachType() + { + return coachType; } + + + public String getTeachingStyle() + { + return teachingStyle; } + + + public double getMinimumTimeSpent() + { + return minimumTimeSpent; } + + + public String getTimeFrame() + { + return timeFrame; } + + public void setAiName(String aiName) + { this.aiName = aiName; } + + + public void setCoachType(String coachType) + { + this.coachType = coachType; + } + + + public void setTeachingStyle(String teachingStyle) + { + this.teachingStyle = teachingStyle; + } + + + public void setTimeFrame(String timeFrame) + { + this.timeFrame = timeFrame; + } + + + public void setMinimumTimeSpent(double minimumTimeSpent) { + if (minimumTimeSpent < 0.5) { + throw new IllegalArgumentException("Minimum time spent must be at least 0.5 hours (30 minutes)."); + } + this.minimumTimeSpent = minimumTimeSpent; + } + + public String getSummary() { + return aiName + " is a " + coachType + " coach using the " + + teachingStyle + " method for " + timeFrame + "."; + } + + public double calculateTotalHours(int sessions) { + if (sessions <= 0) { + throw new IllegalArgumentException("Sessions must be greater than zero."); + } + return minimumTimeSpent * sessions; + } +} \ No newline at end of file diff --git a/src/test/java/object/example/bobbymoney/AiSoftwareTest.java b/src/test/java/object/example/bobbymoney/AiSoftwareTest.java new file mode 100644 index 0000000..b72c173 --- /dev/null +++ b/src/test/java/object/example/bobbymoney/AiSoftwareTest.java @@ -0,0 +1,97 @@ +package object.example.bobbymoney; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class AiSoftwareTest { + + @Test + public void constructorShouldSetAllFields() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + assertEquals("Bucky", aiSoftware.getAiName()); + assertEquals("Guitar", aiSoftware.getCoachType()); + assertEquals("Pomodoro", aiSoftware.getTeachingStyle()); + assertEquals(1.0, aiSoftware.getMinimumTimeSpent()); + assertEquals("2 weeks", aiSoftware.getTimeFrame()); + } + + @Test + public void constructorShouldThrowWhenMinimumTimeSpentIsBelowHalfHour() { + assertThrows(IllegalArgumentException.class, () -> + new AiSoftware("Bucky", "Guitar", "Pomodoro", 0.25, "2 weeks") + ); + } + + @Test + public void setAiNameShouldUpdateAiName() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + aiSoftware.setAiName("Nova"); + assertEquals("Nova", aiSoftware.getAiName()); + } + + @Test + public void setCoachTypeShouldUpdateCoachType() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + aiSoftware.setCoachType("Piano"); + assertEquals("Piano", aiSoftware.getCoachType()); + } + + @Test + public void setTeachingStyleShouldUpdateTeachingStyle() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + aiSoftware.setTeachingStyle("Spaced Repetition"); + assertEquals("Spaced Repetition", aiSoftware.getTeachingStyle()); + } + + @Test + public void setMinimumTimeSpentShouldUpdateValue() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + aiSoftware.setMinimumTimeSpent(2.0); + assertEquals(2.0, aiSoftware.getMinimumTimeSpent()); + } + + @Test + public void setMinimumTimeSpentShouldThrowWhenBelowHalfHour() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + assertThrows(IllegalArgumentException.class, () -> + aiSoftware.setMinimumTimeSpent(0.1) + ); + } + + @Test + public void setTimeFrameShouldUpdateTimeFrame() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + aiSoftware.setTimeFrame("1 month"); + assertEquals("1 month", aiSoftware.getTimeFrame()); + } + + @Test + public void getSummaryShouldReturnFormattedString() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + String result = aiSoftware.getSummary(); + assertEquals("Bucky is a Guitar coach using the Pomodoro method for 2 weeks.", result); + } + + @Test + public void calculateTotalHoursShouldReturnCorrectTotal() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + double total = aiSoftware.calculateTotalHours(5); + assertEquals(5.0, total); + } + + @Test + public void calculateTotalHoursShouldThrowWhenSessionsIsZero() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + assertThrows(IllegalArgumentException.class, () -> + aiSoftware.calculateTotalHours(0) + ); + } + + @Test + public void calculateTotalHoursShouldThrowWhenSessionsIsNegative() { + AiSoftware aiSoftware = new AiSoftware("Bucky", "Guitar", "Pomodoro", 1.0, "2 weeks"); + assertThrows(IllegalArgumentException.class, () -> + aiSoftware.calculateTotalHours(-3) + ); + } +} \ No newline at end of file