Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 16.1, Problem 5STE
In the code given in Self-Test Exercise 1, what is the try block?
1. What output is produced by the following code?
int waitTime = 46; try { cout << "Try block entered.\n"; if (waitTime > 30) throw waitTime; cout << "Leaving try block.\n"; } catch(int thrownValue) { cout << "Exception thrown with\n" << "waitTime equal to " << thrownValue << endl; } cout << "After catch block." << endl; |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java Language
How can I create a test in JUnit for this setter?
public void setAge(int age) throws IllegalArgumentException{
if ( age < 0 || age > 80 ) throw new IllegalArgumentException("Invalid age entered");
this.age = age;
}
Consider the following code:
public static void test_b(int n)
{
if (n>0)
test_b(n-2);
System.out.println(n + " ");
}
What is printed by the call test_b(6)?
this practice assignment wants me to : Write an application that asks a user to enter an integer. Display a statement that indicates whether the integer is even or odd.
it is saying that i am missing a return statement.
here is my code:
mport java.util.Scanner;
class EvenOdd {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
System.out.println("Enter the integer >>>");
number = input.nextInt();
}
public static boolean isEven(int number) {
if (number % 2 == 0)
System.out.println("The number is even.");
else
System.out.println("The number is odd.");
}
}
Chapter 16 Solutions
Problem Solving with C++ (9th Edition)
Ch. 16.1 - Prob. 1STECh. 16.1 - What would be the output produced by the code in...Ch. 16.1 - Prob. 3STECh. 16.1 - What happens when a throw statement is executed?...Ch. 16.1 - In the code given in Self-Test Exercise 1, what is...Ch. 16.1 - Prob. 6STECh. 16.1 - Prob. 7STECh. 16.1 - What is the output produced by the following...Ch. 16.1 - What is the output produced by the program in...Ch. 16.2 - Prob. 10STE
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
- 2- Trace the following code and write the output: class Test1 { Test1(int x) { System.out.println("Test Calls " + x); class Test2 { Testi t1 = new Test1(10); Test2(int i) { t1 = new Test1(i); } public static void main(String[] args) { Test2 t2 = new Test2(5);arrow_forwardJAVA Program ASAP Please modify this program with further modifications which are below so it passes the test cases in Hypergrade. I have provided the failed test cases. 1) For test cases 2 and 3 for the outputted numbers there needs to be commas and there needs to be nothing after that 2)for test case 1 outputted numbers there needs to be nothing after that, 3) for test 4 when file is not found there needs to be nothing after that 4) and for test case 5 and 7 afer a file is not found it needs to display Please re-enter the file name or type QUIT to exit: so you input the text file and displays the numbers. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.InputMismatchException;import java.util.Scanner;public class FileSorting { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please…arrow_forwardComplete the code below according to the instructions below and the example test: method withdraw throws an exception if amount is greater than balance. For example: Test Result Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(5500.0); System.out.println("Balance: "+account.getBalance()); Insufficient: Insufficient funds. Balance: 5000.0 Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(500.0); System.out.println("Balance: "+account.getBalance()); Balance: 4500.0 Incomplete java code: public class Account{ private String accntNumber; private String accntName; private double balance; public Account(){} public Account(String num, String name, double bal){ accntNumber = num; accntName = name; balance = bal; } public double getBalance(){ return balance;}}//your class herearrow_forward
- Use the following code to answer the question public class SpeedTrap {private int speedLimit;/*** Creates a new SpeedTrap with the given* speed limit* * @precondition speedLimit >= 1* @postcondition getSpeedLimit()==speedLimit*/public SpeedTrap(int speedLimit) {if (speedLimit < 1) {throw new IllegalArgumentException("invalid speed limit");}this.speedLimit = speedLimit;}/*** Gets the speed limit* @return the speed limit*/public int getSpeedLimit() {return this.speedLimit;}/*** Checks to see if the given miles-per-hour* is considered speeding.** @precondition mph >= 0* @postcondition none** @returns true if speeding; false otherwise*/public boolean isSpeeding(int mph) {if (mph < 0) {throw new IllegalArgumentException("invalid mph");}return (mph > this.speedLimit);}}Write a JUnit test named testWhenSpeeding that uses a value for mph that is valid and is considered speeding.arrow_forwardUse the following code to answer the question public class SpeedTrap {private int speedLimit;/*** Creates a new SpeedTrap with the given* speed limit* * @precondition speedLimit >= 1* @postcondition getSpeedLimit()==speedLimit*/public SpeedTrap(int speedLimit) {if (speedLimit < 1) {throw new IllegalArgumentException("invalid speed limit");}this.speedLimit = speedLimit;}/*** Gets the speed limit* @return the speed limit*/public int getSpeedLimit() {return this.speedLimit;}/*** Checks to see if the given miles-per-hour* is considered speeding.** @precondition mph >= 0* @postcondition none** @returns true if speeding; false otherwise*/public boolean isSpeeding(int mph) {if (mph < 0) {throw new IllegalArgumentException("invalid mph");}return (mph > this.speedLimit);}}Write a JUnit test for the SpeedTrap constructor named testWhenOneUnderSpeedLimitBoundaryarrow_forwardjava code quation using ExceptionProgramme Leader of ITMB wants to check whether the student number and GSM numberentered by the student for the programming contest is valid or not.Write a Java program to read the Student ID and GSM Number of a student. Use a methodcalled ValidityDetails () for checking the validity of details entered.If the Student ID ends with the characters ST and contains more than 6 letters or if the MobileNumber does not contain exactly 8 digits, throw a user defined exceptionInvalidDetailsException.If the details entered are valid, display the message ‘”correct details are entered!!!” otherwisedisplay “Entered invalid details!!!!”arrow_forward
- PF Assignment 3 BS ERP 105903 Submission date: 18th April, 2021 via LMS Assignment should include:Hand Wriiten Coding + Screenshot of Output (a) Create a method GetMax() which takes two integer (int) parameters as an arguments and returns maximal of the two numbers. (b) Write a program that reads three numbers from the console and prints the biggest of them. Use the GetMax() method you just created. Write a test program that validates that the methods works correctly. Write a method that returns the digits of a given decimal number in a reversed order. For example 256, must be printed as 652. Write a program in C to check a given number is positive or negative using method. Write a program that calculates and prints the n! for any n in the range [1…10] number should be taken as input from user through main and should pass as an argument to the method. Write a program in C# Sharp to create a function to input a string and return count of number of spaces are in the…arrow_forwardAssume that the SampleQueue class, with the given code below, is used in the TestSampleQueue that is also shown below. Show the output of the TestSampleQueue. Do the exercise without using a computer (i.e. Make amanual trace of the program):// TestSampleQueue classimport java.io.*;import java.lang.*;public class TestSampleQueue {private SampleQueue<Integer> queue = new SampleQueue<Integer>();public void run() throws Exception {queue.enqueue(new Integer(10));System.out.println(queue.toString());queue.enqueue(new Integer(5));System.out.println(queue.toString());queue.dequeue();System.out.println(queue.toString());queue.enqueue(new Integer(15));System.out.println(queue.toString());queue.enqueue(new Integer(7));System.out.println(queue.toString());queue.dequeue();System.out.println(queue.toString());} // end of run methodpublic static void main(String[] args) {TestSampleQueue program;try {program = new TestSampleQueue();program.run();} catch ( Exception e )…arrow_forwardHow to develop a test from this code using JUNIT test code? package stubdriver; public class Driver1{public static void main(String[] args){double converted, original;int i, j;String from, to;String[] units = {"inches","feet","yards","miles"};UnitConverter1 calculator; calculator = new UnitConverter1(); original = 10.0;for (i=0; i < units.length; i++) {for (j=0; j < units.length; j++) { from = units[i]; // This could be outside the inner loopto = units[j];converted = calculator.convert(original, from, to);System.out.println(original+" "+from+" = "+converted+" "+to);}}} }arrow_forward
- Question 16 Rk .Please tell me the process of getting this answer:) void quiz( int i ) { if( i > 1) { quiz( i / 2); quiz( i/ 2); } System.out.print(" * "); } How many asterisks are printed by the method call quiz(5)? //Answer: 7 Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardWrite code that prints: firstNumber ... 2 1Print a newline after each number. Ex: If the input is: 3 the output is: 3 2 1 #include <stdio.h> int main(void) { int firstNumber; int i; scanf("%d", &firstNumber); for(/* Your code goes here */) { printf("%d\n", i); } return 0;}arrow_forwardurgentarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License