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...
-
In how many ways can a committee consisting of 6 men and 6 women be selected from a group consisting of 20 men and 22 women?
-
Paper Company acquired 80 percent of Scissor Company's outstanding common stock for $296,000 on January 1, 20X8, when the book value of Scissor's net assets was equal to $370,000. Paper uses the...
-
What is a transfer function?
-
1. How comparable are the two different methods? In what ways are they similar? In what ways are they different? 2. What are the positive and negative aspects of each approach that Shocker should...
-
If you join our team, how will you do with the opportunity to work from home, balancing your own values, priorities and time? How do you personally manage the flow of information and due dates in a...
-
The information listed below refers to the employees of Lemonica Company for the year ended December 31, 2016. The wages are separated into the quarters in which they were paid to the individual...
-
Daniel Schlicksup, an accountant, worked for Caterpillar for 16 years. He previously worked for Arthur Andersen, moved to Peoria to work on the Caterpillar account for PWC, until he began working on...
-
You need to create a uniform electric field in a small region of space, and all you have to work with is one large styrofoam ball that carries a uniform volume charge distribution \(ho\). You cut the...
-
(LO2) In which of the following situations is income taxable to Belinda in Year 1? Belinda owns an architectural firm and reports on the cash basis. I. Belinda received \(\( \$ \) 6,000\) from a...
-
A point \(\mathrm{P}\) is located at \(x_{\mathrm{p}}=2.0 \mathrm{~m}, y_{\mathrm{P}}=3.0 \mathrm{~m}\). What are the magnitude and direction of the electric field at \(\mathrm{P}\) due to a particle...
-
Charged particles 1,2 , and \(3\left(q_{1}=10.0 \mu \mathrm{C}, q_{2}=-5.00 \mu \mathrm{C} ight.\), and \(\left.q_{3}=-3.00 \mu \mathrm{C} ight)\) are arranged in an equilateral triangle in an \(x...
-
You are evaluating a new product. In year 3 of your analysis, you are projecting pro forma sales of \($5\) million and cost of goods sold of \($3\) million. You will be depreciating a \($1\) million...
-
Evaluate the integral 43 cos xdx, using C as the constant of integration.
-
The domain of the variable in the expression x 3/x + 4 is________.
-
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.
-
Consider a gas metal arc welding electrode as shown in Figure P10.29 where we are consuming the electrode as we weld ( rod velocity \(\left.=v_{o} ight)\). We are interested in the steady-state...
-
Consider the heat transfer to a falling film problem of Section 10.3. The mass transfer analog is the dissolution of a solid wall into the falling film. Assuming the solid wall is composed of salt,...
-
In Smoluchowski's Theory of Coagulation we focus on an individual sphere and assume that other like particles diffuse toward it. Once they reach the sphere, they collide and form a new spherical...
Study smarter with the SolutionInn App