Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

CS 1103 Programming 2 with Verified Answers A+ Grade 100%.

Rating
-
Sold
-
Pages
16
Grade
A+
Uploaded on
27-03-2025
Written in
2024/2025

A switch statement, most often has the form: switch (expression) { case constant-1: statements-1 break; ... } The value of the expression can be: i. int ii. short iii. byte iv. Primitive char v. Enum vi. String vii. Real number - c. All, except vi and vii The following code writes out the name of a day of the week depending on the value of day. True or False? String dayName = null; switch (day) { case 1: dayName = "Sunday"; break; case 2: dayName = "Monday"; break; case 3: dayName = "Tuesday"; break; case 4: dayName = "Wednesday"; break; case 5: dayName = "Thursday"; break; case 6: dayName = "Friday"; break; case 7: dayName = "Saturday"

Show more Read less
Institution
Course

Content preview

CS 1103 Programming 2 with Verified Answers A+ Grade
100%.
A switch statement, most often has the form:
switch (expression) {
case constant-1:
statements-1
break;
...
}

The value of the expression can be:
i. int
ii. short
iii. byte
iv. Primitive char
v. Enum
vi. String
vii. Real number - c. All, except vi and vii

The following code writes out the name of a day of the week depending on the value of day.
True or False?

String dayName = null;
switch (day) {
case 1:
dayName = "Sunday";
break;
case 2:
dayName = "Monday";
break;
case 3:
dayName = "Tuesday";
break;
case 4:
dayName = "Wednesday";
break;
case 5:
dayName = "Thursday";
break;
case 6:
dayName = "Friday";
break;
case 7:
dayName = "Saturday";

,break;
}
System.out.println(dayName); - True

Given the following piece of code:

class CostCalculationException extends Exception{}
class Item {
public void calculateCost() throws CostCalculationException {
//...
throw new CostCalculationException();
//...
}
}
class Company {
public void payCost(){
new Item().calculateCost();
}
}

Which of the following statements is correct? - c. This code will compile if you add a try-catch
block in payCost() Correct

d. This code will compile if you add throws CostCalculationException in the signature of method
payCost().

Given the following piece of code:

class Student { public void talk(){} }
public class Test{
public static void main(String args[]){
Student t = null;
try {
t.talk();
} catch(NullPointerException e){
System.out.print("There is a NullPointerException. ");
} catch(Exception e){
System.out.print("There is an Exception. ");
}
System.out.print("Everything ran fine. ");
}
}

what will be the result? - a. If you run this program, the following is printed: There is a
NullPointerException. Everything ran fine.

, Consider the following code (assume that comments are replaced with real code that works as
specified):
public class TestExceptions {

static void e() {
// Might cause any of the following unchecked exceptions to be
// thrown:
// Ex1, Ex2, Ex3, Ex4
}

static void April() {
try {
e();
} catch (Ex1 ex) {
System.out.println("April caught Ex1");
}
}

static void March() {
try {
April();
} catch (Ex2 ex) {
System.out.println("March caught Ex2");
// now cause exception Ex1 to be thrown
}
}

static void February() {
try {
March();
} catch (Ex1 ex) {
System.out.println("February caught Ex1");
} catch (Ex3 ex) {
System.out.println("February caught Ex3");
}
}

static void a() {
try {
February();
} catch (Ex4 ex) {
System.out.println("January caught Ex4");
// now cause exception Ex1 to be thrown
} catch (Ex1 ex) {
System.out.println("January caught Ex1");
}

Written for

Course

Document information

Uploaded on
March 27, 2025
Number of pages
16
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$7.69
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
EXAMHUB1

Get to know the seller

Seller avatar
EXAMHUB1 Cambridge University
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
111
Last sold
-
EXAMHUB1

Hello! My name is EXAMHUB, and I’m an experienced and dedicated online tutor committed to helping students succeed. I provide study materials, notes, and guides to support your academic journey. Your feedback is highly valued, as it helps improve the quality of service and enhances your learning experience. Special Offer! For every student you refer who completes and pays for an order transparently, you’ll receive a free study document of your choice or a complimentary assignment completion! Thank you for your purchase! Please leave a review to share your experience and help others assess the quality of the documents. Your feedback is greatly appreciated!

Read more Read less
0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions