Merge pull request #50 from jkcclemens/master
Make the potato of a higher quality
This commit is contained in:
commit
88f50eb9fd
3 changed files with 64 additions and 5 deletions
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
text eol=lf
|
||||||
|
*.java text
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@ target/
|
||||||
*.class
|
*.class
|
||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
|
.idea
|
||||||
|
*.iml
|
||||||
|
|
|
@ -6,6 +6,9 @@ import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A delicious tuber that is eaten by peoples all over the world.
|
||||||
|
*/
|
||||||
public class Potato implements Tuber {
|
public class Potato implements Tuber {
|
||||||
|
|
||||||
private final List<Condiment> condiments = new ArrayList<Condiment>();
|
private final List<Condiment> condiments = new ArrayList<Condiment>();
|
||||||
|
@ -17,28 +20,57 @@ public class Potato implements Tuber {
|
||||||
System.out.println("Of course potato is prepared and delicious.");
|
System.out.println("Of course potato is prepared and delicious.");
|
||||||
} catch (NotDeliciousException e) {
|
} catch (NotDeliciousException e) {
|
||||||
System.err.println("Fatal error! How could potato not be delicious?");
|
System.err.println("Fatal error! How could potato not be delicious?");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the condiments on this potato.
|
||||||
|
*
|
||||||
|
* @return Mutable list of condiments
|
||||||
|
*/
|
||||||
|
public List<Condiment> getCondiments() {
|
||||||
|
return this.condiments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares the potato for consumption. Adds various condiments and prints them to stdout. Ensures that the potato
|
||||||
|
* is delicious. If it is not, a {@link NotDeliciousException} is thrown.
|
||||||
|
*
|
||||||
|
* @throws NotDeliciousException If the potato is not delicious
|
||||||
|
*/
|
||||||
public void prepare() throws NotDeliciousException {
|
public void prepare() throws NotDeliciousException {
|
||||||
this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "salt", "tabasco");
|
this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "salt", "tabasco");
|
||||||
this.listCondiments();
|
this.listCondiments();
|
||||||
if (!this.isDelicious()) throw new NotDeliciousException();
|
if (!this.isDelicious()) throw new NotDeliciousException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds condiments to the potato.
|
||||||
|
*
|
||||||
|
* @param names Names of the condiments to add
|
||||||
|
*/
|
||||||
public void addCondiments(String... names) {
|
public void addCondiments(String... names) {
|
||||||
for (String condimentName : names) {
|
for (String condimentName : names) {
|
||||||
this.condiments.add(new Condiment(condimentName));
|
this.getCondiments().add(new Condiment(condimentName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the names of the condiments on this potato to stdout.
|
||||||
|
*
|
||||||
|
* @see #getCondiments()
|
||||||
|
*/
|
||||||
public void listCondiments() {
|
public void listCondiments() {
|
||||||
for (Condiment condiment : this.condiments) {
|
for (Condiment condiment : this.getCondiments()) {
|
||||||
System.out.println(condiment.getName());
|
System.out.println(condiment.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the potato is put into the oven.
|
||||||
|
*
|
||||||
|
* @return true if potato is in the oven, false if otherwise
|
||||||
|
*/
|
||||||
public boolean isPutIntoOven() {
|
public boolean isPutIntoOven() {
|
||||||
try {
|
try {
|
||||||
final URL url = new URL("https://www.google.com/search?q=potato");
|
final URL url = new URL("https://www.google.com/search?q=potato");
|
||||||
|
@ -53,20 +85,38 @@ public class Potato implements Tuber {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this potato is baked. Returns the result of {@link #isPutIntoOven()}.
|
||||||
|
*
|
||||||
|
* @return true if this potato is baked, false if otherwise
|
||||||
|
*/
|
||||||
public boolean isBaked() {
|
public boolean isBaked() {
|
||||||
return this.isPutIntoOven();
|
return this.isPutIntoOven();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this potato is delicious. Returns the result of {@link #isBaked()}.
|
||||||
|
*
|
||||||
|
* @return true if this potato is delicious, false if otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isDelicious() {
|
public boolean isDelicious() {
|
||||||
return this.isBaked();
|
return this.isBaked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Propagates a new potato.
|
||||||
|
*
|
||||||
|
* @return A new potato
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Tuber propagate() {
|
public Tuber propagate() {
|
||||||
return new Potato();
|
return new Potato();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type of food added to tubers.
|
||||||
|
*/
|
||||||
private class Condiment {
|
private class Condiment {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
@ -74,6 +124,11 @@ public class Potato implements Tuber {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of this condiment.
|
||||||
|
*
|
||||||
|
* @return Name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue