Write a Java program that prompts the user to enter their name and age, validates the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a Java program that prompts the user to enter their name and age, validates the inputs, and prints a greeting message to the console. If the user enters an invalid age, the program should throw a custom exception called "Invalid InputException". The program should be implemented as follows: I. Create a custom exception class called "Invalid InputException that printout the error message "Invalid age: Age should be a positive integer less than or equal to 120" if the age is a negative number or greater than 120. II. Create another class "GreetingValidator" to get the user inputs through the main method. The program should prompt the user to enter their name and age. III. The program should validate the age by checking that it is a positive integer less than or equal to 120. If the age is invalid, the program should throw an Invalid InputException. If both the age is valid, the program should print a greeting message to the console that includes the user's name and age. IV. Sample Output 1: Enter your name: Ihilini Enter your age: 150 Invalid age: Age should be a positive integer less than or equal to 120. Sample Output 2: Enter your name: Thilini Enter your age: 30 Hello Thilini, you are 30 years old. Write a Java program that prompts the user to enter their name and age, validates the inputs, and prints a greeting message to the console. If the user enters an invalid age, the program should throw a custom exception called "Invalid InputException". The program should be implemented as follows: I. Create a custom exception class called "Invalid InputException that printout the error message "Invalid age: Age should be a positive integer less than or equal to 120" if the age is a negative number or greater than 120. II. Create another class "GreetingValidator" to get the user inputs through the main method. The program should prompt the user to enter their name and age. III. The program should validate the age by checking that it is a positive integer less than or equal to 120. If the age is invalid, the program should throw an Invalid InputException. If both the age is valid, the program should print a greeting message to the console that includes the user's name and age. IV. Sample Output 1: Enter your name: Ihilini Enter your age: 150 Invalid age: Age should be a positive integer less than or equal to 120. Sample Output 2: Enter your name: Thilini Enter your age: 30 Hello Thilini, you are 30 years old.
Expert Answer:
Answer rating: 100% (QA)
Heres a Java program that fulfills your requirements by creating a custom exception class called Inv... View the full answer
Related Book For
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis
Posted Date:
Students also viewed these programming questions
-
Find the intervals of increasing and decreasing for: f(x) = x4-2x3
-
Gale Company has the following inventory and purchases during the fiscal year ended December 31, 2023. Beginning Inventory Feb. 10 purchased Feb. 20 sold Mar. 13 purchased Sept. 5 Oct. 10 purchased...
-
An appropriate structure for large-scale distributed systems is as multiple, independently administered, firewall-protected, domains. Examples are a national health service, a national police service...
-
Define a passive portfolio construction strategy and briefly discuss how reasonable it might be for an investor to pursue a passive strategy. Explain the role of risk aversion in the construction of...
-
Visit the website of your choice and explore it thoroughly. Prepare a report analyzing the various functions provided by that website and its information requirements. Your report should answer these...
-
Why can real estate be an attractive portfolio holding?
-
What does the times-interest-earned ratio indicate and how is it calculated?
-
The Kyle Sports Medicine facility is a not-for-profit health care facility that is trying to determine what transaction information should be included in its calculation of the performance indicator...
-
On June 30, Collins Management Company purchased land for $400,000 and a building for $560,000, paying $360,000 cash and issuing a 5% note for the balance, secured by a mortgage on the property. The...
-
a. How many common shares are outstanding on each cash dividend date? b. What is the total dollar amount for each of the four cash dividends? c. What is the amount of the capitalization of retained...
-
Subtract: (17 7i) - (10+ 22i) difference =
-
Sketch a graph of any third-degree polynomial function that has three distinct x-intercepts, a relative minimum at (-6, -4), and a relative maximum at (3, 5).
-
1. State the names of the plaintiff and defendant: the volume number: page number: name of the reporter: court that decided the case: 2. Describe the facts of the case. 3. What was the cause of...
-
What role do collateralized mortgage obligations (CMOs) play in structuring mortgage-backed securities to meet the diverse risk and return preferences of investors, and how do tranche prioritization...
-
Log into the Wall Street journal with a free account to access the articles. brief 2-3 sent. response to eat answering the question. 1) Read the article The Man Who Drove the VW Beetle's American...
-
5.96x10^24kg Therefore, the mass of the earth is =2.2 lbs). Is your answer close to 5.98 x 1024 kg? kilograms (1 kg 2.2 Assuming an average human has a mass of 70. Kg, how many humans would it take...
-
What are the forms and functions of capital income? What is the difference between short-run conditions and long-run conditions? Do marketers use short-run costs and long-run costs to make economic...
-
All of the following assets can be depreciated, except: (a) A bulldozer (b) A copper mine (c) A surgical robot (d) A conveyor belt
-
Rewrite the following mouse motion listener so it uses an adapter class: Private class MyMouseMotionListener implements MouseMotionListener { Public void mouseDragged(MouseEvent e) { } Public void...
-
This is a variable that keeps a running total. a. Sentinel b. Sum c. Total d. Accumulator
-
True or False: Comments that begin with // can be processed by javadoc.
-
Boston Furniture Company manufactures several steel products. It has three production departments: Fabricating, Assembly, and Finishing. The service departments include Maintenance, Material...
-
John Sheng, cost accountant at Starlet Company, is developing departmental manufacturing overhead application rates for the companys tooling and fabricating departments. The budgeted overhead for...
-
Calculate and Use Overhead Rate Bagley Corporation expects to incur \($450,000\) of factory over- head and \($600,000\) of general and administrative costs next year. Direct labor costs at \($20\)...
Study smarter with the SolutionInn App