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 20RQ
Program Description Answer
A statement that is used in testing programs, which should be true, otherwise throws an Exception is known as assertion.
Hence, the correct answer is option “C”.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
A(n) ____ should be used to specify all the exception types when being handled by a single
exception handler.
list
O tuple
array
O dict
c++ programming
Lab 10-1:
Write a test program to accept two numbers from consol. Then check to see if first number is larger than second number . If it is throwing an exception and handle the error properly.
Lab 10-2:
Write a test program to accept a number from consol. then check to see if the number is positive or negative. If it is negative throw an exception and indicate the number is negative otherwise take the squire root of the number. Use exception handling to control the flow of the code.
Lab 10-3:
Write a test program to accept a number from consol. This number is radius of circle if the number is positive find area and circumference. Otherwise, throw an exception with proper message.
Lab 10-4:
Show the output of the following code with input 10, 60, and 120, respectively.
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_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.
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
- 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_forwardThe code with the discussion of itarrow_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_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_forward
- C++ programming D.S.Malik 14-5 Write a program that prompts the user to enter a person’s date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Follow similar conventions for the invalid values of month and year. (Note that your program must handle a leap year.)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_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_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_forward
- Question (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 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.Example 1Enter an integer: 4S = -2.0Example 2Enter an integer: aYou entered non integer value, please try again.Enter an integer: 4S = -2.0arrow_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_forwardWe use Exception Handling for ? Code Management Debugging Error Handling None of the abovearrow_forward
- Develop an exception class named InvalidMonthException that extends the Exception class. Instances of the class will be thrown based on the following conditions: The value for a month number is not between 1 and 12 The value for a month name is not January, February, March, … December Develop a class named Month. The class should define an integer field named monthNumber that holds the number of a month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods: A no-argument constructor that sets the monthNumberto 1. An overloaded constructor that accepts the number of the month as an argument. The constructor should set the monthNumberfield to the parameter value if the parameter contains the value 1 – 12. Otherwise, throw an InvalidMonthException exception back to the caller. The exception should note that the month number was incorrect. An overloaded constructor that accepts a string containing the name of the month,…arrow_forwardProblem Statement:The purpose of this lab assignment is to gain experience in python’s Exception handling. In thisassignment, you will write a program for .edu email address validation system. Problem Design: The program will take an email address from user and check if it contains thefollowing:a. Address must contain at least an ‘@’ symbolb. Address must contain at least a ‘.edu’ suffixc. Length must contain at least 12 characters.d. Address must contain at least one digit 2. Helper functions to check if an address has at least one digit is provided. Docstring arealso given in the template file. This function returns True if condition satisfies otherwisereturns False. 3. Your task: Design a base class (Invalid Address) and child exception classes(InsufficientLength, NoDigit, NoEdu, NoAtSymbol ) to raise the exception when theconditions are not met. 4. Design a simple user menu to ask for the address as long as the user does not enter a validaddress. 5. The menu should also make a…arrow_forwardYou can catch any exception by writing one except clause.True or Falsearrow_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