Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
class AnnalynsInfiltration {
public static boolean canFastAttack(boolean knightIsAwake) {
throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canFastAttack() method");
public static boolean canFastAttack(boolean knightIsAwake){
// throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canFastAttack() method");
return !knightIsAwake;
}

public static boolean canSpy(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake) {
throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canSpy() method");
// throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canSpy() method");
return ((knightIsAwake || archerIsAwake) || prisonerIsAwake);
}

public static boolean canSignalPrisoner(boolean archerIsAwake, boolean prisonerIsAwake) {
throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canSignalPrisoner() method");
// throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canSignalPrisoner() method");
return !archerIsAwake && prisonerIsAwake;
}

public static boolean canFreePrisoner(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake, boolean petDogIsPresent) {
throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canFreePrisoner() method");
// throw new UnsupportedOperationException("Please implement the (static) AnnalynsInfiltration.canFreePrisoner() method");
return (prisonerIsAwake && !archerIsAwake && !knightIsAwake) || (!archerIsAwake && petDogIsPresent);
}
}
}
43 changes: 36 additions & 7 deletions exercises/concept/bird-watcher/src/main/java/BirdWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,55 @@ public BirdWatcher(int[] birdsPerDay) {
}

public int[] getLastWeek() {
throw new UnsupportedOperationException("Please implement the BirdWatcher.getLastWeek() method");
// throw new UnsupportedOperationException("Please implement the BirdWatcher.getLastWeek() method");
int[] birdCount = new int[] {0,2,5,3,7,8,4};
return birdCount;
}

public int getToday() {
throw new UnsupportedOperationException("Please implement the BirdWatcher.getToday() method");
// throw new UnsupportedOperationException("Please implement the BirdWatcher.getToday() method");
return birdsPerDay[birdsPerDay.length-1];
}

public void incrementTodaysCount() {
throw new UnsupportedOperationException("Please implement the BirdWatcher.incrementTodaysCount() method");
/// throw new UnsupportedOperationException("Please implement the BirdWatcher.incrementTodaysCount() method");
birdsPerDay[birdsPerDay.length-1] += 1;
}

public boolean hasDayWithoutBirds() {
throw new UnsupportedOperationException("Please implement the BirdWatcher.hasDayWithoutBirds() method");
// throw new UnsupportedOperationException("Please implement the BirdWatcher.hasDayWithoutBirds() method");
boolean noBird = false;
for(int count : birdsPerDay){
if (count == 0){
noBird = true;
}

}
return noBird;
}

public int getCountForFirstDays(int numberOfDays) {
throw new UnsupportedOperationException("Please implement the BirdWatcher.getCountForFirstDays() method");
// throw new UnsupportedOperationException("Please implement the BirdWatcher.getCountForFirstDays() method");
int getTotalCount=0;
if(numberOfDays>birdsPerDay.length){
numberOfDays = birdsPerDay.length;
}
for(int i=0;i<numberOfDays;i++){
getTotalCount += birdsPerDay[i];
}
return getTotalCount;

}

