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 8RQ
Program Description Answer
In object-oriented
Hence, the correct answer is option “B”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Fill-in-the-Blank
The __________ block handles an exception.
To send an exception, use the _______ keyword.
a. finally
b. exception
c. send
d. raise
Fill-in-the-Blank
The __________ block should enclose code that directly or indirectly might cause an exception to be thrown.
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
- 1. Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays an appropriate message.arrow_forwardQ1. Again --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..arrow_forwardThe 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.arrow_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_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_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_forwardChallenge 2: InvalidNumbers.java Write a program InvalidNumbers that asks the user to enter a positive integer. The program will warn the user if a valid integer is not entered using the InputMismatchException and ask to enter again. The program should also throw an exception if the user enters negative numbers. Write the program and test it using negative numbers, doubles, and very large numbers.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.arrow_forward
- 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. 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 (1): Write a program that asks the user to enter an integer greater than zero and store it in a variable called “n". Then it calculates the final value that will be stored in a variable called “s" according to the following equation. 1х 2 2 x 3 3 x 4 4 x 5 Nx (N+ 1) .. ( + or - ) 2 3 4 5 N+1 And add an exception when the user enters any value other than integer shows the message “You entered non integer value, please try again.", and let the user to enter a new value. Enter an integer: 4 Example 1 S = -2.0 Enter an integer: a You entered non integer value, please try again. Ехample 2 Enter an integer: 4 S = -2.0arrow_forwardThis is the question - 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. Code I was given, I will attach a screenshot of the errors- public class GradeException extends Exception { public GradeException(String string) { } } import java.util.*; public class TestGrade { public static void main(String args[]) throws…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