It's 2020. The mentors of Codecool Phnom Pen (capital of Cambodia) are fed up, that despite the strict house rules, no one cares about collecting the waste in a selective way in the school. They decided to make an automated dustbin, which can detect different types of garbage, and can put them to different containers automatically.
Mentors at Codecool usually have a whole bunch of things to do, and they aren't exceptions either, so they don't have time to implement the dustbin's software. Luckily their internal computer is capable of running Java or C# programs...
Have you found out yet? Yes! It's your job to implement it in an object-oriented way!
- How to use the basic mechanics of Inheritance
- How to use arrays and how to make them grow in size dynamically
- How to inspect the runtime type of objects referenced by polymorphic references
- How to make decisions in your code based on the runtime type of an oject
- How to throw exceptions to signal errors, bad usage from within methods and catch those in an outer scope
- How to allow objects to display textual information about themselves in an object-oriented way
- How to use access modifiers like
privateandprotectedto achieve Data-Hinding and Encapsulation
-
Define the
Dustbinclass in an Object-Oriented way.-
Only allow instantiating
Dustbininstances by supplying a color name -
Dustbininstances allow access to the color name they were created with using thegetColor()method -
Dustbininstances allowGarbageinstances to be thrown into them using thethrowOutGarbage(Garbage)method -
Dustbininstances only allow the following kinds of garbage to be thrown into them:- cleaned
PlasticGarbage - squeezed
PaperGarbage - any other kind of
Garbage(e.g. house waste),
otherwise a
DustbinContentExceptionshould occur - cleaned
-
Dustbininstances allow access to the number of different kinds of garbages stored in them via the following methods:getHouseWasteCount()getPaperCount()getPlasticCount()
-
Dustbininstances provide a way to clear their contents via theemptyContents()method -
Dustbinshould provide a way to get its textual representation viatoString()method and it should look like this:Green Dustbin! House waste content: 2 item(s) Rotten tomato nr.1 Half-eaten lettuce nr.2 Paper content: 1 item(s) Failed exam nr.1 Plastic content: 3 item(s) Empty plastic bottle nr.1 Plastic bag nr.2 Wrapper foil nr.3 -
Dustbininstances provide possibility to print to the console their textual representation via thedisplayContents()method
-
-
Define the
Garbageclass in a way that other garbage types could use it as their base/parent class, sharing as many behaviour between parent-child as possible.- Only allow instantiating
Garbageinstances by supplying a garbage name Garbageinstances allow access to the name they were created with using thegetName()method
- Only allow instantiating
-
Define the
PlasticGarbageclass in a way that it reuses every regular garbage behaviour as possible and extends it with the notion of being cleanable.- Only allow instantiating
PlasticGarbageinstances by supplying a garbage name and a flag that signals whether they are clean or not (in this order) PlasticGarbageinstances allow access to the name they were created with just likeGarbageinstances doPlasticGarbageinstances allow checking whether they are clean or not using theisClean()methodPlasticGarbageinstances provide a way to clean them via theclean()method (if a plastic garbage is already clean using this method has no effect)
- Only allow instantiating
-
Define the
PaperGarbageclass in a way that it reuses every regular garbage behaviour as possible and extends it with the notion of being squeezable.- Only allow instantiating
PaperGarbageinstances by supplying a garbage name and a flag that signals whether they are squeezed or not (in this order) PaperGarbageinstances allow access to the name they were created with just likeGarbageinstances doPaperGarbageinstances allow checking whether they are squeezed or not using theisSqueezed()methodPaperGarbageinstances provide a way to squeeze them via thesqueeze()method (if a paper garbage is already squeezed using this method has no effect)
- Only allow instantiating
-
In your Main class write code that serves as a “movie script” for a little story. Think of the contents of the main method as series of things (statements) that happen over time in the life of an ordinary dustbin.
- Create at least one
DustBininstance and name it as you wish. - Create at least one instance of each garbage subtype but store them in
Garbagevariables. - Throw all garbage you created into the
DustBin. - Create a dirty plastic garbage and throw it to the DustBin.
- Clean one of the dirty plastic garbage and throw it to the
DustBin. - Write your bin content to the console.
- Empty your bin and print its content again to see how did it change.
- Create at least one
- Your program should be compiled without error and be executable.
- Your code should follow language specific naming convention.
- The program should notify the user when excpetional situation occurs.
- Make your life easy with formatted strings.
- In case of the different contents of Dustbin you can use simple arrays and resize them dynamically.
- To determine that a variable is a particular type or not you can use the
instanceofoperator.
Follow this link to create your project repository.
- ❗ Arrays
- ❗ OOP Basics
- ❗ OOP Basics 2
- ❗ Inheritance
- ❗ Polymorphism
- ❗ Exception handling
- 🍭 How do dynamic arrays work
- 🎥 📖 Formatted string
You will need this only at review time, after completing the project. Use this form to record the review you provide for your peer.
For now, you can check your (and everyone else's) results in the summary spreadsheet.