java


Write a java program using Scanner to help you decide what to do this weekend


I need help with when asking the questions how do i get the question answered i think my teacher what me to use yes or no. how to i get the program to understand the yes or no and letting that equal true or false. below is the question and under that will be the code i already have.
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 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
public class WhatWeDoing {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int N;
int Y;
boolean parentsVisiting = false;
boolean weatherGood = false;
boolean imRich = false;
//prompt user to answer questions yes or no
System.out.print("Are Parents Visiting? Y or N ");
int parents = input.nextInt();
System.out.print("Is the Weather Good? Y or N");
int weather = input.nextInt();
System.out.print("Are You Rich? Y or N");
int Rich = input.nextInt();
{
if (parentsVisiting == false && weatherGood == true && imRich == true) {
System.out.println("Go Shopping! ");
} else if (parentsVisiting == false && weatherGood == false && imRich == false) {
System.out.println("Stay in!");
} else {
System.out.println("Cinema!");
}
}
System.out.println("What you should do is: ");
}
}
You can use input.next().equals and then set your boolean accordingly.
import java.util.Scanner;
public class Main {
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 (input.next().equals("Y"))
parentsVisiting = true;
System.out.print("Is the Weather Good? Y or N");
if (input.next().equals("Y"))
weatherGood = true;
System.out.print("Are You Rich? Y or N");
if (input.next().equals("Y"))
imRich = true;
System.out.println("What you should do is: ");
if (!parentsVisiting && weatherGood && imRich) {
System.out.println("Go Shopping! ");
} else if (!parentsVisiting && !weatherGood && !imRich) {
System.out.println("Stay in!");
} else {
System.out.println("Cinema!");
}
}
}
test
Are Parents Visiting? Y or N Y
Is the Weather Good? Y or NN
Are You Rich? Y or NY
Cinema!
First, you should scan 'Strings' or 'chars', as the user was required
Second, a nice way to getting the value:
//in case of 'char':<br>
Boolean a = (parentsVisiting == 'Y');
or:
//in case of 'String':<br>
Boolean a = parentsVisiting.equals("Y");
The "normal" way to do it will be using 'char' if it is just homework.
Solving it with 'String' helps with lower and uppercase, as well as with unexpected input

Related Links

Java - Reversing the way the output is shown
libgdx: Error java.lang.NullPointerException [duplicate]
Unable to retrieve the file data from parse.com in android
Java transfer from HDFS to S3
Continue after catching exception (Android/Java)
Recover the deleted project android studio [duplicate]
setting ImageAdapter for retrieveing image
Java reflection isAccessible method
java.util.observer with multiple JFrame
Adding Views with Java LayoutInflater in a loop either doesn't set the width or only adds the first item in the loop
Using a ListenableFuture Azure call inside an AsyncTask
What is the error in the following Queue implementation using linked list?
How to configure spring-data-mongodb to use a replica set via properties
Effective data-structure for maintaining state information of multiple servers
Adding Apache POI 3.12 to Eclipse
Reason of the OpenJPA Error in Web - You cannot access the EntityTransaction when using managed transactions

Categories

HOME
hive
mockito
google-docs
google-oauth
gps
google-project-tango
installshield
ezpublish
fancybox
azure-media-services
mouse
azure-storage-tables
tomcat6
correlation
orchardcms
quickfix
caml
pugjs
oracle-coherence
text-rendering
introduction
jtextfield
reverse-proxy
zapier
arabic
qhull
phpfox
windows-error-reporting
maxmind
kendo-datasource
c++-amp
lightswitch-2013
.net-4.0
functor
catch-all
perlin-noise
webtest
accelerate-framework
overriding
automake
gesture
neuroscience
occlusion
sharefile
ssjs
squib
pdf-reactor
total-commander
flashair
convertapi
angular2-meteor
hibernate-tools
pango
react-scripts
logparser
boost-multi-index
nativeapplication
forever
worker-thread
kbuild
pillow
pdfclown
flutterwave
passport-google-oauth
removechild
xml-attribute
player
moveit
packagist
rvest
lib.web.mvc
thredds
libressl
emailrelay
graph-drawing
sonarqube5.1.2
facebook-graph-api-v2.4
tablelayout
gui-test-framework
titanium-modules
yorick
kgdb
dealloc
flexmojos
gridfs
runtime.exec
excel-2003
xamlparseexception
sharp-repository
tinn-r
multipage
bubble-chart
spring-portlet-mvc
custom-backend
genshi
coercion
horizontal-accordion
locationlistener
appender
calling-convention
sql-server-profiler
defensive-programming
lzh

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App