Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 12, Problem 6RQ
Program Description Answer
A Throws Exception is referred to as a method, which detects an error condition or Exception.
Hence, the correct answer is option “A”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Needed code
The return Or the throw function sometimes returns a random number and throws anither number as an exception. Write a code that will print out the number that the returnorthrow function gives back even if it throws an exception.
write a code in java
Chapter 12 Solutions
Java Programming (MindTap Course List)
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 an application that displays a series of at least eight student ID numbers (that you have stored in an array) and asks the user to enter a test letter grade for the student. Create an Exception class named GradeException that contains a static public array of valid grade letters (A, B, C, D, F, and I) that you can use to determine whether a grade entered from the application is valid. In your application, throw a GradeException if the user does not enter a valid letter grade. Catch the GradeException, and then display the message Invalid grade. In addition, store an I (for Incomplete) for any student for whom an exception is caught. At the end of the application, display all the student IDs and grades.arrow_forwardWrite an application that displays a series of at least eight student ID numbers (that you have stored in an array) and asks the user to enter a test letter grade for the student. Create an Exception class named GradeException that contains a static public array of valid grade letters (A, B, C, D, F, and I) that you can use to determine whether a grade entered from the application is valid. In your application, throw a GradeException if the user does not enter a valid letter grade. Catch the GradeException, and then display the message Invalid grade. In addition, store an I (for Incomplete) for any student for whom an exception is caught. At the end of the application, display all the student IDs and grades. import java.util.*; public class TestGrade { public static void main(String args[]) throws Exception { Scanner input = new Scanner(System.in); int[] ids = {1234, 1245, 1267, 1278, 2345, 1256, 3456, 3478, 4567, 5678 };…arrow_forwardQuestion 01 - Exceptions Write a Java program that reads a list of integers from the user, and then calculates the average of the positive integers in the list. If there are no positive integers in the list, the program should throw a custom exception called "NoPositiveIntegersException". The program should be implemented as follows: I. II. III. IV. V. Create a custom exception class called "NoPositiveIntegersException" that printout the error message "There are no positive integers in the list" if there are no positive integers in the user entered list. Create another class called "AveragePositiveIntegers" to get the user inputs through the main method. The program should prompt the user to enter a list of integers, one integer per line. The user should indicate the end of the list by entering a negative integer (Ex: -2) Store the user entered positive integers in an ArrayList. Calculate the average of the positive integers and print it to the console, rounded to two decimal places.…arrow_forward
- python Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burning_heart_rate() to calculate the fat burning heart rate. The adult's age must be between the ages of 18 and 75 inclusive. If the age entered is not in this range, raise a ValueError exception in get_age() with the message "Invalid age." Handle the exception in __main__ and print the ValueError message along with "Could not calculate heart rate info." Ex: If the input is: 35 the output is: Fat burning heart rate for a 35 year-old: 129.5 bpm If the input is: 17 the output is: Invalid age. Could not calculate heart rate info. # here is the script I have but its not working def get_age():age = int(input())age=int(input("Enter the age:"))if age<18 or age>75:raise ValueError('Invalid age.')return age # TODO: Complete fat_burning_heart_rate() functiondef fat_burning_heart_rate(age):heart_rate=(220-age)*.70return heart_rate if __name__ == "__main__":#…arrow_forwardWrite an application that displays a series of at least 10 student ID numbers (that you have stored in an array) and asks the user to enter a test letter grade for the student. Create an Exception class named Grade Exception that contains a static public array of valid grade letters ('A', 'B', 'C', 'D', 'F', and 'T') you can use to determine whether a grade entered from the application is valid. In your application, throw a Grade Exception if the user does not enter a valid letter grade. Catch the Grade Exception, and then display an appropriate message. In addition, store an l' (for Incomplete) for any student for whom an exception is caught. At the end of the application, display all the student IDs and grades. Save the files as Grade Exception.java and TestGrade.java. Show transcribed image text Write an application that displays a series of at least 10 student ID numbers (that you have stored in an array) and asks the user to enter a test letter grade for the student. Create an…arrow_forwardWrite codesarrow_forward
- What is a throw point? 2. What is an exception handler? 3. Explain the difference between a try block and a catch block. 4. What happens if an exception is thrown, but not caught? 5. Complete the following function that searches a numeric array for a specified value. The function should return the subscript of the element containing the value if it is found in the array. If the value is not found, the function should throw an exception. int searchArray(int array[], int size, int value){ int index = 0; // Used as an index to search array int subscript = -1; // To record position of search value while (index < size && subscript == -1) { if (array[index] == value) // If the value is found ___________________________________________________ ___________________________________________________ } if (subscript == -1) ___________________________________________________ return subscript; } Bonus…arrow_forwardWrite a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burning_heartrate() to calculate the fat burning heart rate. The adult's age must be between the ages of 18 and 75 inclusive. If the age entered is not in this range, raise a ValueError exception in get age() with the message "Invalid age." Handle the exception in_main_and print the ValueError message along with "Could not calculate heart rate info." Ex: If the input is: 35 the output is: Fat burning heart rate for a 35 year-old: 129.5 bpm If the input is: 17 the output is: Invalid age. Could not calculate heart rate info.arrow_forwardAnswer and the outputarrow_forward
- Write a Month class that holds information about the month. Write exception classes for the following error conditions:• A number less than 1 or greater than 12 is given for the month number.• An invalid string is given for the name of the month.Modify the Month class so that it throws the appropriate exception when either of these errors occurs. Demonstrate the classes in a program.arrow_forwardPlease do this in Java! 3. RetailItem Exceptions Programming Challenge 4 of Chapter 6 required you to write a RetailItem class that holds data pertaining to a retail item. Write an exception class that can be instantiated and thrown when a negative number is given for the price. Write another exception class that can be instantiated and thrown when a negative number is given for the units on hand. Demonstrate the exception classes in a program. /** *Description: This program will displays a string without any user interaction *Class: Fall - COSC 1437.81002 *Assignment1: Hello World *Date: 08/15/2011 *@author Zoltan Szabo *@version 0.0.0 */ For each method, you will also be required to create docstring as follows: /** * @param String as args * @return Termination code as int, 0 for normal, anything else is error condition * @throws Nothing is implemented */ Flowcharts/UML and Pseudo code All assignment questions must show design flowchart/UML and/or pseudo code unless otherwise…arrow_forwardFill-in-the-Blank The __________ block should enclose code that directly or indirectly might cause an exception to be thrown.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft 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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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