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

Having trouble converting textfield to integer and more
javascript document.forms[0] and document.<formname> have different elements
JavaFX Table Cell Editing
Java Swing: Custom Cell Editor does not return most recent value
Remember Me, Single Session and Encrypt Cookie with HTTP (Not HTTPS)
Replace old fragment to add new fragment inside viewpager
Can javascript be used to render web pages
can we use super keyword within the main() class in java? [duplicate]
env.getProperty not working Spring PropertyPlaceholderConfigurer
ExceptionBug in java project?
Android app with onClickListener not working
Trouble with using UNICODE symbols in Java
How to delete in one time few buttons or text fields?
SimpleJDBCCall class parameter passing
Avoid Java compiler optimization of a loop and an if statement
I have a string variable and another string assigned to same variable. Then how to get old string?

Categories

HOME
sendgrid
hive
webpack
omnet++
magnific-popup
mediawiki
mockito
pycharm
xmpp
razor
filtering
google-oauth
rdf
google-project-tango
echarts
azure-media-services
bs4
communication
dax
modelica
export-to-csv
etl
windows-azure-storage
windows-server-2012
decomposition
workload-scheduler
angular-ui
lucene.net
emulator
errorlevel
tapestry
trading
crosstab
opennlp
cas
librato
preg-match-all
siesta-swift
google-qpx-express-api
webtest
xmlreader
swift3.0.2
mapzen
gulp-sourcemaps
g-code
spring-security-kerberos
jsch
hendrix
tropo
python-cryptography
messenger
passport-google-oauth
url-masking
mikroc
mongocsharpdriver
plottable.js
fuzzy-search
natvis
javax.sound.midi
jmeter-maven-plugin
map-projections
method-parameters
umbraco6
javax.mail
python-green
cctv
java-metro-framework
funcunit
seaside
ms-project-server-2010
runtime.exec
html-editor
http-unit
typoscript2
mhtml
appconkit
ohm
vdsp
calling-convention
mysql-error-1005
html-input
brewmp
procedural-music
ubuntu-9.04
grid-system

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