SlideShare a Scribd company logo
1 of 21
1
Midterm Preview
Time allotted: 50 minutes
CS 110, Programming Fundamentals I
Central Washington University
Computer Science
Instructions
There are five sections on this exam that contain 24 required
questions, a sixth section that contains extra
credit questions, and a last, seventh section, with supplementary
information that may be helpful in answering
some of the required questions. This midterm is worth 100
points. Each question in a section is worth the points
indicated at the beginning of the section.
• Pace yourself
• Do not spend too much time on any one question
• Partial credit will be given, if warranted
• Partial credit will NOT be given on the extra credit questions,
and points will NOT be taken off for
incorrectly answering an extra credit question
This exam is a closed book, closed notes, no IPhones, no
Internet, etc. exam. All that you need is a pen or
pencil.
Name (Print)
Honor Code Statement: I pledge that this submission is solely
my work, and that I have neither
given to, nor received help from anyone.
Signature:
Section Question Type Question Numbers Points Possible
Points Scored
I True / False 1-10 20
II Multiple Choice 11-15 20
III Find the Error 16 20
IV Short Answer 17-22 30
V One or More Answers 23-24 10
Total 100
VI Extra Credit
Total Including Extra Credit
2
Section I: True/False Each question is worth 2 points; no partial
credit given
Circle either True or False.
1. True / False The following is a syntactically correct variable
declaration and assignment
statement:
double int = 2.0;
2.
True / False
The diagram in Figure 1a is the decision structure logic of the
Java statements in
Figure 1b.
if (Condition_1){
if (Condition_2){
Statement_B;
}else{
Statement_C;
}
}
if (! Condition_1){
Statement_A;
}
Figure 1a Figure 1b
3. True / False Java is a case sensitive programming language.
4. True / False Assuming that letter has been declared as a
variable of type char, the below
statement is syntactically correct:
letter = “a”;
5. True / False For the logical AND operator, &&, which
connects two boolean expressions, both
expressions must be false for the overall expression to be false.
6. True / False The below two pieces of code output the same
thing to the console:
int someVariable = 0;
System.out.println(“Output : “ + someVariable);
int someVar1 = 1, someVar2 = 2;
System.out.println(“Output : “ + someVar1 / someVar2);
7. True / False Syntax errors are mistakes that the programmer
has made that violate the rules of the
programming language.
3
8. True / False The following Java code is syntactically
incorrect:
Scanner keyBoard = new Scanner(System.in);
int someValue = keyBoard.nextInt();
switch (someValue){
case 1:
case 2:
case 3:
System.out.println("Input is 1 or 2 or 3.");
break;
default:
System.out.println("Input is not 1, not 2 nor 3.");
}
9. True / False The following piece of Java code is syntactically
correct:
int k = 0;
for (int i=0; i<10; i--);{k++;}
10. True / False The equality operator, ==, cannot be used to
compare the values stored in two
variables of type String.
Section II: Multiple Choice Each question is worth 4 points; no
partial credit given
Directions: Circle the single correct choice from among the
provided lettered options for each question.
11. Assuming x has been declared as a variable of type int, the
below Java code in the box is equivalent to
which of the logical statements?
if (x > -1 && x < 100)
A. If x is greater than 0 and x is less than 99
B. If x is greater than 1 and x is less than 99
C. If x is (0 or greater) and x is less than 99
D. If x is (0 or greater) and x is at most 99
12. What does the following piece of Java code output:
String sentence = “heya”;
System.out.println(sentence.toLowerCase());
A. heya
B. Heya
C. HeYa
D. HEYA
4
13. Major components of a typical modern computer consist of:
A. The Central Processing Unit
B. Input/output devices
C. Secondary storage devices
D. All of the above
14. What will be the values of x and y after the following code
is executed?
int x = 25, y = 8;
x += (7-y);
y--;
A. x = 24, y = 7
B. x = 24, y = 8
C. x = 25, y = 7
D. x = 25, y = 8
E. x = 26, y = 7
F. x = 26, y = 8
15. What would be the value of percentVal after the following
statements are executed?
A. 0.05 double percentVal = 0.0; int purchase = 950;
B. 0.04 char cust = 'N';
C. 0.03 if (purchase > 1000){
D. 0.02 if (cust == 'Y')
E. 0.01 percentVal = .05;
else
percentVal = .04;
} else {
if (cust == 'Y')
percentVal = .03;
else
percentVal = .02;
}
percentVal = .05;
5
Section III: Find the Error This question is worth 20 points;
partial credit given
16. For the below Java code, circle any portion that contains a
syntax error. Circle those parts of the
Java code where there is a mistyped character, missing
semicolon, etc.
public class HowMuchTimeRemaining
public static void main (String[] args){
timeRemaining double = 12.5;
timeSinceStart double = 33.0;
if (timEremaining =< 10.647320){
System.out.println("Less than 10 minutes
left.")
} else if (timeRemaining < 20.2098756434){
System("Less than 20.2098756434 but more than 10.647320
minutes left.")
} else {
System.out.println("Ahh. At least 20 minutes remaining.")
}
}
}
Section IV: Short Answer Each question is worth 5 points;
partial credit given
Directions: Provide a short, concise answer for each question.
17. Explain the following line of code (do NOT predict the
value of x; explain what the statement does).
final int x = 10/5;
Your Answer :
18. What is the value of y after the following code is executed?
int y = 1;
while (y < 10){
y += 3;
}
Your Answer :
6
19. What is the output of the following Java Program?
public class MidtermQuestion {
public static void main (String[] args){
String cwu = "Central Washington University";
System.out.print(cwu.substring(0,1));
System.out.println(cwu.substring(cwu.length()-3,cwu.length()));
}
}
Your Answer :
20. The binary encoding 00001110 is equivalent to what base-10
number? Show your work to receive
partial credit, in the case that your answer is incorrect.
Your Answer :
21. Write a one-line syntactically correct Java statement that
declares a variable animal of type String
and assigns it the value tiger
Your Answer:
7
22. Write a Java program that will print to the console all even
integers starting from 2 through (and
including) 50. Complete the program, which has been started for
you. Hint: you can use a while or
for loop. Hint 2: One correct solution requires only 3 lines of
VERY simple code.
// A program that prints the even integers
// from 2 through (and including) 50
public class EvenNumFrom2Through50 {
// the main routine
public static void main (String[] args) {
}
}
8
Section V: Multiple Choice, Multiple Answer Each question is
worth 5 points; partial credit given
Directions: Select ALL correct answer choices, for each
question. The correct answer might be one, two-
or more, or all choices. For each choice that you circle that is
NOT a correct answer, you will be deducted
1 point. For each choice that you do NOT circle that should be
circled, you will lose 1 point. You cannot
lose more than 5 points for a question.
23. Which of the following statements is/are true about
comments.
A. A single line comment begins with the characters 
B. A multiple-line comment begins with */
C. The following is a syntactically correct comment: // */ */
//////////
D. Single-line comments are ignored by the compiler
E. Multiple-line comments are not ignored by the compiler
F. Multiple-line comments must end with the characters /*
24. Based on the for-loop shown below, which of the lettered
choice is/are correct?
for (int i=-1; i<10; i+=2){
System.out.print(i);
}
A. The body of the for-loop will be executed 5 times
B. The i+=2 part of the for loop will be performed 5 times
C. The output produced by the for loop will be -113579
D. The i+=2 part of the for loop is performed as many times as
the i<10 check is performed
E. The i<10 part of the for loop is the initialization portion, and
is executed only once
F. The i+=2 part of the for loop is executed at least once.
Section VI: Extra Credit; Questions are worth 3 points; no
partial credit given; no penalty for guessing
This section will contain 3 extra credit questions.
9
Section VII: Supplementary Information which MAY help you
to answer some of the required questions
String Methods
Method Description
charAt(index) The argument index is an integer value and
specifies a character position in the string
length() This method returns the number of characters in the
string
toLowerCase() This method returns a new string that is the
lowercase equivalent of the original string object
toUpperCase() This method returns a new string that is the
uppercase equivalent of the original string object
substring(a,b) This method returns a substring with starting
position a and continuing to (and not including)
the character at position b of the original string.
Binary Representation of Base-10 Integers
Left-most Right-most
Binary representation for
each position of a byte
7
2
6
2
5
2
4
2
3
2
2
2
1
2 2
0
Decimal equivalent of binary
representation
128 64 32 16 8 4 2 1
Java's 8 Primitive Data Types and the String Class
Data Type Description Examples
byte The byte data type is an 8-bit integer. It has a minimum
value of -128 and a
maximum value of 127 (inclusive).
-34, 0, 17
short The short data type is a 16-bit integer. It has a minimum
value of -32,768
and a maximum value of 32,767 (inclusive).
-34, 17653, 0
int The int data type is a 32-bit integer. It has a minimum value
of -
2,147,483,648 and a maximum value of 2,147,483,647
(inclusive).
-34, 32, -787632,
123443235
long The long data type is a 64-bit signed integer. It has a
minimum value of -
9,223,372,036,854,775,808 and a maximum of
9,223,372,036,854,775,807.
-123443235, 0, 1,
381234432327
float The float data type is a single-precision 32-bit IEEE 754
floating point. 1256.7f, 123.4f
double The double data type is a double-precision 64-bit IEEE
754 floating point. -3456.0, 3256.543
boolean The boolean data type has only two possible values
true, false
char The char data type is a single 16-bit Unicode character. It
has a minimum
value of 'u0000' (or 0) and a maximum value of 'uffff' (or
65,535 inclusive).
A char is enclosed in single quotes.
'a', '45'
String The String class represents character strings. All string
literals in Java are
enclosed in double quotes, and are implemented as instances of
this class.
“Hello”, “hElLo”,
“a”, “45”

More Related Content

Similar to 1 Midterm Preview Time allotted 50 minutes CS 11.docx

Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
rosemarybdodson23141
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
maxinesmith73660
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
amrit47
 

Similar to 1 Midterm Preview Time allotted 50 minutes CS 11.docx (20)

Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
9 January 2023(Tech).pdf
9 January 2023(Tech).pdf9 January 2023(Tech).pdf
9 January 2023(Tech).pdf
 
Java Foundations: Basic Syntax, Conditions, Loops
Java Foundations: Basic Syntax, Conditions, LoopsJava Foundations: Basic Syntax, Conditions, Loops
Java Foundations: Basic Syntax, Conditions, Loops
 
Core java
Core javaCore java
Core java
 
Ansi c
Ansi cAnsi c
Ansi c
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
Java tut1
Java tut1Java tut1
Java tut1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
 
Testing techniques
Testing techniquesTesting techniques
Testing techniques
 
Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operators
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Presentation slides: "How to get 100% code coverage"
Presentation slides: "How to get 100% code coverage" Presentation slides: "How to get 100% code coverage"
Presentation slides: "How to get 100% code coverage"
 

More from honey725342

NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docxNRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
honey725342
 
Now the Earth has had wide variations in atmospheric CO2-level throu.docx
Now the Earth has had wide variations in atmospheric CO2-level throu.docxNow the Earth has had wide variations in atmospheric CO2-level throu.docx
Now the Earth has had wide variations in atmospheric CO2-level throu.docx
honey725342
 
Nurse Education Today 87 (2020) 104348Contents lists avail.docx
Nurse Education Today 87 (2020) 104348Contents lists avail.docxNurse Education Today 87 (2020) 104348Contents lists avail.docx
Nurse Education Today 87 (2020) 104348Contents lists avail.docx
honey725342
 
Now that you’ve seen all of the elements contributing to the Devil’s.docx
Now that you’ve seen all of the elements contributing to the Devil’s.docxNow that you’ve seen all of the elements contributing to the Devil’s.docx
Now that you’ve seen all of the elements contributing to the Devil’s.docx
honey725342
 
NR360 We Can But Dare We.docx Revised 5 ‐ 9 .docx
NR360   We   Can   But   Dare   We.docx   Revised   5 ‐ 9 .docxNR360   We   Can   But   Dare   We.docx   Revised   5 ‐ 9 .docx
NR360 We Can But Dare We.docx Revised 5 ‐ 9 .docx
honey725342
 
NURS 6002 Foundations of Graduate StudyAcademic and P.docx
NURS 6002 Foundations of Graduate StudyAcademic and P.docxNURS 6002 Foundations of Graduate StudyAcademic and P.docx
NURS 6002 Foundations of Graduate StudyAcademic and P.docx
honey725342
 
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docxNur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
honey725342
 
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docxNU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
honey725342
 
NR631 Concluding Graduate Experience - Scope Project Managemen.docx
NR631 Concluding Graduate Experience - Scope  Project Managemen.docxNR631 Concluding Graduate Experience - Scope  Project Managemen.docx
NR631 Concluding Graduate Experience - Scope Project Managemen.docx
honey725342
 

More from honey725342 (20)

NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docxNRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
 
Now the Earth has had wide variations in atmospheric CO2-level throu.docx
Now the Earth has had wide variations in atmospheric CO2-level throu.docxNow the Earth has had wide variations in atmospheric CO2-level throu.docx
Now the Earth has had wide variations in atmospheric CO2-level throu.docx
 
NR224 Fundamentals SkillsTopic Safety Goals BOOK P.docx
NR224 Fundamentals SkillsTopic Safety Goals BOOK P.docxNR224 Fundamentals SkillsTopic Safety Goals BOOK P.docx
NR224 Fundamentals SkillsTopic Safety Goals BOOK P.docx
 
Nurse Education Today 87 (2020) 104348Contents lists avail.docx
Nurse Education Today 87 (2020) 104348Contents lists avail.docxNurse Education Today 87 (2020) 104348Contents lists avail.docx
Nurse Education Today 87 (2020) 104348Contents lists avail.docx
 
Now that you’ve seen all of the elements contributing to the Devil’s.docx
Now that you’ve seen all of the elements contributing to the Devil’s.docxNow that you’ve seen all of the elements contributing to the Devil’s.docx
Now that you’ve seen all of the elements contributing to the Devil’s.docx
 
NR360 We Can But Dare We.docx Revised 5 ‐ 9 .docx
NR360   We   Can   But   Dare   We.docx   Revised   5 ‐ 9 .docxNR360   We   Can   But   Dare   We.docx   Revised   5 ‐ 9 .docx
NR360 We Can But Dare We.docx Revised 5 ‐ 9 .docx
 
Nurse Practitioner Diagnosis- Chest Pain.SOAPS-Subjective.docx
Nurse Practitioner Diagnosis- Chest Pain.SOAPS-Subjective.docxNurse Practitioner Diagnosis- Chest Pain.SOAPS-Subjective.docx
Nurse Practitioner Diagnosis- Chest Pain.SOAPS-Subjective.docx
 
NURS 6002 Foundations of Graduate StudyAcademic and P.docx
NURS 6002 Foundations of Graduate StudyAcademic and P.docxNURS 6002 Foundations of Graduate StudyAcademic and P.docx
NURS 6002 Foundations of Graduate StudyAcademic and P.docx
 
Nurse workforce shortage are predicted to get worse as baby boomers .docx
Nurse workforce shortage are predicted to get worse as baby boomers .docxNurse workforce shortage are predicted to get worse as baby boomers .docx
Nurse workforce shortage are predicted to get worse as baby boomers .docx
 
Now, for the exam itself. Below are 4 questions. You need to answer .docx
Now, for the exam itself. Below are 4 questions. You need to answer .docxNow, for the exam itself. Below are 4 questions. You need to answer .docx
Now, for the exam itself. Below are 4 questions. You need to answer .docx
 
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docxNur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
 
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docxNU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
 
Nurse Working in the CommunityDescribe the community nurses.docx
Nurse Working in the CommunityDescribe the community nurses.docxNurse Working in the CommunityDescribe the community nurses.docx
Nurse Working in the CommunityDescribe the community nurses.docx
 
nursing diagnosis1. Decreased Cardiac Output  related to Alter.docx
nursing diagnosis1. Decreased Cardiac Output  related to Alter.docxnursing diagnosis1. Decreased Cardiac Output  related to Alter.docx
nursing diagnosis1. Decreased Cardiac Output  related to Alter.docx
 
Nursing Documentation Is it valuable Discuss the value of nursin.docx
Nursing Documentation Is it valuable Discuss the value of nursin.docxNursing Documentation Is it valuable Discuss the value of nursin.docx
Nursing Documentation Is it valuable Discuss the value of nursin.docx
 
NR631 Concluding Graduate Experience - Scope Project Managemen.docx
NR631 Concluding Graduate Experience - Scope  Project Managemen.docxNR631 Concluding Graduate Experience - Scope  Project Managemen.docx
NR631 Concluding Graduate Experience - Scope Project Managemen.docx
 
Number 11. Describe at least five populations who are vulner.docx
Number 11. Describe at least five populations who are vulner.docxNumber 11. Describe at least five populations who are vulner.docx
Number 11. Describe at least five populations who are vulner.docx
 
ntertainment, the media, and sometimes public leaders can perpetuate.docx
ntertainment, the media, and sometimes public leaders can perpetuate.docxntertainment, the media, and sometimes public leaders can perpetuate.docx
ntertainment, the media, and sometimes public leaders can perpetuate.docx
 
Now that you have  completed Lesson 23 & 24 and have thought a.docx
Now that you have  completed Lesson 23 & 24 and have thought a.docxNow that you have  completed Lesson 23 & 24 and have thought a.docx
Now that you have  completed Lesson 23 & 24 and have thought a.docx
 
nothing wrong with the paper, my professor just wants it to be in an.docx
nothing wrong with the paper, my professor just wants it to be in an.docxnothing wrong with the paper, my professor just wants it to be in an.docx
nothing wrong with the paper, my professor just wants it to be in an.docx
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 

1 Midterm Preview Time allotted 50 minutes CS 11.docx

  • 1. 1 Midterm Preview Time allotted: 50 minutes CS 110, Programming Fundamentals I Central Washington University Computer Science Instructions There are five sections on this exam that contain 24 required questions, a sixth section that contains extra credit questions, and a last, seventh section, with supplementary information that may be helpful in answering some of the required questions. This midterm is worth 100 points. Each question in a section is worth the points indicated at the beginning of the section. • Pace yourself
  • 2. • Do not spend too much time on any one question • Partial credit will be given, if warranted • Partial credit will NOT be given on the extra credit questions, and points will NOT be taken off for incorrectly answering an extra credit question This exam is a closed book, closed notes, no IPhones, no Internet, etc. exam. All that you need is a pen or pencil. Name (Print) Honor Code Statement: I pledge that this submission is solely my work, and that I have neither given to, nor received help from anyone. Signature: Section Question Type Question Numbers Points Possible Points Scored I True / False 1-10 20
  • 3. II Multiple Choice 11-15 20 III Find the Error 16 20 IV Short Answer 17-22 30 V One or More Answers 23-24 10 Total 100 VI Extra Credit Total Including Extra Credit 2 Section I: True/False Each question is worth 2 points; no partial credit given Circle either True or False. 1. True / False The following is a syntactically correct variable declaration and assignment statement: double int = 2.0; 2.
  • 4. True / False The diagram in Figure 1a is the decision structure logic of the Java statements in Figure 1b. if (Condition_1){ if (Condition_2){ Statement_B; }else{ Statement_C; } } if (! Condition_1){ Statement_A; } Figure 1a Figure 1b
  • 5. 3. True / False Java is a case sensitive programming language. 4. True / False Assuming that letter has been declared as a variable of type char, the below statement is syntactically correct: letter = “a”; 5. True / False For the logical AND operator, &&, which connects two boolean expressions, both expressions must be false for the overall expression to be false. 6. True / False The below two pieces of code output the same thing to the console: int someVariable = 0; System.out.println(“Output : “ + someVariable); int someVar1 = 1, someVar2 = 2; System.out.println(“Output : “ + someVar1 / someVar2); 7. True / False Syntax errors are mistakes that the programmer has made that violate the rules of the programming language.
  • 6. 3 8. True / False The following Java code is syntactically incorrect: Scanner keyBoard = new Scanner(System.in); int someValue = keyBoard.nextInt(); switch (someValue){ case 1: case 2: case 3: System.out.println("Input is 1 or 2 or 3."); break; default: System.out.println("Input is not 1, not 2 nor 3."); } 9. True / False The following piece of Java code is syntactically correct:
  • 7. int k = 0; for (int i=0; i<10; i--);{k++;} 10. True / False The equality operator, ==, cannot be used to compare the values stored in two variables of type String. Section II: Multiple Choice Each question is worth 4 points; no partial credit given Directions: Circle the single correct choice from among the provided lettered options for each question. 11. Assuming x has been declared as a variable of type int, the below Java code in the box is equivalent to which of the logical statements? if (x > -1 && x < 100) A. If x is greater than 0 and x is less than 99 B. If x is greater than 1 and x is less than 99
  • 8. C. If x is (0 or greater) and x is less than 99 D. If x is (0 or greater) and x is at most 99 12. What does the following piece of Java code output: String sentence = “heya”; System.out.println(sentence.toLowerCase()); A. heya B. Heya C. HeYa D. HEYA 4 13. Major components of a typical modern computer consist of: A. The Central Processing Unit
  • 9. B. Input/output devices C. Secondary storage devices D. All of the above 14. What will be the values of x and y after the following code is executed? int x = 25, y = 8; x += (7-y); y--; A. x = 24, y = 7 B. x = 24, y = 8 C. x = 25, y = 7 D. x = 25, y = 8 E. x = 26, y = 7 F. x = 26, y = 8 15. What would be the value of percentVal after the following statements are executed?
  • 10. A. 0.05 double percentVal = 0.0; int purchase = 950; B. 0.04 char cust = 'N'; C. 0.03 if (purchase > 1000){ D. 0.02 if (cust == 'Y') E. 0.01 percentVal = .05; else percentVal = .04; } else { if (cust == 'Y') percentVal = .03; else percentVal = .02; } percentVal = .05; 5 Section III: Find the Error This question is worth 20 points; partial credit given
  • 11. 16. For the below Java code, circle any portion that contains a syntax error. Circle those parts of the Java code where there is a mistyped character, missing semicolon, etc. public class HowMuchTimeRemaining public static void main (String[] args){ timeRemaining double = 12.5; timeSinceStart double = 33.0; if (timEremaining =< 10.647320){ System.out.println("Less than 10 minutes left.") } else if (timeRemaining < 20.2098756434){ System("Less than 20.2098756434 but more than 10.647320 minutes left.") } else { System.out.println("Ahh. At least 20 minutes remaining.")
  • 12. } } } Section IV: Short Answer Each question is worth 5 points; partial credit given Directions: Provide a short, concise answer for each question. 17. Explain the following line of code (do NOT predict the value of x; explain what the statement does). final int x = 10/5; Your Answer : 18. What is the value of y after the following code is executed? int y = 1; while (y < 10){ y += 3;
  • 13. } Your Answer : 6 19. What is the output of the following Java Program? public class MidtermQuestion { public static void main (String[] args){ String cwu = "Central Washington University"; System.out.print(cwu.substring(0,1)); System.out.println(cwu.substring(cwu.length()-3,cwu.length())); } } Your Answer : 20. The binary encoding 00001110 is equivalent to what base-10 number? Show your work to receive
  • 14. partial credit, in the case that your answer is incorrect. Your Answer : 21. Write a one-line syntactically correct Java statement that declares a variable animal of type String and assigns it the value tiger Your Answer: 7 22. Write a Java program that will print to the console all even integers starting from 2 through (and including) 50. Complete the program, which has been started for you. Hint: you can use a while or for loop. Hint 2: One correct solution requires only 3 lines of VERY simple code.
  • 15. // A program that prints the even integers // from 2 through (and including) 50 public class EvenNumFrom2Through50 { // the main routine public static void main (String[] args) { } }
  • 16. 8 Section V: Multiple Choice, Multiple Answer Each question is worth 5 points; partial credit given Directions: Select ALL correct answer choices, for each question. The correct answer might be one, two- or more, or all choices. For each choice that you circle that is NOT a correct answer, you will be deducted 1 point. For each choice that you do NOT circle that should be circled, you will lose 1 point. You cannot lose more than 5 points for a question. 23. Which of the following statements is/are true about comments. A. A single line comment begins with the characters B. A multiple-line comment begins with */ C. The following is a syntactically correct comment: // */ */ ////////// D. Single-line comments are ignored by the compiler E. Multiple-line comments are not ignored by the compiler F. Multiple-line comments must end with the characters /*
  • 17. 24. Based on the for-loop shown below, which of the lettered choice is/are correct? for (int i=-1; i<10; i+=2){ System.out.print(i); } A. The body of the for-loop will be executed 5 times B. The i+=2 part of the for loop will be performed 5 times C. The output produced by the for loop will be -113579 D. The i+=2 part of the for loop is performed as many times as the i<10 check is performed E. The i<10 part of the for loop is the initialization portion, and is executed only once F. The i+=2 part of the for loop is executed at least once. Section VI: Extra Credit; Questions are worth 3 points; no partial credit given; no penalty for guessing This section will contain 3 extra credit questions.
  • 18. 9 Section VII: Supplementary Information which MAY help you to answer some of the required questions String Methods Method Description charAt(index) The argument index is an integer value and specifies a character position in the string length() This method returns the number of characters in the string toLowerCase() This method returns a new string that is the lowercase equivalent of the original string object toUpperCase() This method returns a new string that is the uppercase equivalent of the original string object substring(a,b) This method returns a substring with starting position a and continuing to (and not including) the character at position b of the original string. Binary Representation of Base-10 Integers Left-most Right-most
  • 19. Binary representation for each position of a byte 7 2 6 2 5 2 4 2 3 2 2 2 1 2 2 0 Decimal equivalent of binary representation 128 64 32 16 8 4 2 1 Java's 8 Primitive Data Types and the String Class Data Type Description Examples
  • 20. byte The byte data type is an 8-bit integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). -34, 0, 17 short The short data type is a 16-bit integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). -34, 17653, 0 int The int data type is a 32-bit integer. It has a minimum value of - 2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). -34, 32, -787632, 123443235 long The long data type is a 64-bit signed integer. It has a minimum value of - 9,223,372,036,854,775,808 and a maximum of 9,223,372,036,854,775,807. -123443235, 0, 1, 381234432327 float The float data type is a single-precision 32-bit IEEE 754 floating point. 1256.7f, 123.4f double The double data type is a double-precision 64-bit IEEE 754 floating point. -3456.0, 3256.543
  • 21. boolean The boolean data type has only two possible values true, false char The char data type is a single 16-bit Unicode character. It has a minimum value of 'u0000' (or 0) and a maximum value of 'uffff' (or 65,535 inclusive). A char is enclosed in single quotes. 'a', '45' String The String class represents character strings. All string literals in Java are enclosed in double quotes, and are implemented as instances of this class. “Hello”, “hElLo”, “a”, “45”