
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
Question
Write an input verification loop that ensures that the user enters a positive integer as input. You may assume that a Scanner object called scan has already been created. use Java.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 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
- The following code is in Java: // Assume inputFile references a Scanner object. try { input = inputFile.nextInt(); } finally { inputFile.close(); } catch (InputMismatchException e) { System.out.println(e.getMessage()); } 1)What is the issue with this code?2) How can it be fixed?arrow_forwardComplete the following program to implement the user interface of the preceding exercise. For simplicity, only the units cm, m, and in are supported. Hint: The value of factor1 or factor2 should be the conversion factor from the selected unit to cm. Ex: If the selected unit is in, factor1 is 2.54 because 1 in = 2.54 cm."in java"arrow_forwardHi I am having some difficulties with this problem, I am not sure why my code is giving an incorrect output. Here is the provided code: import java.util.Scanner; public class DrawHalfArrow { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int arrowBaseHeight; int arrowBaseWidth; int arrowHeadWidth; System.out.println("Enter arrow base height:"); arrowBaseHeight = scnr.nextInt(); System.out.println("Enter arrow base width:"); arrowBaseWidth = scnr.nextInt(); System.out.println("Enter arrow head width:"); arrowHeadWidth = scnr.nextInt(); System.out.println(""); // Draw arrow base (height = 3, width = 2) System.out.println("**"); System.out.println("**"); System.out.println("**"); // Draw arrow head (width = 4) System.out.println("****"); System.out.println("***"); System.out.println("**"); System.out.println("*"); }}…arrow_forward
- This is a debugging question - The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. You also will use a file named DebugEmployeeIDException.java with the DebugTwelve4.java file. Code I was given- public class DebugEmployeeIDException extends Exception { public DebugEmployeeIDException() { super(s); } } // An employee ID can't be more than 999 // Keep executing until user enters four valid employee IDs // This program throws a FixDebugEmployeeIDException import java.util.*; public class DebugTwelve4 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String inStr, outString = ""; final int MAX = 999; int[] emps = new int[4]; for(x = 0; x < emps.length; ++x) { System.out.println("Enter employee ID number"); inStr =…arrow_forwardIn a statement: Scanner keyboard = new Scanner (System.in); !! it reads user input by means of a Scanner, the user types the line of input below, exactly as shown, including that same spacing. What is the statement keyboard.nextDouble(); returned ? Answer "2": 1+2 is 3 and "5.0" squared is 25.0 ! O a. 25.0 Ob. "5.0" OC. 2 O d.5.0arrow_forwardAssume you are considering writing a method and are deciding what should happen when given input that is outside of perfect input. Which of the following is not a way to handle this? Group of answer choices 1. Use better JUnit testing 2. Throw an exception 3. Try to reasonably auto-correct 4. Prevent the errorarrow_forward
- The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. You also will use a file named DebugEmployeeIDException.java with the DebugTwelve4.java file. // An employee ID can't be more than 999 // Keep executing until user enters four valid employee IDs // This program throws a FixDebugEmployeeIDException import java.util.*; public class DebugTwelve4 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String inStr, outString = ""; final int MAX = 999; int[] emps = new int[4]; for(int x = 0; x < emps.length; ++x) { System.out.println("Enter employee ID number"); inStr = input.next(); try { emps[x] = Integer.parseInt(inStr); if(emps[x] > MAX) { throw(new…arrow_forwardIn the following code stream, identify if there are any hazards. Crisply describe if it is possible to get around the hazards, and what the resulting steps will be. lw r2, 0(r1) add r3, r2, r3 sub r1, r1, r4arrow_forwardGrey lines (start-8 & 12-end of code) can NOT be edited. New JAVA will have to go inbetween as shown in photo.arrow_forward
- Write code that outputs variable numDogs as follows. End with a newline. Ex: If the input is: 3 the output is: Dogs: 3 I tried to get the output of 6 by its wrong everytime.arrow_forwardWrite a class, NumberToMonth, which does the following: a. Ask the user to enter the month of the year (number1 through 12): "Enter the month of the year - number 1 to 12" b. Get the month using a Scanner c. checks for invalid input (i.e. numbers that are not 1- 12) and terminates the program using System.exit(1)if input is invalid d. Prints the name of the month: "The month is XXXXX" Tips | Use a multi-way if-else statement Submission I Copy and paste your code | Screen shot the console with user input of three example months (one invalid input, two any month) Sample Run Enter the month of the year (number 1 to 12) 77 Invalid Input Enter the month of the year (number 1 to 12) 6 The month is June Enter the month of the year (number 1 to 12) 12 The month is Decemberarrow_forwardHello! I am trying to debug this assigment. I already find some bugs and fixed them, however; I am stuck and struggling with the rest. I would appreciate a hint and explanation to continue. Thank you. import java.util.*; // for scanner public class Calc { public static void main(String[] args) { boolean done = false; Scanner console = new Scanner (System.in); while (!done){ displayMenu(); selection = getUserSelection(console); done = processSelection(selection, console); } System.out.println("Thank you for using this program. Goodbye."); } private static boolean processSelection(String selection, Scanner console) { boolean done = false; if (!selection.equalsIgnoreCase("E")){ if (selection.equalsIgnoreCase("U")){ calculateResults(console); } else if (selection.equalsIgnoreCase("H")){ //No need to write a Help Menu at this time, but logic and program execution // should still operate normally and display original menu after message prints System.out.print("Help Menu is under…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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