Question

In: Computer Science

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”

Solutions

Expert Solution

Done accordingly. Please comment for further help.

Code:

package Testing;

import java.util.Scanner;

public class AgeMessages {
   public static void main(String[] args) {
       Scanner input=new Scanner(System.in);
       System.out.print("Please give age :");
       int age=input.nextInt();
      
       if(age<0) {
           System.out.println("Invalid Input.");
       }else {
           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.");
       }
      
       input.close();
   }
}

Output:


Related Solutions

Write a JAVA program to display your complete names, your matric number and your course of...
Write a JAVA program to display your complete names, your matric number and your course of study, using the two access modifiers stated in (a) and (b) (a) Use static access modifier for the method declaration of the program class, also use class name Eee532MakeUp. Use any method name of your choice. (b) Use public access modifier for the method declaration of the program class, also use class name EceCourseJava. (2) Which of the programs in (a) or (b) is...
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
Q1) Input your age and display what your age would be next year. Submit screenshots from...
Q1) Input your age and display what your age would be next year. Submit screenshots from Marie. My age is 21 and please provide clear screenshots. Q2)  Get your age and your friend's age Determine who is the youngest Determine who is the oldest My age is 21 and my friend is 22 Marie is a stimulator and the program is Java. Kindly provide the work !!
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
Meant to be written in Java JDK 14.0 Write a program to display the conversion table...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
Java - Write a program to calculate a user’s BMI and display his/her weight status. The...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The status is defined as Underweight, Normal, Overweight and obese if BMI is less than 18.5, 25, 30 or otherwise respectively. You need to read weight (in kilogram) and height (in metre) from the user as inputs. The BMI is defined as the ratio of the weight and the square of the height. [10 marks]
I am trying to write a program in Java: Pick 4 cards and display the cards...
I am trying to write a program in Java: Pick 4 cards and display the cards and their total value (Ace = 1, King = 13, Queen = 12, and Jack 11...etc. , BUT you should check that no card is a duplicate... there is only one "Ace of Spades" per deck for example. I need to utilize the displayMenu so the program continues to run for the user without breaking. My program is not running correctly. import java.util.Scanner; import...
Write a complete java program to get input of a person’s age and their years of...
Write a complete java program to get input of a person’s age and their years of current USA citizenship. Tell them if they are eligible to run for US House of Representatives, US Senate, or President. At first, have the program just run once and give the answer for the given inputs. Give the answer in a nice format and be clear which offices the person can run for. Write good and complete pseudo code. Next, put that program in...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move across the Frame and randomly change direction when they hit the edge of the screen. Do this by creating a Dot class and making each dot an object of that class. You may reuse code written in class for this part of the assignment. Create a subclass of the Dot class called PlayerDot that is controlled by the player through keyboard input (arrow keys)...
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT