Question

(java)Write the “Will I eat lunch” program (Use Nested If statements). Declare variables for each criteria....

(java)Write the “Will I eat lunch” program (Use Nested If statements). Declare variables for each criteria. (haveMoney, haveTime, amHungry, restaurantOpen, haveTransportation ) Have the user input the values for each criteria. Use Nested if statements to determine if user will eat lunch today. Inform the user why they are or are not having lunch at McDonalds.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class WillIEatLunch {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        boolean haveMoney, haveTime, amHungry, restaurantOpen, haveTransportation;
        System.out.print("Do you have money(true or false): ");
        haveMoney = in.nextBoolean();
        System.out.print("Do you have time(true or false): ");
        haveTime = in.nextBoolean();
        System.out.print("Are you hungry(true or false): ");
        amHungry = in.nextBoolean();
        System.out.print("Is the restaurant open(true or false): ");
        restaurantOpen = in.nextBoolean();
        System.out.print("Do you have transportation(true or false): ");
        haveTransportation = in.nextBoolean();
        if (haveMoney) {
            if (haveTime) {
                if (amHungry) {
                    if (restaurantOpen) {
                        if (haveTransportation) {
                            System.out.println("Yes, You can eat today.");
                        } else {
                            System.out.println("No, You can't eat today, because of no transportation!");
                        }
                    } else {
                        System.out.println("No, You can't eat today, because restaurant is not open!");
                    }
                } else {
                    System.out.println("No, You can't eat today, because you are not hungry!");
                }
            } else {
                System.out.println("No, You can't eat today, because you don't have time!");
            }
        } else {
            System.out.println("No, You can't eat today, because you don't have money!");
        }
    }
}

Add a comment
Know the answer?
Add Answer to:
(java)Write the “Will I eat lunch” program (Use Nested If statements). Declare variables for each criteria....
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
  • Java Eclipse program Write statements to declare and initialize eight constants, one for each of the...

    Java Eclipse program Write statements to declare and initialize eight constants, one for each of the primitive types in Java. boolean, byte, char, short, int, long, float and double. Add statements to print the name of the constant and its value to your VariableDefinitions.javaprogram and compile the program. Assign a new value to one of the constants and compile. Comment out the lines of code that cause compilation errors but do not delete them and recompile your program.

  • *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create...

    *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create an array of doubles named “hummus” with 2 rows and 300 columns. Initialize all array elements to zero. Write a loop that will repeatedly ask the user to enter a value and store it in the first row of the array (do not overwrite previously entered values) until the whole first row is populated with the user input. (hint the loop should have the...

  • I am having problems with my java homework in class. Write a program that will interactively...

    I am having problems with my java homework in class. Write a program that will interactively read the name, age, weight in pounds, and height in inches for five people and output the BMI for each one. At the end of the program, it should output the average age, average height and average weight of the five participants. IT HAS TO INCLUDE: Declare and use a program constant of data type int named CONVERSION_FACTOR to represent the value 703. Use...

  • Write a java program that will print out the following patters. Use nested for loop.101101010110101

    Write a java program that will print out the following patters. Use nested for loop.101101010110101

  • ***LOOPS NOT ALLOWED*** String variables and use of String methods: Write a complete Java program which...

    ***LOOPS NOT ALLOWED*** String variables and use of String methods: Write a complete Java program which prompts the user for a string with 3 words each separated by a single space and reads the line into one String variable using nextline(). Extract each word and add them to a new String variable in reverse order with a space between the words. Have the 1st letter of the new string in upper case and all other strings in lower case letter....

  • Write a function (NOT a complete program) that displays the following picture. Use nested for loops...

    Write a function (NOT a complete program) that displays the following picture. Use nested for loops inside of the program. ||#|@|#|(a) | # | @ # | @ #|(a) | # | @ You do not need to ask the user for input and can assume that there are only 6 columns

  • Using java Sample Outputs Write a program which asks the user for an integer and then...

    Using java Sample Outputs Write a program which asks the user for an integer and then prints the following patterns based on that integer. Input Validation For Pattern 1, the input must be a value between 1 and 999 For Pattern 2, the input must be a value between 1 and 26. Requirements: For Pattern 1: must be able to work with up to three digit numbers. You will want to use printf to get the spacing correct. For Pattern...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • WRITE THIS PROGRAM IN JAVA CODING ONLY ! Program 1: In Order Using an IF/ELSE IF/ELSE...

    WRITE THIS PROGRAM IN JAVA CODING ONLY ! Program 1: In Order Using an IF/ELSE IF/ELSE structure, write a program that will prompt the user for three numbers and displays them in ascending order. First, the program will prompt the user for each of the three numbers. Next, find the smallest value of the three. Then decide which of the other two is the next smallest. Then have the program display the three numbers in ascending order. Be sure to...

  • Write a Java program that determines if a person hits the "Pick 3" loterry numbers. Have...

    Write a Java program that determines if a person hits the "Pick 3" loterry numbers. Have the program to randomly create a 3 digit lottery number. Have the user enter the number they will be playing and the results: (DO NOT USE ARRAYS or STRINGS) -If the user input matches the lottery number in the exact order, the award is $5Million. -If all the digits in the user input match all the digits in the lottery number, the award is...

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