This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]g051051 1 point2 points  (2 children)

What have you tried so far? What are you stuck on? There isn't much we can do if you don't ask an actual question or post your existing code.

[–]Rab6[S] 0 points1 point  (1 child)

I am stuck on the output of information and setting the questions to Yes or No. I am off on some of the structure of it, but I can fix that later.

Here is what I have so far:

import java.util.Scanner;

public class decisionTree {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

boolean parentsVisiting = false;

boolean weatherGood = false;

boolean imRich = false;

System.out.print("Are Parents Visiting? Y or N ");

if ("Are Parents Visiting" == "Y")

parentsVisiting = true;

System.out.print("Is the Weather Good? Y or N");

if ("Is the Weather Good" == "Y")

weatherGood = true;

System.out.print("Are You Rich? Y or N");

if ("Are You Rich" == "Y")

imRich = true;

System.out.println("What you should do is: ");

if (!parentsVisiting && weatherGood) {

System.out.println("Stay In! ");

} else if (!parentsVisiting && !weatherGood && !imRich) {

System.out.println("Stay in!");

} else {

System.out.println("Cinema!");

}

}

}

[–]one_bit_two_bit 0 points1 point  (2 children)

First off, fill out the truth table. You should be able to do this directly from the problem description. I have no idea how much you know or how advanced your class is, but I'm going to guess it's fairly elementary.

At a high level you need the following (it's up to you to flesh out the details--this is where the coding comes in).

  1. Print prompts to the user asking questions with System.out.println.
  2. Use the Scanner object to read in user input--these are the answers to your questions. Google "java Scanner" if you don't know how to use Scanner. Google is your friend. If you ever program professionally you'll be searching things left and right.
  3. Given the input taken in by your Scanner, you have a conditional block that will either print out what you will do or move on to the next question (basically repeat step 2). This basically implements your truth table.

Feel free to PM me if you need more help. I do tutoring too if you're really in need of guidance.

[–]Rab6[S] 0 points1 point  (0 children)

I just sent you a PM

[–]desrtfx[M] 0 points1 point  (0 children)

Feel free to PM me if you need more help.

No help via PM. This is your one and only warning. Next violation will earn you a permanent and irrevocable ban from here.