
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
new java code can only be added between lines 22 - 24. as seen in image.
![1 import java.util.Scanner;
2 import java.util.InputMismatchException;
3
4 public class UserAge {
5 public static void main(String[] args) {
Scanner scnr = new Scanner (System.in);
int userAge;
boolean retry true;
LO
6
7
0096
8
10
11
PPPPBERR
12
Vas A WN
13
14
15
16
17
while (retry) {
try {
userAge = scnr.nextInt ();
if (userAge < 0) {
throw new Exception ("User's age must be nonnegative");
}](https://content.bartleby.com/qna-images/question/0cc153ae-b205-4fb2-9991-7cf6a21d5016/f04bf561-963c-4947-8bad-99ba72cd881c/iypju1p_thumbnail.png)
Transcribed Image Text:1 import java.util.Scanner;
2 import java.util.InputMismatchException;
3
4 public class UserAge {
5 public static void main(String[] args) {
Scanner scnr = new Scanner (System.in);
int userAge;
boolean retry true;
LO
6
7
0096
8
10
11
PPPPBERR
12
Vas A WN
13
14
15
16
17
while (retry) {
try {
userAge = scnr.nextInt ();
if (userAge < 0) {
throw new Exception ("User's age must be nonnegative");
}

Transcribed Image Text:The while loop makes multiple attempts to read a nonnegative integer from input into userAge. Use multiple exception handlers
to:
Catch an InputMismatchException, output "Unexpected input: The UserAge program quits", and assign retry with false.
• Catch an Exception and output the message of the Exception.
End each output with a newline.
Ex: If the input is 44, then the output is:
Valid input: User's age is 44
Ex: If the input is L, then the output is:
Unexpected input: The UserAge program quits
Ex: If the input is -65 44, then the output is:
User's age must be nonnegative
Valid input: User's age is 44
11
12
13
14
29999999
15
16
17
18
19
20
21
22
23
24
25
26 }
27 }
}
try {
userAge scnr.next Int();
if (userAge < 0) {
throw new Exception ("User's age must be nonnegative");
}
retry = false;
System.out.print("Valid input: ");
System.out.println("User's age is + userAge);
}
/* Your code goes here */
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Full comments and a java language implementation are needed. Write some code so that your name is shown in red font inside a blue frame, then save the file.arrow_forwardYou have to use comment function to describe what each line does import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class PreferenceData { private final List<Student> students; private final List<Project> projects; private int[][] preferences; private static enum ReadState { STUDENT_MODE, PROJECT_MODE, PREFERENCE_MODE, UNKNOWN; }; public PreferenceData() { super(); this.students = new ArrayList<Student>(); this.projects = new ArrayList<Project>(); } public void addStudent(Student s) { this.students.add(s); } public void addStudent(String s) { this.addStudent(Student.createStudent(s)); } public void addProject(Project p) { this.projects.add(p); } public void addProject(String p) { this.addProject(Project.createProject(p)); } public void createPreferenceMatrix() { this.preferences = new…arrow_forwardimplement a grid transformation that reduces the size of the grid, while retaining the information in it in python 3 __init__(self, size: int): create a square 2-D grid of ints with size rows and size columns. Initialize all values to 0. set_value(self, i: int, j: int, val: int): set the value in the i-th row and j-th column to val. squish(self, k:int): Sum up the elements of k by k blocks of the grid. This method does not return anything, but rather modifies the grid object. The size of the modified grid is n / k where n was the original size. You can assume that the grid's size is divisible by k.arrow_forward
- You can plot shapes in Python using line graphs in matplot lib by providing the coordinates of the vertices of the shapes as x, y pairs and using the matplotlib.pyplot.plot (i.e. plt.plot) function. Draw a triangle, square, pentagon, hexagon and heptagon. Note: Use symmetry, starting with the origin at (0,0), and set the distance from the origin to the vertex to be of length 1.0 (otherwise this becomes very complicated for some shapes).arrow_forwardUsing DrawingPanel.java (from chapter 3G), draw a grid for filling in a 4 x 4 square of cell containing integers. For this part of the assignment the values are not important, but you are welcome to use the values shown in the magic square from below. Note that the values in any horizontal row, vertical column or main diagonals add up to 34, in addition to various sub-squares in the larger square also add up to the same value. Requirements: The magic square should be centered in the panel The values in each of the cells should be centered in that cell (both horizontally and vertically). You can assume the values will be <= 99 (i.e., at most 2 digits). For this part of the assignment, you can hard-code the values; you will store them in a 2-dimensional array (from chapter 7) when implementing Part B of the assignment. The title "CSC 142 Magic Square" is centered horizontally in the panel and at y = 50 You are free to choose the colors, fonts, font sizes and effects. This is what I used…arrow_forwardWrite a program that draws a fixed polygonwith points at (30, 10), (60, 30), (50, 70), (35, 35), and (10, 50). Wheneverthe mouse is moved, display a message indicating whether the mousepoint is inside the polygon at the mouse point or outside of it, as shown inFigure. To detect whether a point is inside a polygon, use the containsmethod defined in the Node class.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education