-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More robust version for beverage-machine & Proper distribution of matches for IPL-tournament #3
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
package com.tarktech.training.beverage.maker; | ||
|
||
public class CappuccinoMaker extends BeverageMaker { | ||
public CappuccinoMaker(){ | ||
import com.tarktech.training.beverage.BeverageType; | ||
|
||
} | ||
public class CappuccinoMaker extends BeverageMaker { | ||
public String dispenseBeverage() { | ||
validateBeveragesAreAvailable(); | ||
updateBeverageCount(); | ||
return "Enjoy hot cappuccino made from freshly brewed beans!"; | ||
return configBeverage(BeverageType.valueOf("Cappuccino")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
package com.tarktech.training.beverage.maker; | ||
|
||
public class LatteMaker extends BeverageMaker { | ||
|
||
public LatteMaker(){ | ||
} | ||
import com.tarktech.training.beverage.BeverageType; | ||
|
||
public class LatteMaker extends BeverageMaker { | ||
public String dispenseBeverage() { | ||
if(getAvailableBeverageCount() == 0){ | ||
throw new RuntimeException("Sorry, Beverage is out of stock!"); | ||
} | ||
updateBeverageCount(); | ||
return "Enjoy your Latte with fresh creamy milk!"; | ||
return configBeverage(BeverageType.valueOf("Latte")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
package com.tarktech.training.beverage.maker; | ||
|
||
public class MochaMaker extends BeverageMaker { | ||
|
||
public MochaMaker() { | ||
} | ||
import com.tarktech.training.beverage.BeverageType; | ||
|
||
public class MochaMaker extends BeverageMaker { | ||
public String dispenseBeverage() { | ||
validateBeveragesAreAvailable(); | ||
updateBeverageCount(); | ||
return "Enjoy your cup of Mocha made from exotic chocolate!"; | ||
return configBeverage(BeverageType.valueOf("Mocha")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package com.tarktech.training.beverage.maker; | ||
|
||
|
||
public class TeaMaker extends BeverageMaker { | ||
|
||
import com.tarktech.training.beverage.BeverageType; | ||
|
||
public class TeaMaker extends BeverageMaker { | ||
public String dispenseBeverage() { | ||
validateBeveragesAreAvailable(); | ||
updateBeverageCount(); | ||
return "Enjoy your Hot Masala Tea!"; | ||
return configBeverage(BeverageType.valueOf("Tea")); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,17 +13,41 @@ public List<CricketMatch> scheduleLeagueRound(List<Team> teams, LocalDate startD | |
|
||
LocalDate matchScheduleDate = startDate; | ||
|
||
for (int i = 0; i < teams.size(); ++i) { | ||
for (int j = i + 1; j < teams.size(); ++j) { | ||
CricketMatch cricketMatch = new CricketMatch(teams.get(i), teams.get(j)); | ||
cricketMatch.scheduleOn(matchScheduleDate); | ||
|
||
scheduledMatches.add(cricketMatch); | ||
|
||
matchScheduleDate = matchScheduleDate.plusDays(1); | ||
ArrayList<String> schedule = new ArrayList<>(); | ||
int r = 0; | ||
int i = 0; | ||
int j = teams.size()-1; | ||
|
||
if (teams.size() % 2 == 0) { | ||
while (r < teams.size() - 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to be a correct approach. However, in each round, we also need to schedule a match between last team in the array and team at array position (n-1)/2, where n is the total team count. That is the team which is located at top in the polygon and the one at the center. For example, if team size is 10 (Team-0 to Team-9), the scheduled matches in first round would be,
Additionally, using above reference link, also try to implement it for odd number of teams. At last, try to schedule matches (when team count is >= 10) so that none of the team has to play matches on consecutive days, i.e. each team will get at least one day to rest/practice after playing a match. |
||
while (i < j) { | ||
schedule.add(teams.get(i) + " " + teams.get(j)); | ||
|
||
CricketMatch cricketMatch = new CricketMatch(teams.get(i), teams.get(j)); | ||
cricketMatch.scheduleOn(matchScheduleDate); | ||
scheduledMatches.add(cricketMatch); | ||
matchScheduleDate = matchScheduleDate.plusDays(1); | ||
|
||
i++; | ||
j--; | ||
} | ||
i = 0; | ||
j = teams.size() - 1; | ||
|
||
//right shifting of teams... | ||
List<Team> temp = new ArrayList<>(teams); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can further simplify the array rotation, using the methods supported by List/ArrayList. This will eliminate the You may want to look at below documentation and see, which methods could be used to achieve this. |
||
teams.set(1, temp.get(temp.size()-1)); | ||
|
||
for (int k=2; k<temp.size(); k++){ | ||
teams.set(k, temp.get(k-1)); | ||
} | ||
|
||
r++; | ||
} | ||
//System.out.println(schedule); | ||
} | ||
|
||
//System.out.println(scheduledMatches); | ||
return scheduledMatches; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this is correct solution!
It also meets the constrainsts that we've laid out in the workshop.
So, good effort on this.
However, there is scope to improvize it further, i.e.
So, let's improvize it further so that the
Hint:
Implementation as of yesterday,
Is it possible to modify it like below? Find a pattern and then apply the learnings from yesterday's session to eliminate duplicate code across all BeverageMakers?