Merge branch 'main'
This commit is contained in:
0
src/main/java/oving4/card/.gitkeep
Normal file
0
src/main/java/oving4/card/.gitkeep
Normal file
0
src/main/java/oving4/stopwatch/.gitkeep
Normal file
0
src/main/java/oving4/stopwatch/.gitkeep
Normal file
73
src/main/java/oving4/testing/CoffeeCup.java
Normal file
73
src/main/java/oving4/testing/CoffeeCup.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package oving4.testing;
|
||||
|
||||
public class CoffeeCup {
|
||||
|
||||
private double capacity;
|
||||
private double currentVolume;
|
||||
|
||||
public CoffeeCup() {
|
||||
this.capacity = 0.0;
|
||||
this.currentVolume = 0.0;
|
||||
}
|
||||
|
||||
public CoffeeCup(double capacity, double currentVolume) {
|
||||
if (!CoffeeCup.isValidCapacity(capacity)) {
|
||||
throw new IllegalArgumentException("Illegal capacity given.");
|
||||
}
|
||||
this.capacity = capacity;
|
||||
|
||||
if (!this.isValidVolume(currentVolume)) {
|
||||
throw new IllegalArgumentException("Illegal volume given.");
|
||||
}
|
||||
this.currentVolume = currentVolume;
|
||||
}
|
||||
|
||||
public double getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public double getCurrentVolume() {
|
||||
return this.currentVolume;
|
||||
}
|
||||
|
||||
private static boolean isValidCapacity(double capacity) {
|
||||
return capacity >= 0.0;
|
||||
}
|
||||
|
||||
public void increaseCupSize(double biggerCapacity) {
|
||||
if (CoffeeCup.isValidCapacity(biggerCapacity)) {
|
||||
this.capacity += biggerCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidVolume(double volume) {
|
||||
return volume <= this.capacity && volume >= 0.0;
|
||||
}
|
||||
|
||||
private boolean canDrink(double volume) {
|
||||
return volume <= this.currentVolume;
|
||||
}
|
||||
|
||||
public void drinkCoffee(double volume) {
|
||||
if (!this.isValidVolume(volume) || !this.canDrink(volume)) {
|
||||
throw new IllegalArgumentException("You cannot drink that much coffee!");
|
||||
}
|
||||
|
||||
this.currentVolume -= volume;
|
||||
}
|
||||
|
||||
public void fillCoffee(double volume) {
|
||||
if (!this.isValidVolume(this.currentVolume + volume)) {
|
||||
throw new IllegalArgumentException(
|
||||
"You just poured coffee all over the table. Good job.");
|
||||
}
|
||||
|
||||
this.currentVolume += volume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[CoffeeCup capacity=%.2f, currentVolume=%.2f]", this.capacity,
|
||||
this.currentVolume);
|
||||
}
|
||||
}
|
||||
0
src/main/java/oving4/twitter/.gitkeep
Normal file
0
src/main/java/oving4/twitter/.gitkeep
Normal file
0
src/main/java/oving5/card/.gitkeep
Normal file
0
src/main/java/oving5/card/.gitkeep
Normal file
0
src/main/java/oving5/named/.gitkeep
Normal file
0
src/main/java/oving5/named/.gitkeep
Normal file
0
src/main/java/oving5/stringgrid/.gitkeep
Normal file
0
src/main/java/oving5/stringgrid/.gitkeep
Normal file
0
src/main/java/oving5/ticket/.gitkeep
Normal file
0
src/main/java/oving5/ticket/.gitkeep
Normal file
0
src/main/java/oving5/twitter/.gitkeep
Normal file
0
src/main/java/oving5/twitter/.gitkeep
Normal file
Reference in New Issue
Block a user