Question

In: Computer Science

(JAVA) Create a program that prompts the user for an age input. The program defines the...

(JAVA)

Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program.

Age Age Group
0 Baby
1-3 Toddler
4-11 Child
12-17 Teenager
18-21 Young Adult
22-64 Adult
65+ Senior
Negative Number Invalid Input


Sample Input
Enter an age: 18

Sample Output:
You are a young adult.
Sample Input
Enter an age: 29

Sample Output:
You are an adult.
Sample Input:
Enter an age: 10

Sample Output:
You are a child.
Sample Input:
Enter an age: -10

Sample Output:
Invalid Input

Solutions

Expert Solution

import java.util.Scanner;

public class AgeGroup {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.print("Enter age: ");
                int age = sc.nextInt();
                if (age < 0) {
                        System.out.println("Invalid input");
                } else if (age == 0) {
                        System.out.println("You are a baby");
                } else if (age >= 1 && age <= 3) {
                        System.out.println("You are a Toddler");
                } else if (age >= 4 && age <= 11) {
                        System.out.println("You are a Child");
                } else if (age >= 12 && age <= 17) {
                        System.out.println("You are an Teenager");
                } else if (age >= 18 && age <= 21) {
                        System.out.println("You are an Young Adult");
                } else if (age >= 22 && age <= 64) {
                        System.out.println("You are an Adult");
                } else if (age >= 65) {
                        System.out.println("You are an Senior");
                }
        }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Java Programming Create a program that prompts the user for an integer number and searches for...
Java Programming Create a program that prompts the user for an integer number and searches for it within an array of 10 elements. What is the average number of comparisons required to find an element in the array? Your program should print the number of comparisons required to find the number or determine that the number does not exist. Try finding the first and last numbers stored in the array. Run your program several times before computing the average.
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the...
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the number is positive, then add the number to the current sum. If the number is negative, then subtract the sum by one. Implement just the main method. Assume that all libraries are imported, and class has been declared.
TO BE DONE IN JAvA Complete the calculator program so that it prompts the user to...
TO BE DONE IN JAvA Complete the calculator program so that it prompts the user to enter two integers and an operation and then outputs the answer. Prompt the user three times, don't expect all the inputs on one line. Possible operations are + - * / No other words or symbols should be output, just the answer. Requested files import java.util.Scanner; /** * This is a simple calculator Java program. * It can be used to calculate some simple...
Write a program in JAVA that prompts the user for a lower bound and an upper...
Write a program in JAVA that prompts the user for a lower bound and an upper bound. Use a loop to output all of the even integers within the range inputted by the user on a single line.
Part A In PyCharm, write a program that prompts the user for their name and age....
Part A In PyCharm, write a program that prompts the user for their name and age. Your program should then tell the user the year they were born. Here is a sample execution of the program with the user input in bold: What is your name? Amanda How old are you? 15 Hello Amanda! You were born in 2005. Write the program. Format your code using best practices. Refer to the zyBooks style guide, if needed, to use proper naming...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user...
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user to enter a capital for a state (by getting a state/capital pair via the StateCapitals class. Upon receiving the user’s input, the program reports whether the answer is correct. The program should randomly select 10 out of the 50 states. Modify your program so that it is guaranteed your program never asks the same state within one round of 10 guesses.
Write a JAVA program that prompts the user for the number of names they’d like to...
Write a JAVA program that prompts the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT