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

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...
Write a Java program that will display different messages depending on your age. Your program should...
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...
Write a program that reads in a single integer. Display a message depending on what is...
Write a program that reads in a single integer. Display a message depending on what is given: When the number is 42, output "42 is the Ultimate Question of Life, the Universe, and Everything." When the number is 2020 output "2020 is the current year." When the number is greater than 1000 and less than 3000 output "1500 could be a year." where 1500 is the number the user originally inputted When none of the above, output "no idea." One...
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...
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
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 the program in Java (with a graphical user interface) and have it calculate and display...
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. Allow the user to loop back and enter new data or quit. You need to include Calculate, Reset, and Exit buttons on your GUI. Please insert comments in the program to document the program. Allow the user to enter...
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199   Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT