Microsoft Visual C#
7th Edition
ISBN: 9781337102100
Author: Joyce, Farrell.
Publisher: Cengage Learning,
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
error_outline
This textbook solution is under construction.
Students have asked these similar questions
Modify the GreenvilleRevenue program created in Chapter 10, Case Study 1 so that it performs the following tasks:
The program prompts the user for the number of contestants in this year’s competition; the number must be between 0 and 30. Use exception-handling techniques to ensure a valid value and display the error message:Number must be between 0 and 30
The program prompts the user for talent codes. Use exception-handling techniques to ensure a valid code and update the displayed message to the following message:x is not a valid talent code. Assigned as Invalid.where x was the invalid code entered into the console.
After data entry is complete, the program prompts the user for codes so the user can view lists of appropriate contestants. Use exception-handling techniques for the code verification and display the following message:
Enter a talent type or Z to quit >> x x is not a valid code
and for valid codes:
Enter a talent type or Z to quit >> S Contestants with talent…
Modify the GreenvilleRevenue program created in Chapter 10, Case Study 1 so that it performs the following tasks:
The program prompts the user for the number of contestants in this year’s competition; the number must be between 0 and 30. Use exception-handling techniques to ensure a valid value and display the error message:Number must be between 0 and 30
The program prompts the user for talent codes. Use exception-handling techniques to ensure a valid code and update the displayed message to the following message:x is not a valid talent code. Assigned as Invalid.where x was the invalid code entered into the console.
After data entry is complete, the program prompts the user for codes so the user can view lists of appropriate contestants. Use exception-handling techniques for the code verification and display the following message:
Enter a talent type or Z to quit >> x x is not a valid code
and for valid codes:
Enter a talent type or Z to quit >> S Contestants with talent…
This lab will exercise your understanding of some of the concepts covered in Chapter 14:
exception handling
1. Create a program that uses EXCEPTION HANDLING to deal with an invalid input entry by a user.
a. Write a program that prompts a user to enter a length in feet and inches. The length valuesmust be positive integers.
b. Calculate and output the equivalent measurement in centimeters1. inch = 2.54 centimeters
c. Write the code to handle the following exceptions:
If the user enters a negative number, throw and catch an error that gives the user the appropriate message and request a valid number. Do this until the user enters a valid number
If the user enters a character, throw and catch an error that indicates the input stream is invalid. Write code that resets the input stream and request a valid number. Do this until the user enters a valid number
d. Output the feet-inch input values to centimeter conversion value
The program may be named any name of our choice, must have a .cpp…
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
- Write a JAVA PROGRAM to create a user defined exception class. In this, a constructor of InvalidGradeException accepts a string as an argument. This string is passed to constructor of parent class Exception using the super () method. Also the constructor of Exception class can be called without using a parameter and calling super () method is not mandatory. WRITE JAVA PROGRAM only, and give screenshot of sample runarrow_forwardJAVA Given a main program that searches for the ID or the name of a student from a text file, complete the findID() and the findName() methods that return the corresponding information of a student. Then, insert a try/catch statement in main() to catch any exceptions thrown by findID() or findName(), and output the exception message. Each line in the text file contains the name and the ID of a student, separated by a space. Method findID() takes two parameters, a student's name and a Scanner object containing the text file's contents. Method findID() returns the ID associated with the student's name if the name is in the file, otherwise the method throws an Exception object with the message "Student ID not found for studentName", where studentName is the name of the student. Method findName() takes two parameters, a student's ID and a Scanner object containing the text file's contents. Method findName() returns the name associated with the student's ID if the ID is in the file,…arrow_forwardWrite a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. (in Python)arrow_forward
- Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of…arrow_forwardProgramme Leader of ITMB wants to check whether the student number and GSM number entered by the student for the programming contest is valid or not. Write a Java program to read the Student ID and GSM Number of a student. Use a method called ValidityDetails () for checking the validity of details entered. If the Student ID doesn’t start with the characters ST and contains more than 6 letters or if the Mobile Number does not contain exactly 8 digits, throw a user defined exception InvalidDetailsException. If the details entered are valid, display the message ‘”correct details are entered!!!” otherwise display “Entered invalid details!!!!”arrow_forwardC++ You did this way back in Unit 1! But now all of your RomanNumber code is wrapped up in a class, so the "main" program is short and sweet. As before, write a program that accepts entries from the user. If it's an integer, convert to Roman Number and display. If it's a Roman Number, convert to integer and display. If it's neither, thrown an exception and continue to process The action to take here will be to display an error message If the entry is 0 or O (The digit 0 (zero) or the letter O) exit and state how many conversions were done of each type (integer to Roman and Roman to integer) and how many exceptions were thrown. As I said, the main program will be short and sweet. Provide your .cpp code and a screen shot of your program in action. Enter twelve conversions - four integer to Roman, four Roman to integer, and two of each in which the input is invalid so that I can see the exceptions. The thirteenth and final entry will be 0 or O.arrow_forward
- What is exception propagation? Give an example of a class that contains at least two methods, in which one method calls another. Ensure that the subordinate method will call a predefined Java method that can throw a checked exception. The subordinate method should not catch the exception. Explain how exception propagation will occur in your example.arrow_forwardQ3(a). Explain the purpose of exception handling by taking one of the following scenarios. b. Write a piece of Java code that illustrates how you handle the scenario selected in Q3(a)” Scenario 1. Users enter values that are not included in a predefined list.Scenario 2. A potentially corrupt file could be uploaded to your program.Scenario 3. A database query returns some null value.Scenario 4. A remote method invocation returns null valuearrow_forwardWrite a program that converts a time from 24-hour notation to 12-hour notation. To make the solution easier, a requirement is imposed on the input: It must be in xx:xx format, i.e. it must have two digits, a colon, and then another two digits. Define an exception class called TimeException. If the user enters an illegal time, like 10:65, or even gibberish, like 8&*68, your program should throw and handle a TimeException. Test your program with the file "times.txt" as input and store the result in the file "result.txt" File times.txt: 00:00 12:00 12:01 11:59 23:59 24:00 10:65 3:23 1145 8&*68 File result.txt: # 24-hour 12-hour -------------------------------------------- 1 00:00 12:00 AM 2 12:00 12:00 PM 3 12:01 12:01 PM 4 11:59 11:59 AM 5 23:59 11:59 PM 6 24:00 Time Exception 7 10:65…arrow_forward
- باستخدام جافا Write a program that allows the user to compute the subtracted value afterthe subtraction of two integer values. The subtraction value of x - y isstored in z. Catch any exception thrown and allow the user to enter newvalues.arrow_forwardWe have created a hierarchy of exceptions like below: A) The code written below throws an exception from the above hierarchy, depending on the value of c. Fill in the 5 gaps below, so that a correct working program is created. B) the following code throws two exceptions: Exception and ExceptionD. The exception name in the catch statement was removed as I expect you to recognize the order by which the exceptions are written in this code. B-1) what will be printed if the method is called by x = 0. B-2) what will be printed if the method is called by x = -1. B-3) what will be printed if the method is called by x = 1. C) A class called Exam is defined as below. Another class called TT2 extends class Exam and overrides all the three methods of Exam class. Specify what type of exceptions can be thrown by the methods that are defined in class TT2.arrow_forwardIn a few well-written paragraphs, discuss the use of exceptions and exception handling in programming. Your discussion should include definitions for exception, exception handler, throw signal, and catch process. Discuss why exceptions are helpful for handling runtime errors, such as division by zero.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning