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

JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
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.
Question 1: Write a Java program that prompts the user to input a file name (existing...
Question 1: Write a Java program that prompts the user to input a file name (existing text file), then calculate and display the numbers of lines in that file. Also calculate and display the length of the longest line in that file. For example, if the input file has the following lines: Hello This is the longest line Bye The output should be: The file has 3 lines. The longest line is line 2 and it has 24 characters. Test...
Write a Java application that prompts the user for an age. If the age entered is...
Write a Java application that prompts the user for an age. If the age entered is greater or equal to 65, display the statement "Age is greater than or equal to 65"; otherwise display the message "Age is less than 65". If the age entered is less than 18; display the statement "This person is a minor"; otherwise display the message "This person can legally vote. Do not create a class for this application. The code can be created in...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT