100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

CSE 2221 Final Exam Review| Study Questions Solved 100% Correct

Rating
-
Sold
-
Pages
25
Grade
A+
Uploaded on
07-09-2024
Written in
2024/2025

CSE 2221 Final Exam Review| Study Questions Solved 100% Correct

Institution
CSE 2221
Course
CSE 2221

Content preview

CSE 2221 Final Exam Review| Study
Questions Solved 100% Correct

If you write class C implements interface I, the Java compiler checks:
a. Whether I overrides all the methods of C
b. Whether C inherits all the methods of I
c. Whether each method in I has a method body in C

d. Whether each method body in C is a correct implementation of the contract for that method
in I - ANSWER c. Whether each method in I has a method body in C


Consider the following code:
int x=80;
if (x>70){
x=40;
}else if (x<90){
x=20;
}
if (x>30){
x=60;
}
a. 20
b. 40
c. 60
d. 80 - ANSWER C. 60


In design-by-contract, the code responsible for making sure the precondition (requires clause)
is true when a method is called is:

,a. the code that implements the method

b. the client code that calls the method
c. both the client and the implementation code

d. neither the client nor the implementation code - ANSWER b. the client code that calls
the method



Suppose you want want to set teh double variable value to a random real number
uniformly distributed in the interval [-2.0, 2.0). You have made the following declaration:
Random r=new Random1L();

noting that r.nextDouble() returns a random real number uniformly distributed in the
interval [0.0, 1.0). Which statement will set value to the desired result?
a. value=-2.0 * r.nextDouble();
b. value=-2.0+2.0*r.nextdouble();
c. value= 4.0*r.nextDouble()-2.0;
d. value=-2.0 *r.nextDouble() + 2.0*r.nextDouble() - ANSWER c. value= 4.0*r.nextDouble()-2.0;


Consider the following method header:
private static boolean isPrime(int x)
and the call:
boolean answer=isPrime(number);
In this context:
a. x is a formal parameter and number is an argument(or actual parameter)
b. x is an argument (or actual parameter) and number is a formal parameter
c. x is a local variable and number is a distinguished variable

d. both x and number are global variables - ANSWER a. x is a formal parameter and number is
an argument(or actual parameter)


If a and b are boolean variables, when does the expression (!a||!b) evaluate to false?
a. when either a or b is true, but not both

, b. when both a and b are false
c. when both a and b are true
d. when a is not equal to b - ANSWER c. when both a and b are true


Consider the following method header:
private static void setToZero (int x)
and the client code:
int number=10;
setToZero(number);
The value of variable number after the method call:
a. is guaranteed to be 0
b. is guaranteed to be 10
c. could be either 0 or 10, but nothing else

d. could be anything; there is not enough information to know - ANSWER b. is guaranteed to
be 10


What is the value of nums[1] +nums[3] just after you declare:
int[] nums={7,3,5,6};
a.12
b.9
c.4
d. It is impossible to tell - ANSWER b.9



Which line of code could be the body of a method that reports whether a point
with coordinates (x,y) is inside the square with sides of length 2 centered (1,1)?

a. return(Math.abs(x)<=1.0 &&Math.abs(y)<=1.0);
b. return(x<=2.0 && y<=2.0);
c. return (Math.abs(x-1.0)<=1.0 && Math.abs(y-1.0)<==1.0)

Written for

Institution
CSE 2221
Course
CSE 2221

Document information

Uploaded on
September 7, 2024
Number of pages
25
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
KenAli West Virginia University
View profile
Follow You need to be logged in order to follow users or courses
Sold
90
Member since
1 year
Number of followers
5
Documents
17546
Last sold
1 month ago

2.6

17 reviews

5
2
4
4
3
4
2
0
1
7

Trending documents

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

Frequently asked questions