-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Added Fries extending Potato & Organised Potato! #193
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
Open
Supermarcel10
wants to merge
12
commits into
drtshock:master
Choose a base branch
from
Supermarcel10:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f30082a
Implemented UndercookedException for our Potato!
Supermarcel10 1b2e819
Organised our Potato
Supermarcel10 988b043
Revert "Organised our Potato"
Supermarcel10 8ed3734
Organised our Potato
Supermarcel10 3fc739b
Made our Potato Condiment static
Supermarcel10 bc43ab5
Seperated Potato object into Main and Potato
Supermarcel10 d5c8bbd
Added documentation for newly added method
Supermarcel10 04faac6
Removed UndercookedException due to NotDeliciousException already cov…
Supermarcel10 ab2838c
Added Fries which extend Potato.
Supermarcel10 0382944
Caught BurntException and added methods to find out how our Potato burnt
Supermarcel10 377b5b6
Added a method to change our Potato into Fries.
Supermarcel10 9ba9175
Reindented Potato's code in spaces
Supermarcel10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.drtshock; | ||
|
|
||
| import org.drtshock.exceptions.BurntException; | ||
| import org.drtshock.exceptions.NotDeliciousException; | ||
| import org.drtshock.types.NotDeliciousReason; | ||
|
|
||
| public class Fries extends Potato { | ||
|
|
||
| public Fries(boolean isVegan) { | ||
| super(isVegan); | ||
| } | ||
|
|
||
| public void prepare() throws NotDeliciousException, BurntException { | ||
| this.addCondiments("salt", "pepper"); | ||
| if (!this.isVegan()) this.addCondiments("ketchup", "mayo"); | ||
| if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.UNDERCOOKED); | ||
| else if (Math.random() < 0.1) throw new BurntException(250 + (int) (Math.random() * 100)); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.drtshock; | ||
|
|
||
| import org.drtshock.exceptions.BurntException; | ||
| import org.drtshock.exceptions.NotDeliciousException; | ||
|
|
||
| /** | ||
| * Where the potato deliciousness begins. | ||
| */ | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
| Potato potato = new Potato(args.length == 1 && args[0].equals("--vegan")); | ||
| potato = Math.random() < 0.75 ? potato : potato.turnIntoFries(); | ||
| if (potato.isVegan()) System.out.println("This potato is vegan."); | ||
| try { | ||
| potato.prepare(); | ||
| potato.listCondiments(); | ||
| System.out.println("Of course Potato is prepared and delicious."); | ||
| } catch (NotDeliciousException e) { | ||
| System.err.println("Fatal error! How could Potato not be delicious?\nReason: " + e.getReason()); | ||
| } catch (BurntException e) { | ||
| System.err.println("Fatal error! Potato has been burnt to a crisp!\nTemperature: " + e.getTemperature() + " degrees"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| package org.drtshock; | ||
|
|
||
| import org.drtshock.exceptions.BurntException; | ||
| import org.drtshock.exceptions.NotDeliciousException; | ||
|
|
||
| public interface Tuber { | ||
| boolean isDelicious(); | ||
|
|
||
| Tuber propagate(); | ||
|
|
||
| void prepare() throws NotDeliciousException, BurntException; | ||
| } |
15 changes: 14 additions & 1 deletion
15
...ain/java/org/drtshock/BurntException.java → ...g/drtshock/exceptions/BurntException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,29 @@ | ||
| package org.drtshock; | ||
| package org.drtshock.exceptions; | ||
|
|
||
| /** | ||
| * An exception to describe that something went wrong with our oven! | ||
| */ | ||
| public class BurntException extends Exception { | ||
|
|
||
| private int temperature; | ||
| private long bakeTime; | ||
|
|
||
| public BurntException(int degrees) { | ||
| super("Potato is badly burnt by trying to boil it at " + degrees + " degrees!!"); | ||
| this.temperature = degrees; | ||
| } | ||
|
|
||
| public BurntException(long bakeTime) { | ||
| super("Potato is badly burnt by baking for too long!! (" + bakeTime + "ms)"); | ||
| this.bakeTime = bakeTime; | ||
| } | ||
|
|
||
| public int getTemperature() { | ||
| return temperature; | ||
| } | ||
|
|
||
| public long getBakeTime() { | ||
| return bakeTime; | ||
| } | ||
|
|
||
| } |
4 changes: 3 additions & 1 deletion
4
...a/org/drtshock/NotDeliciousException.java → ...ock/exceptions/NotDeliciousException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main/java/org/drtshock/OvenException.java → ...rg/drtshock/exceptions/OvenException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...java/org/drtshock/NotDeliciousReason.java → ...rg/drtshock/types/NotDeliciousReason.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package org.drtshock; | ||
| package org.drtshock.types; | ||
|
|
||
| /** | ||
| * Different ways the potato can be not delicious | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.