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

How to pass parameters to post method in Spring MVC controller while doing junit?
Integer.Parse(String) throws exception
I'm trying to make a Harry Potter spell game
How can I use private data fields for a class and still call them in my main?
How to invoke Queue Manager connection with different user?
key - value mapping in a HashMap
Why are my radiobuttons not mutually exclusive?
Surrounding JTextPane with images
How can I get a vector output?
PriorityBlockingQueue: is it realy blocking
Assigning an Integer to an Integer in java [closed]
Building a data model using kmeans algorithm and using it to classify new data set
Application stopped working when loading layout with setContentView
Renderer won't render texture
Java/Android - set DecimalFormat to show only mantissa
ClassCastException when unmarshalling JSON

Categories

HOME
image
homebrew
hashmap
relay
android-4.4-kitkat
routes
google-docs
infragistics
youtube-api-v3
cakephp-2.5
jgroups
win32gui
flyway4
portia
applepay
node-pdfkit
fancybox-3
kentor-authservices
percona
designer
seaborn
django-cms
ml
clickonce
angular2-aot
shopware
jaxb2
fabric8
airconsole
contact-form
form-data
android-nestedscrollview
espeak
webdriver-manager
opshub
quadratic-programming
nxlog
.net-4.6.2
slick-3.0
rainbowtable
zip4j
dds
rails-routing
logparser
boost-multi-index
setter
forever
sqlclient
pg-dump
ifs
cubes
deadbolt-2
fuzzy-search
persist
react-native-listview
browser-link
kendonumerictextbox
r-tree
intellij-14
citrus-pay
computer-algebra-systems
drawbitmap
processmodel
mmc
dia
ng-animate
java.util.concurrent
relocation
flask-cors
mesa
balanced-payments
geos
jmapviewer
listings
ftps
eventual-consistency
orchardcms-1.7
pygit2
smtp-auth
clipper
ohm
custom-backend
cinema-4d
servicehost
krl
disclosure
inotifycollectionchanged
datareader
telerik-scheduler
cxxtest
coda-slider
gamequery
zend-tool
misv

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