diff options
author | Camil Staps | 2015-06-10 08:15:16 +0200 |
---|---|---|
committer | Camil Staps | 2015-06-10 08:15:16 +0200 |
commit | 98e209683cfa0e0fd7c35eb7d08c5bf2cfc0e30d (patch) | |
tree | 83ca755fd5083934e0d9a882a581bb646917af34 /Week16 Ice Cream | |
parent | Start w16 ice cream (diff) |
Week 16 ice cream
Diffstat (limited to 'Week16 Ice Cream')
8 files changed, 340 insertions, 4 deletions
diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/ChocoTopping.java b/Week16 Ice Cream/src/com/camilstaps/icecream/ChocoTopping.java new file mode 100644 index 0000000..5bdcbf5 --- /dev/null +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/ChocoTopping.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.camilstaps.icecream; + +/** + * Choco topping + * @author Camil Staps + */ +public class ChocoTopping extends Topping { + + public ChocoTopping(IceCream base) { + super(base); + description = "choco dip"; + } + + @Override + public int getPrice() { + return super.getPrice() + 30; + } + +} diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/IceCream.java b/Week16 Ice Cream/src/com/camilstaps/icecream/IceCream.java new file mode 100644 index 0000000..452e69e --- /dev/null +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/IceCream.java @@ -0,0 +1,51 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.camilstaps.icecream; + +/** + * A general ice cream + * @author Camil Staps + */ +public abstract class IceCream { + + /** + * Set this attribute in the constructor of your subclass + */ + protected String description = "Unknown ice cream"; + + /** + * The description of the ice cream + * @return + */ + public String getDescription() { + return description; + } + + /** + * The price of the ice cream in cents + * @return + */ + abstract public int getPrice(); + +} diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/SpecklesTopping.java b/Week16 Ice Cream/src/com/camilstaps/icecream/SpecklesTopping.java new file mode 100644 index 0000000..47fe9de --- /dev/null +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/SpecklesTopping.java @@ -0,0 +1,37 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.camilstaps.icecream; + +/** + * Speckles topping + * @author Camil Staps + */ +public class SpecklesTopping extends Topping { + + public SpecklesTopping(IceCream base) { + super(base); + description = "speckles"; + } + +} diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/Topping.java b/Week16 Ice Cream/src/com/camilstaps/icecream/Topping.java new file mode 100644 index 0000000..0995698 --- /dev/null +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/Topping.java @@ -0,0 +1,60 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.camilstaps.icecream; + +/** + * A topping is an ice cream with something + * @author Camil Staps + */ +public abstract class Topping extends IceCream { + + /** + * The ice cream to put topping on + */ + private final IceCream base; + + /** + * Create a new ice cream with topping + * @param base the ice cream + */ + public Topping(IceCream base) { + this.base = base; + description = "unknown topping"; + } + + @Override + public String getDescription() { + return base.getDescription() + " with " + description; + } + + /** + * Overriding this method shows that it would be possible to charge a base 10ct for every tpoping, for example + * @return + */ + @Override + public int getPrice() { + return base.getPrice(); + } + +} diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/VanillaIceCream.java b/Week16 Ice Cream/src/com/camilstaps/icecream/VanillaIceCream.java new file mode 100644 index 0000000..c777267 --- /dev/null +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/VanillaIceCream.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.camilstaps.icecream; + +/** + * Vanilla ice cream + * @author Camil Staps + */ +public class VanillaIceCream extends IceCream { + + public VanillaIceCream() { + description = "Vanilla ice cream"; + } + + @Override + public int getPrice() { + return 150; + } + +} diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/Week16IceCream.java b/Week16 Ice Cream/src/com/camilstaps/icecream/Week16IceCream.java index df72e2e..6ed39e2 100644 --- a/Week16 Ice Cream/src/com/camilstaps/icecream/Week16IceCream.java +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/Week16IceCream.java @@ -1,19 +1,41 @@ /* - * Copyright (c) 2015 Camil Staps + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ package com.camilstaps.icecream; /** - * - * @author camilstaps + * Solutions to week 16, part 1 + * @author Camil Staps */ public class Week16IceCream { /** + * Example making a yoghurt ice cream with choco topping and whipped cream * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here + IceCream iceCream = new WhippedCreamTopping(new ChocoTopping(new YoghurtIceCream())); + System.out.println(iceCream.getDescription() + " - " + iceCream.getPrice() + "ct"); } } diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/WhippedCreamTopping.java b/Week16 Ice Cream/src/com/camilstaps/icecream/WhippedCreamTopping.java new file mode 100644 index 0000000..9d45821 --- /dev/null +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/WhippedCreamTopping.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.camilstaps.icecream; + +/** + * Whipped cream topping + * @author Camil Staps + */ +public class WhippedCreamTopping extends Topping { + + public WhippedCreamTopping(IceCream base) { + super(base); + description = "whipped cream"; + } + + @Override + public int getPrice() { + return super.getPrice() + 50; + } + +} diff --git a/Week16 Ice Cream/src/com/camilstaps/icecream/YoghurtIceCream.java b/Week16 Ice Cream/src/com/camilstaps/icecream/YoghurtIceCream.java new file mode 100644 index 0000000..630689a --- /dev/null +++ b/Week16 Ice Cream/src/com/camilstaps/icecream/YoghurtIceCream.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps <info@camilstaps.nl> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.camilstaps.icecream; + +/** + * Yoghurt ice cream + * @author Camil Staps + */ +public class YoghurtIceCream extends IceCream { + + public YoghurtIceCream() { + description = "Yoghurt ice cream"; + } + + @Override + public int getPrice() { + return 200; + } + +} |