Did You Ever Have To Make Up Your Mind? (In JAVA programming; I already asked th
ID: 3871360 • Letter: D
Question
Did You Ever Have To Make Up Your Mind? (In JAVA programming; I already asked this question before, but the person who answered it made it so complicated that I did not understand anything, could someone please make this in the simplest Beginner Java form. I appreciate it)
Write a program using Scanner to help you decide what to do this weekend. Decision Trees Imagine 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, we'll go to the cinema. If they're not visiting and the weather's good and I'm rich, then I'll go shopping. If they're not visiting, and the weather's good and I'm poor, then I will go to the cinema. If they're not visiting and the weather is bad and I'm rich, I'll go to the cinema. If they're not visiting and the weather is bad and I'm poor, I'll stay in. 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 parents visiting? Is the weather good? Are you rich? What you doExplanation / Answer
Find the programe for above question
package com;
import java.util.Scanner;
public class WeekandActivity {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Parents visiting :");
String pvisit=sc.nextLine();
Scanner sc1 = new Scanner(System.in);
System.out.println("is weather good :");
String wgood=sc1.nextLine();
Scanner sc2 = new Scanner(System.in);
System.out.println("are you rich :");
String rich=sc2.nextLine();
String finalDecision=myDecision(pvisit,wgood,rich);
System.out.println(finalDecision);
}
public static String myDecision(String parentVisit,String wheterGood,String ImRich){
String result="";
if(parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result="go to the cinema";
}
else if(!parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result ="I'll go shopping ";
}
else if(!parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result="go to the cinema";
}
else if (!parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result="go to the cinema";
}
else if (!parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result ="I'll stay in";
}
else if(parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result ="I'll go shopping ";
}
else if(parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result ="go to the cinema";
}
else if(parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result ="I'll stay in";
}
return result;
}
}
OUT PUT
Parents visiting :
no
is weather good :
no
are you rich :
yes
go to the cinema