Fixed: Make potato compile
Also removed GLaDOS (not really a potato). Added a listCondiments method. Formatted code.
This commit is contained in:
parent
5c3010c4c1
commit
d15e2073e5
2 changed files with 64 additions and 67 deletions
|
@ -1,54 +1,61 @@
|
||||||
package org.drtshock;
|
package org.drtshock;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
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>();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Potato potato = new Potato();
|
final Potato potato = new Potato();
|
||||||
GLaDOS glados = new GLaDOS();
|
|
||||||
if (potato.prepare()) System.out.println("Of course potato is prepared and delicious.");
|
if (potato.prepare()) System.out.println("Of course potato is prepared and delicious.");
|
||||||
else System.err.println("Fatal error! How could potato not be delicious?");
|
else System.err.println("Fatal error! How could potato not be delicious?");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean prepare() {
|
public boolean prepare() {
|
||||||
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();
|
||||||
return this.isDelicious();
|
return this.isDelicious();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCondiments(String... names) {
|
public void addCondiments(String... names) {
|
||||||
synchronized (condiments) {
|
synchronized (this.condiments) {
|
||||||
for (String condimentName : names) condiments.add(new Condiment(condimentName));
|
for (String condimentName : names) this.condiments.add(new Condiment(condimentName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPutintoOven {
|
public void listCondiments() {
|
||||||
URL url = new URL("https://www.google.com/");
|
for (Condiment condiment : this.condiments) {
|
||||||
|
System.out.println(condiment.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPutIntoOven() {
|
||||||
|
try {
|
||||||
|
final URL url = new URL("https://www.google.com/");
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
int inOven = connection.getResponseCode();
|
int inOven = connection.getResponseCode();
|
||||||
if (inOven == 200) return true; // you need to put into an oven before bake it.
|
return inOven == 200;
|
||||||
else return false;
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBaked() {
|
public boolean isBaked() {
|
||||||
if(this.isPutintoOven) return true;
|
return this.isPutIntoOven();
|
||||||
else return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDelicious() {
|
public boolean isDelicious() {
|
||||||
if(isBaked) return true; // this way we could move on to our condiments. =D
|
return this.isBaked();
|
||||||
else return false; // you don't eat a raw potato, don't you?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tuber propagate() {
|
public Tuber propagate() {
|
||||||
return new Potato();
|
return new Potato();
|
||||||
}
|
}
|
||||||
|
@ -65,15 +72,4 @@ public class Potato implements Tuber {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class GLaDOS extends Potato {
|
|
||||||
public GLaDOS() {
|
|
||||||
System.out.println("Oh hi, how are you holding up? BECAUSE I'M A POTATO... clap clap clap... oh good, my slow clap processor made it into this thing, at least we have that.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDelicious() {
|
|
||||||
return false; // robots are not delicious
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,6 @@ package org.drtshock;
|
||||||
|
|
||||||
public interface Tuber {
|
public interface Tuber {
|
||||||
public boolean isDelicious();
|
public boolean isDelicious();
|
||||||
|
|
||||||
public Tuber propagate();
|
public Tuber propagate();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue