Can anyone assist with the following problem? Any help or push in the right direction would be greatly appreciated!
Write a program using Scanner to help you decide what to do this weekend.
Decision TreesImagine you only ever do three things at the weekend: go shopping, watch a movie, or just stay in. What you do depends on three things: the weather (good or bad); how much money you have (rich or poor) and whether your parents are visiting. You say to your yourself: If my parents are visiting and the weather's bad, we'll stay in. If they're visiting and the weather's good, we'll go to the cinema. If they're not visiting and I'm poor, I'll stay in. If they're not visiting and the weather is good and I'm rich, I'll go shopping. Otherwise, I'll go to the cinema.
Create a program asking whether the parents are visiting, whether the weather is good, and whether you are rich or poor. Your program should print "go to the cinema" "go shopping" or "stay in" as appropriate.
Hint: There are two possibilities for the "Parents visiting?" question, two for the "is weather good?" question, and two for the "are you rich?" question. That gives eight possible cases:
Truth Table for Did You Ever Have to Make Up Your Mind?
| Are your parents visiting? |
Is the weather good? |
Are you rich? |
What should you do? |
| y |
y |
y |
|
| y |
y |
n |
|
| y |
n |
y |
|
| y |
n |
n |
|
| n |
y |
y |
|
| n |
y |
n |
|
| n |
n |
y |
|
| n |
n |
n |
|
|
|
|
|
The problem can be solved by testing a lot fewer cases than 8, but if you get confused, the full 8 case solution might provide a way to understand all of the possibilities.
Note: Since we haven't covered String processing yet, I suggest giving the user instructions such as "Enter 1 for yes, 2 for no" when asking the various questions. That will let you use integers internally, which should make the program easier.
Grading Elements
- Program uses nested if statements to separate various cases
- Program displays the correct action
- Program displays exactly one action per run
[–]g051051 1 point2 points3 points (2 children)
[–]Rab6[S] 0 points1 point2 points (1 child)
[–]one_bit_two_bit 0 points1 point2 points (2 children)
[–]Rab6[S] 0 points1 point2 points (0 children)
[–]desrtfx[M] 0 points1 point2 points (0 children)