Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 9.1, Problem 7STQ
Explanation of Solution
“throw” statement:
- • The keyword “throw” is used to throw an exception from the
program . It is possible to throw either checked or unchecked exception. - • When an exception is thrown using “throw” keyword, the “try” block ends and the statements inside that block will not get executed. The control directly goes to the subsequent “catch” block whose parameter matches the exception object.
Example program:
//Main Class
class Main
{
//Main method
public static void main(String[] args)
{
/*A variable is declared and a value is assigned*/
int value = 9;
//Try block
try
{
//Check if value is greater than 30
if(value < 10)
//Throw an exception
throw new Exception("Value is lesser");
//Print the message
System...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
READY CAREFULLY
Java add comment to code, please write your test-cases on how you would
test your solution assumptions and hence your code.
Example of cases to be tested for are like : What if the array input which
is expected does not exist - that is , input is a null. How should your code
handle such a situation ? Maybe output some message like ”Null input
case, so no output”? What if the length of the array is one ?....so on and
so forth.
Please Remember : Although, written as comments - You will address
your test cases in the form of code and not prose
In this assignment you are required to do a programs which takes as input two sorted arrays and returns a new array containing the elements found in both the sorted arrays. It is alright if the input arrays have duplicates, but the returned array should be duplicate free!
Below is how the arrays are represented
ARRAY1[] = [1, 5, 6, 6, 9, 9, 9, 11, 11, 21]
Here length of ARRAY1 is m.
ARRAY2[] = [6, 6, 9, 11, 21, 21, 21]
Here…
Look at the image for the expected output. Use if class, scanner class, return class to do this program.
Look image for the valid user input.
Could you please explain the Write Through method?
Chapter 9 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 9.1 - Prob. 1STQCh. 9.1 - What output would the code in the previous...Ch. 9.1 - Prob. 3STQCh. 9.1 - Prob. 4STQCh. 9.1 - Prob. 5STQCh. 9.1 - Prob. 6STQCh. 9.1 - Prob. 7STQCh. 9.1 - Prob. 8STQCh. 9.1 - In the code given in Self-Test Question 1,...Ch. 9.1 - In the code given in Self-Test Question 1,...
Ch. 9.1 - Prob. 11STQCh. 9.1 - Prob. 12STQCh. 9.1 - Prob. 13STQCh. 9.1 - Prob. 14STQCh. 9.2 - Prob. 15STQCh. 9.2 - Prob. 16STQCh. 9.2 - Prob. 17STQCh. 9.2 - Prob. 18STQCh. 9.2 - Prob. 19STQCh. 9.2 - Prob. 20STQCh. 9.2 - Suppose that, in Self-Test Question 19, we change...Ch. 9.2 - Prob. 22STQCh. 9.2 - Prob. 23STQCh. 9.3 - Prob. 24STQCh. 9.3 - Prob. 25STQCh. 9.3 - Prob. 26STQCh. 9.3 - Prob. 27STQCh. 9.3 - Prob. 28STQCh. 9.3 - Repeat Self-Test Question 27, but change the value...Ch. 9.3 - Prob. 30STQCh. 9.3 - Prob. 31STQCh. 9.3 - Prob. 32STQCh. 9.3 - Consider the following program: a. What output...Ch. 9.3 - Write an accessor method called getPrecision that...Ch. 9.3 - Prob. 35STQCh. 9.4 - Rewrite the class ColorDemo in Listing 9.13 so...Ch. 9.4 - Prob. 37STQCh. 9 - Write a program that allows students to schedule...Ch. 9 - Prob. 2ECh. 9 - Prob. 3ECh. 9 - Prob. 4ECh. 9 - Prob. 5ECh. 9 - Write code that reads a string from the keyboard...Ch. 9 - Create a class Rational that represents a rational...Ch. 9 - Prob. 9ECh. 9 - Suppose that you are going to create an object...Ch. 9 - Revise the class RoomCounter described in the...Ch. 9 - Prob. 12ECh. 9 - Write a class LapTimer that can be used to time...Ch. 9 - Prob. 1PCh. 9 - Prob. 2PCh. 9 - Prob. 3PCh. 9 - Write a program that uses the class calculator in...Ch. 9 - Prob. 3PPCh. 9 - Prob. 7PPCh. 9 - Prob. 9PPCh. 9 - Suppose that you are in change of customer service...Ch. 9 - Write an application that implements a trip-time...
Knowledge Booster
Similar questions
- Give me answer fast please.arrow_forwardplease solve this important, thanks.arrow_forwardJava Foundations : Please provide code and explain. Thank you. Write the code segments in main( ) and in methodA( ) for the following scenario: main( ) passes methodA an int variable called a. methodA generates an exception, but does not deal with it, if a is not between 1 and 100.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_forwardWrite the code in java and please don't plagiarize or copy from other sources write it on your own. Read carefully and follow the instructions in the question. Thank you.arrow_forwardI am having trouble with this: Implement the convertString method based on its specification. Here are some things that can help: the Character class has some utility methods to determine if a character is uppercase, lowercase, or a digit (numeral) the String class has a method to get the character at a specific position (called the index). Find that method and use it. make use of the convert methods you already have!convertString Specification: /** * Converts the letters and numerals in the given string * to their circled counterparts. All other characters * are unchanged. * * @precondition text != null * @postcondition none * * @param text the text to convert * @return a modified version of text, with all letters and numerals * circled. */My code: public class CircleStrings { /** * Converts the letters and numerals in the given string * to their circled counterparts. All other characters * are unchanged. * *…arrow_forward
- USE PYTHON PROGRAMMING. The expected outputs seen in the screenshot must be achieved. (Not working = Thumbs Down) You must use the code template below. You cannot modify the class or its methods. You are only allowed to add lines of code to the main part of the program. Thank you. import ast class WeightedQuickUnion: def __init__(self, size: int) -> None: """ Initializes the union-find ds size: number of elements to initialize """ self.size = size self.parent = [-1]*self.size # create a list where all elements are roots self.group_size = [1]*self.size # create separate list to indicate the size for each element # (useful for knowing the size in root's perspective) def __str__(self) -> str: return f"parent: {self.parent}\nsize: {self.group_size}\n" def get_root(self, p: int) -> int: """Find the root of p""" idx = p while self.parent[idx] >= 0:…arrow_forwardplease include comments for better understandingarrow_forwardThis is for java. I need help asap. Thanks!arrow_forward
- I have the code for this one but I do seem to be missing something. This is the question - Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed. This is the code I have. I have got one check right but I can't get the other two - import java.util.*; public class CountByAnything { // Modify the code below public static void main (String args[]) { Scanner input = new Scanner(System.in); final int START; System.out.print("Please enter the value: "); START = input.nextInt(); final int STOP = 500; final int NUMBER_PER_LINE = 10; for(int i = START; i <= STOP; i += START) { System.out.print(i + " "); if(i % NUMBER_PER_LINE == 0) System.out.println(); } } }arrow_forwardPlease Use JAVA and DO NOT use Array or ArrayList. In English vocabulary there are many interesting and meaningful phenomena, such as isogram, pangram, malapropisms, anagram, palindrome, etc., which leave a “room” for language-learners to enthusiastically discover secret, surprise, and something different instead of negatively listing words. They make the boring vocabulary lesson an interactive practical course that helps to grasp interest of students as English language-learners.1Some of these interesting linguistic phenomena2are: Isogram: referred to a word, phrase, or sentence in which no letter of the alphabet occurs more than once. For example; the words “ambidextrously”, “endolymphatic”, and “unpredictably”. Pangram: A phrase or sentence containing all 26 letters of the alphabet (ideally repeating as few letters as possible). For example; the sentence: “Brown jars prevented the mixture from freezing too quickly”. Palindrome: a word, number, phrase, or other sequence of…arrow_forwardThank you! base on these methods, I want to write one more method Spec for method 5: A method to print a text-based histogram takes one parameter, an array of integers no return value image 2 is the example of expected output. Hint: basically it means base on the file, if number 20 appears once in the file, then I will print one star(*) after the number 20. I think we can get these information from method 4arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning