Question

IN JAVA PROGRAMMING Write a program using Scanner to help you decide what to do this...

IN JAVA PROGRAMMING

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 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

The problem can be solved by testing a lot fewer cases than 8, but if you get confused, the full 8 case solution might provide a way to understand all of the possibilities.

Grading Elements

  • Program uses nested if statements to separate various cases
  • Program displays the correct action
  • Program displays exactly one action per run
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Weekend {

   public static void main(String[] args)
   {
       Scanner s = new Scanner(System.in);
       char parentVisit, goodWeather, areYouRich;
       System.out.println("Are parents visiting?");
       parentVisit = s.next().charAt(0);
      
       if(parentVisit=='y') // if parents come we will go to cineman
           System.out.println("We'll go to the cinema.");
       else                // if they don't
       {
           System.out.println("Is the weather good?");
           goodWeather = s.next().charAt(0);
           System.out.println("Are you rich?");
           areYouRich = s.next().charAt(0);
           if(goodWeather=='y')//if weather is good
               {
               if(areYouRich=='y')//and you are rich then you will go shopping
                   System.out.println("I'll go shopping.");
               else//if you are poor with a good weather you go to the cinema
                   System.out.println("I'll go to the cinema.");
               }
           else//if weather is bad
           {
               if(areYouRich=='y')//and you are rich, you go to cinema.
                   System.out.println("I'll go to the cinema.");
               else//if you are poor and the weather is bad as well, you just stay in..
                   System.out.println("I'll just stay in..");
           }
              
       }

   }

}

Add a comment
Know the answer?
Add Answer to:
IN JAVA PROGRAMMING Write a program using Scanner to help you decide what to do this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • The Requirement (What you need to do) You are asked to write a program that takes...

    The Requirement (What you need to do) You are asked to write a program that takes as input a dollar amount, and then displays the dollar amount in English (similar to how you would write the amount in a check). Use case (Scenario) $PrintDollar Enter the dollar amount:$23.45 It's twenty three and 45/100 Try again(y/n):n Bye! Error handling: You are required to handle the following error inputs. If the input is any of the following case, your program should display...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I...

    Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • package week_3; /** Write a program that can help decide if a particular programming project is...

    package week_3; /** Write a program that can help decide if a particular programming project is best solved using a Waterfall or Agile methodology. Your program should ask the user: • How many programmers will be on the team [ More than 30 programmers -> Waterfall ] • If there needs to be firm deadlines and a fixed schedule [ Yes - > Waterfall ] • If the programmers have experience in requirements, analysis and testing as well as coding...

  • Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent...

    Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent generates a secret letter for the user to guess. The user must be able to take turns guessing the secret letter, with the Al responding to the user's guesses. After successfully guessing, the user must be allowed to play again. The Al must count how many turns the user has taken. Here is an example of a game in progress where the human user...

  • Help pls! and kindly explain how you do this as well. Thaank you Write a program...

    Help pls! and kindly explain how you do this as well. Thaank you Write a program to test whether a square is a 3x3 magic square. A magic square is a grid with 3 rows and 3 columns, like the figure below. A magic square has the following properties: the grid contains only the numbers 1 through 9 the sum of each row, each column, and each diagonal all add up to the same number Notes: I have provided the...

  • Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a str...

    Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right. Examples: 3 a) radar à is a palindrome b)Able was I ere I saw Elba à is a palindrome e good à not a palindrome Write java program to read a line of text and tell...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT