Problem 3: A decision tree (DT) is a type of flowchart that shows a clear pathway to a decision. In terms of data analytics, it is a type of algorithm that includes conditional control statements to classify data. A decision tree starts at a single point (or node) which then branches or splits in two or more directions. Each branch offers different possible outcomes, incorporating a variety of decisions and chance events until a final outcome is achieved.
Consider the following simple decision tree. The tree allows us to see what options are available if we are hungry.
Feeling hungry?
Y
Is it midday?
Eat lunch!
Eat dinner
N
Is it after 6pm?
Have a snack
Do work
Have a snack
Go to the gym
Work to do?
70% chance of rain
Have you worked out?
N
Go running
30% chance of rain
In this diagram, our different options are laid out in a clear, visual way. Decision nodes are white, chance node is gold, and output nodes are black.
Your program must read: 1 user's name and 2 responses to the questions. Use arrays to save all the user inputs (name, responses to the questions) and the final output. Your program must print out the output.
Design a modularized solution with two classes.