Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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_a(int n) { System.out.println(n + " "); if (n>0) test_a(n-2); }What is printed by the call test_a(6)?
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)?
Chapter 16 Solutions
Problem Solving with C++ (10th 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
- You are to develop a set ofunit testcasesfor the following code block.Note that the code below 5 may contain some faults. The test cases you write should catch these faults and any others that might arise as the code evolves. Write at-least 5 tests, make sure that your tests cover and test evert aspect of the code.arrow_forwardthis 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."); } }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_forward
- Complete 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_forwardComplete both Unit Tests using the given code Unit Test #1 performOperation addition test Build Output NtTest6b116967.java:9: error: performOperation(double,double,String) has private access in Calculator assertTrue(tester201.performOperation(5, 2, "+") == 7.00); ^ Test Contents Calculator tester201 = new Calculator(); @Test public void unitTest() { assertTrue(tester201.performOperation(5, 2, "+") == 7.00); } Unit Test #2 performOperation multiplication test Build Output NtTeste16b3fd1.java:9: error: performOperation(double,double,String) has private access in Calculator assertTrue(tester202.performOperation(5, 2, "*") == 10); Test Contents ^ Calculator tester202 = new Calculator(); @Test public void unitTest() { assertTrue(tester202.performOperation(5, 2, "*") == 10); } The Given Code // Calculator.java - This program performs arithmetic, ( +. -, *. /, % ) on two…arrow_forwardPlease help, write the code for the test cases: public class JunitTest_RideRequestTest { // Test parameterized constructor with invalid input @Test public void test_2_0() { try { RideRequest request = new RideRequest(new String()); fail("You should throw an exception If the input is null or empty."); } catch (IllegalArgumentException e) { // exception excepted do nothing } } @Test public void test_2_2() { RideRequest request = null; try { RideRequest request2 = new RideRequest(request); fail("You should throw an exception If the input is null."); } catch (IllegalArgumentException e) { // exception excepted do nothing } } @Test public void test_2_3() { String s = "John , Downtown , 50.0 , Y , extra info"; try { RideRequest request2 = new RideRequest(s);…arrow_forward
- Print "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 9. Otherwise, print "userNum2 is less than or equal to 9.". End with newline. 1 import java.util.Scanner; 2 public class UserNums { public static void main (String [] args) { int userNum1; int userNum2; 4 6. 7 Scanner input userNum1 = 8. = new Scanner(System.in); input.nextInt(); input.nextInt(); 9. 10 userNum2 11 12 V* Your code goes here */ 13 System.out.println("userNum2 is " } 14 + userNum2); 15 16 17 }arrow_forwardJava Exception 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.0arrow_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 named testWhenSpeeding that uses a value for mph that is valid and is considered speeding.arrow_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 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_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_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