Question

Q1: Write a Java program that will display different messages depending on your age. Your program...

Q1: Write a Java program that will display different messages depending on your age.

Your program should ask the user for his/her name and their age in years

and give one or more answers from the following ones below:

  • if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”.
  • if the age of the user is less than 18, the program should print on the screen “You are not allowed to vote at the moment”
  • if the age of the user is less than 25, the program should print on the screen “You are not allowed to rent a car at the moment
  • if the age of the user is greater than or equal with 25, the program should print on the screen “You can do anything that is legal”
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class AgeMessage {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter your age: ");
        int age = in.nextInt();
        if (age < 16) {
            System.out.println("You are not allowed to drive at the moment");
        }
        if (age < 18) {
            System.out.println("You are not allowed to vote at the moment");
        }
        if (age < 25) {
            System.out.println("You are not allowed to rent a car at the moment");
        }

        if (age >= 25) {
            System.out.println("You can do anything that is legal");
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
Q1: Write a Java program that will display different messages depending on your age. Your program...
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
  • 1. Write a Python program that will determine if the user can vote or not. The...

    1. Write a Python program that will determine if the user can vote or not. The program will ask the user to enter integer numbers that represent year, month, and day of birth. Also, the program will ask the user to enter the current year, current month, and current day. The program will determine if the user is allowed to vote or not. If the user age is greater than or equal 18 then the program will print the following...

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • Program specification You and your partner must write a Java program to print a simple black...

    Program specification You and your partner must write a Java program to print a simple black and white excerpt of the periodic table of elements. First you should obtain the following information from the user: whether the 'Lanthanum, group (elements 57-71) and Άctinium, group (elements 89-103) should be printed-the default is no; the atomic number of the first element to display 118 is given; and the default is 1 and should be used whenever a value less than 1 or...

  • For Java - Write a program that creates an array of 10 integers. Ask the user...

    For Java - Write a program that creates an array of 10 integers. Ask the user to enter the subscript (index) of an element, then displays the element located at that subscript. If the subscript entered is out of bounds (less than 0 or greater than length - 1), display the message "Out of Bounds".

  • . Write a complete Java program that is to be used for a psychology study into...

    . Write a complete Java program that is to be used for a psychology study into random number choices by a human volunteer. Your program is to operate as follows. (Programs that correctly carry out some of the tasks will receive partial credit. Your program should not be more than 30 lines long.) Ask the user (the volunteer) to repeatedly type 2 digit numbers onto the screen. Read the user input and discard any number that is less than 10...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • Write a java program that demonstrates recursion. This program can be in a java GUI frame...

    Write a java program that demonstrates recursion. This program can be in a java GUI frame or as a console application. On this one it is up to you. (It would probably work better as a console program for this particular program.) The input for this program is a number of boxes. Ask the user for this with a textbox or a prompt on the command line. Demonstrate recursion with a function called LoadTruck() that takes a number of boxes...

  • Need a program that outputs all possible combinations of X amount of numbers depending on the...

    Need a program that outputs all possible combinations of X amount of numbers depending on the length of the password. For example it will ask the user the length of the password and if they input 3 then it will display all possible combinations from numbers 0 through 9 so the sample output will look like. 000, 001, 002, 003, 004, 005, 006, ..................................................... 994, 995, 996, 997, 998, 999 after it will ask the user if they want to...

  • Q1. CLO: (5 points) Write a java program that reads 10 words from the keyboard then...

    Q1. CLO: (5 points) Write a java program that reads 10 words from the keyboard then place them in an array. Display the array elements in reverse order, and then count and print the number of times a word appears in that array. The user shall insert the word from the keyboard.

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

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
ADVERTISEMENT