public int getBusyDays() {
throw new UnsupportedOperationException("Please implement the BirdWatcher.getBusyDays() method");
// throw new UnsupportedOperationException("Please implement the BirdWatcher.getBusyDays() method");

int busyDays=0;
for (int count : birdsPerDay){
if(count >= 5) {
busyDays++;
}
}
return busyDays;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

class AppointmentScheduler {
public LocalDateTime schedule(String appointmentDateDescription) {
throw new UnsupportedOperationException("Please implement the AppointmentScheduler.schedule() method");
// throw new UnsupportedOperationException("Please implement the AppointmentScheduler.schedule() method");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss");
LocalDateTime date = LocalDateTime.parse(appointmentDateDescription, formatter);

DateTimeFormatter printer = DateTimeFormatter.ofPattern("yyyy, MM, dd, HH, mm, ss");
printer.format(date);
return LocalDateTime.of(date.getYear(), date.getMonth(), date.getDayOfMonth(), date.getHour(), date.getMinute(), date.getSecond());
}

public boolean hasPassed(LocalDateTime appointmentDate) {
throw new UnsupportedOperationException("Please implement the AppointmentScheduler.hasPassed() method");
// throw new UnsupportedOperationException("Please implement the AppointmentScheduler.hasPassed() method");
return appointmentDate.isBefore(LocalDateTime.now());
}

public boolean isAfternoonAppointment(LocalDateTime appointmentDate) {
throw new UnsupportedOperationException("Please implement the AppointmentScheduler.isAfternoonAppointment() method");
// throw new UnsupportedOperationException("Please implement the AppointmentScheduler.isAfternoonAppointment() method");
return appointmentDate.getHour() >= 12 && appointmentDate.getHour() < 18;
}

public String getDescription(LocalDateTime appointmentDate) {
throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getDescription() method");
// throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getDescription() method");
DateTimeFormatter printer = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy, 'at' h:mm a'.'");
return "You have an appointment on "+printer.format(appointmentDate);
}

public LocalDate getAnniversaryDate() {
throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getAnniversaryDate() method");
// throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getAnniversaryDate() method");
return LocalDate.of(LocalDate.now().getYear(), 9,15);
}
}
35 changes: 31 additions & 4 deletions exercises/concept/jedliks-toy-car/src/main/java/JedliksToyCar.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
public class JedliksToyCar {
private int distance=0;
private int battery=100;

public static JedliksToyCar buy() {
throw new UnsupportedOperationException("Please implement the (static) JedliksToyCar.buy() method");
// throw new UnsupportedOperationException("Please implement the (static) JedliksToyCar.buy() method");
JedliksToyCar car = new JedliksToyCar();
return car;
}

public String distanceDisplay() {
throw new UnsupportedOperationException("Please implement the JedliksToyCar.distanceDisplay() method");
// throw new UnsupportedOperationException("Please implement the JedliksToyCar.distanceDisplay() method");


String carDistanceDisplay = null;
if (this.distance <= 2000) {
carDistanceDisplay = "Driven " + this.distance + " meters";
}
else if(this.distance > 2000) {
carDistanceDisplay = "Driven 2000 meters";
}

return carDistanceDisplay;
}

public String batteryDisplay() {
throw new UnsupportedOperationException("Please implement the JedliksToyCar.batteryDisplay() method");
// throw new UnsupportedOperationException("Please implement the JedliksToyCar.batteryDisplay() method");
String carBatteryDisplay = null;
if (this.battery <= 100 && this.battery >= 1) {
carBatteryDisplay = "Battery at "+ this.battery +"%";
}
else if(this.battery <= 0) {
carBatteryDisplay = "Battery empty";
}
return carBatteryDisplay;
}

public void drive() {
throw new UnsupportedOperationException("Please implement the JedliksToyCar.drive() method");
// throw new UnsupportedOperationException("Please implement the JedliksToyCar.drive() method");
this.distance += 20;
this.battery -= 1;

}
}
21 changes: 14 additions & 7 deletions exercises/concept/karls-languages/src/main/java/LanguageList.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@ public class LanguageList {
private final List<String> languages = new ArrayList<>();

public boolean isEmpty() {
throw new UnsupportedOperationException("Please implement the isEmpty() method");
//throw new UnsupportedOperationException("Please implement the isEmpty() method");
return languages.isEmpty();
}

public void addLanguage(String language) {
throw new UnsupportedOperationException("Please implement the addLanguage() method");
// throw new UnsupportedOperationException("Please implement the addLanguage() method");
languages.add(language);
}

public void removeLanguage(String language) {
throw new UnsupportedOperationException("Please implement the removeLanguage() method");
// throw new UnsupportedOperationException("Please implement the removeLanguage() method");
languages.remove(language);
}

public String firstLanguage() {
throw new UnsupportedOperationException("Please implement the firstLanguage() method");
// throw new UnsupportedOperationException("Please implement the firstLanguage() method");
return languages.getFirst();
}

public int count() {
throw new UnsupportedOperationException("Please implement the count() method");
// throw new UnsupportedOperationException("Please implement the count() method");
return languages.size();
}

public boolean containsLanguage(String language) {
throw new UnsupportedOperationException("Please implement the containsLanguage() method");
// throw new UnsupportedOperationException("Please implement the containsLanguage() method");
return languages.contains(language);
}

public boolean isExciting() {
throw new UnsupportedOperationException("Please implement the isExciting() method");
// throw new UnsupportedOperationException("Please implement the isExciting() method");
return languages.contains("Java") || languages.contains("Kotlin");
}
}
31 changes: 30 additions & 1 deletion exercises/concept/squeaky-clean/src/main/java/SqueakyClean.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
class SqueakyClean {
static String clean(String identifier) {
throw new UnsupportedOperationException("Please implement the (static) SqueakyClean.clean() method");
// throw new UnsupportedOperationException("Please implement the (static) SqueakyClean.clean() method");
int index =0;
String cleanString = identifier.replace(' ','_');
if(cleanString.contains("-")) {
index = cleanString.indexOf('-');
cleanString = cleanString.replace("-", "");
cleanString = cleanString.substring(0,index) + cleanString.substring(index,index+1).toUpperCase() + cleanString.substring(index+1);
}
char[] chars = cleanString.toCharArray();
String newString = "";
for(char c : chars) {
if(c=='4') c = 'a';
else if(c=='3') c = 'e';
else if(c=='0') c = 'o';
else if(c=='1') c = 'l';
else if(c=='7') c = 't';

newString += c;
}
cleanString = newString;

chars = cleanString.toCharArray();
newString = "";
for(char c : chars) {
if(Character.isAlphabetic(c)) newString += c;
else if(c=='_') newString += c;
}
cleanString = newString;

return cleanString;
}
}