diff --git a/exercises/concept/annalyns-infiltration/src/main/java/AnnalynsInfiltration.java b/exercises/concept/annalyns-infiltration/src/main/java/AnnalynsInfiltration.java index 97a724d39..6d5bb7d84 100644 --- a/exercises/concept/annalyns-infiltration/src/main/java/AnnalynsInfiltration.java +++ b/exercises/concept/annalyns-infiltration/src/main/java/AnnalynsInfiltration.java @@ -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); } -} +} \ No newline at end of file diff --git a/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java b/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java index c19dd38e6..23efc7b8f 100644 --- a/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java +++ b/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java @@ -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= 5) { + busyDays++; + } + } + return busyDays; } -} +} \ No newline at end of file diff --git a/exercises/concept/booking-up-for-beauty/src/main/java/AppointmentScheduler.java b/exercises/concept/booking-up-for-beauty/src/main/java/AppointmentScheduler.java index e60072f9e..e9fa07023 100644 --- a/exercises/concept/booking-up-for-beauty/src/main/java/AppointmentScheduler.java +++ b/exercises/concept/booking-up-for-beauty/src/main/java/AppointmentScheduler.java @@ -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); } } diff --git a/exercises/concept/jedliks-toy-car/src/main/java/JedliksToyCar.java b/exercises/concept/jedliks-toy-car/src/main/java/JedliksToyCar.java index d9906a7b8..0e17182a6 100644 --- a/exercises/concept/jedliks-toy-car/src/main/java/JedliksToyCar.java +++ b/exercises/concept/jedliks-toy-car/src/main/java/JedliksToyCar.java @@ -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; + } } diff --git a/exercises/concept/karls-languages/src/main/java/LanguageList.java b/exercises/concept/karls-languages/src/main/java/LanguageList.java index 0da6b44c7..5cb188f60 100644 --- a/exercises/concept/karls-languages/src/main/java/LanguageList.java +++ b/exercises/concept/karls-languages/src/main/java/LanguageList.java @@ -5,30 +5,37 @@ public class LanguageList { private final List 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"); } } diff --git a/exercises/concept/squeaky-clean/src/main/java/SqueakyClean.java b/exercises/concept/squeaky-clean/src/main/java/SqueakyClean.java index c56787fab..2a8d51751 100644 --- a/exercises/concept/squeaky-clean/src/main/java/SqueakyClean.java +++ b/exercises/concept/squeaky-clean/src/main/java/SqueakyClean.java @@ -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; } }