Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
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 TEST-CASE 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.
In this assignment you are required 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 length of ARRAY2 is n.
Array to be returned would be:
ARRAY[] = [6, 9, 11, 21]
ANSWER THE QUESTION BELOW.
Implement the function…
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.
Is the following argument valid or invalid? why?
There is a single cause for everything, therefore everything has a cause.
Chapter 9 Solutions
Java: An Introduction to Problem Solving and Programming (8th 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 - Prob. 36STQCh. 9.4 - Prob. 37STQCh. 9.4 - Prob. 38STQCh. 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 - Suppose that you are in change of customer service...Ch. 9 - Write an application that implements a trip-time...
Knowledge Booster
Similar questions
- 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_forwardQ3/ Answer with true or false for any three of the following, ( enhance your answer with interpretation). 1: The EraseMode method is better than the Movie method. 2: The ode45function represents the Euler's method. 3: The instruction Rand(n,0) gives random number between 0 and n. 4: In the Movie method there is no need for a pause.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_forward
- (YOU ARE NOT ALLOWED TO USE ARRAYLIST IN THIS PROJECT)Write a Java program to simulate a blackjack game of cards. The computer will play the role of the dealer. The program will randomly generate the cards dealt to the player and dealer during the game. Cards in this game will be represented by numbers 1 to 13 with Ace being represented by a 1. Remember, that face cards (i.e. Jack, Queen, and King) are worth 10 points to a hand while an Ace can be worth 1 or 11 points depending on the user’s choice. The numbered cards are worth their number value to the hand.arrow_forwardI am struggling with creating arrays program on eclipse. Struggling with getting the result as asked in assignment. Need help with problem a and b. Please help as soon as you can.arrow_forwardJava Note:- Do not provide handwritten solution. Maintain accuracy and quality in your answer. Take care of plagiarism.Answer completely.You will get up vote for sure.arrow_forward
- e Please read the whole document. Show the output screenshots with the code when done. You have to write it in Java Try and use methods and functions in the code.arrow_forwardHow could you make the execution more deterministic so that only one set of values is possible?arrow_forwardmodify Exercise 6.57 in a way that every time the user give the right answer , the response varies within the following : Possible responses to a correct answer: Very good!Excellent!Nice work!Keep up the good work! while if the user give the incorrect answer the response varies within the following : Possible responses to an incorrect answer: No. Please try again.Wrong. Try once more.Don't give up!No. Keep trying. Use random-number generation to choose a number from 1 to 4 that will be used to select one of the four appropriate responses to each correct or incorrect answer. Use a switch statement to issue the responses. here is the code that need to be modified : and make sure you add line comments for each new line of code EXERCISE 6.57 CODE: ----------------------------- //Name: IhabAtouf//Date:02/23/2023// exercise 6.57 on page 281//program description: create computer-assisted instruction (CAI) program that help students master thier math skills in multiplications,//…arrow_forward
- Complete the convert() method that casts the parameter from a double to an integer and returns the result.Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 code: public class LabProgram { public static int convert(double d){ /* Type your code here */ } public static void main(String[] args) { System.out.println(convert(19.9)); System.out.println(convert(3.1)); }}arrow_forwardCoding in C!!! Fun assignment if you know what you're doing. The screenshot explains. Code is pasted below. /*analyzeHand: Determines whether the hand contains a straight, a flush, four-of-a-kind, and/or a three-of-a-kind; determines thenumber of pairs; stores the results into the external variables straight, flush, four, three, and pairs. */ void analyzeHand( ... {int num_consec = 0;int rank, suit;straight = FALSE;flush = FALSE;four = FALSE;three = FALSE;pairs = 0;// check for flush – 5 cards of the same suitfor (suit = 0; suit < SUITS; suit++)if (suitsInHand[suit] == 5)flush = TRUE;// check for straight – eg. One each of 5,6,7,8,9// locate the first cardrank = 0;while (facesInHand[rank] == 0) rank++;// count the consecutive non-zero facesfor (; rank < FACES && facesInHand[rank]; rank++)num_consec++;if (num_consec == 5) {straight = TRUE;return;}/* check for 4-of-a-kind, 3-of-a-kind, and pairs */for (rank = 0; rank < NUM_RANKS; rank++) {if (facesInHand[rank] == 4)…arrow_forwardWrite this program in Java using a custom method. Implementation details You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists. Use an array of strings to store the 4 strings listed in the description. Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below: determine the fruits to display (step 3 below) and print them determine if there are 3 or 4 of the same image display the results update the customer balance as necessary prompt to play or quit continue loop if customer wants to play and there's money for another game. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an…arrow_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