Font size
WorksheetsCMP128 Java Ch. 11-07-05-04 Exam #2 Study Guide Quiz
Total questions: 84
Worksheet time: 3hrs 41mins
for (int i=0; i<5; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i));
}
int num = 1;
char keepSquaring = 'Y';
do
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
System.out.print("Would you like to square another number? (Y/N): ");
keepSquaring = keyboard.nextLine().charAt(0);
}
while (keepSquaring == 'Y' || keepSquaring == 'y');
int num = 1;
char keepSquaring = 'Y';
while (keepSquaring == 'Y' || keepSquaring == 'y')
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
System.out.print("Would you like to square another number? (Y/N): ");
keepSquaring = keyboard.nextLine().charAt(0);
}
int num = 1;
char keepSquaring = 'Y';
while (keepSquaring == 'Y' || keepSquaring == 'y')
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
}
for (int i=0; i>5; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i) + "\n");
}
for (int i=10; i>0; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i) + "\n");
}
for (int i=0; i<5; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i) + "\n");
}
int num = 1;
char keepSquaring = 'Y';
do
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
System.out.print("Would you like to square another number? (Y/N): ");
keepSquaring = keyboard.nextLine.charAt(0);
}
while (keepSquaring == 'Y' || keepSquaring == 'y')
int num = 1;
do
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
System.out.print("Would you like to square another number? (Y/N): ");
keepSquaring = keyboard.nextLine().charAt(0);
}
while (keepSquaring == 'Y' || keepSquaring == 'y');
int num = 1;
char keepSquaring = 'Y';
while (keepSquaring == 'Y' || keepSquaring == 'y');
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
System.out.print("Would you like to square another number? (Y/N): ");
keepSquaring = keyboard.nextLine().charAt(0);
}
A ___________ is a pre-defined set of steps that complete a specific task, optionally based on parameter values, and optionally returning some result.
array
function
method
module
class
Java method (function/module) definitions can contain which of the following parts in their headers?
An access modifier such as public or private
An optional access specifier called static
a return type or void
all of the above
Java method definitions require which of the following parts in their headers?
A method name
a set of parentheses
a comma-separated parameter list
all of the above
The body of a method definition is contained within a set of ______________.
parentheses
rectangle brackets
curly braces
angle brackets
Methods are called (instantiated/invoked) by referencing the __________ of the method and any optional _____________ list.
data type, parameter
method name, argument
public keyword, parameter
static keyword, argument
Methods that contain the _______ keyword in the data type position do not return any data, so they can simply be called without being part of a larger statement.
void
static
public
boolean
public static void welcomeBanner(char symbol)
{
for (int i=0; i<60; i++)
System.out.print(symbol);
System.out.println(" ");
System.out.println(symbol + " This is a Welcome Banner " + symbol);
for (int i=0; i<60; i++)
System.out.print(symbol);
System.out.println(" ");
}
Which of the following would be the correct way to call a welcomeBanner method that contains a parameter for the symbol of the border and does not return data?
answer = welcomeBanner('$');
System.out.println("Calling a method" + welcomeBanner('%') );
welcomeBanner('*');
None of the above
What type of data will be returned by this method?
public static boolean isCorrect(char answer)
{
boolean result=false;
switch (answer)
{
case 'C':
result = true;
break;
case 'A':
case 'B':
case 'D':
default:
result = false;
}//end switch
return result;
}//end method isCorrect
int
void
static
char
boolean
Based on the method definition below, what will happen when the following method invoking statement is processed?
boolean questionResult = false;
questionResult = isCorrect('C');
public static boolean isCorrect(char answer)
{
boolean result=false;
switch (answer)
{
case 'C':
result = true;
break;
case 'A':
case 'B':
case 'D':
default:
result = false;
}//end switch
return result;
}//end method isCorrect
the method will return false
the method will return true and false
the method will crash the application
the method will return true
What argument value will cause the following method to return false?
public static boolean isCorrect(char answer)
{
boolean result=false;
switch (answer)
{
case 'C':
result = true;
break;
case 'A':
case 'B':
case 'D':
default:
result = false;
}//end switch
return result;
}//end method isCorrect
A
B
D
X
All of the above
What argument value will cause the following method to return a message stating that an invalid option was chosen and that they have to enter only A, B, C or D?
public static boolean isCorrect(char answer)
{
boolean result=false;
switch (answer)
{
case 'C':
result = true;
break;
case 'A':
case 'B':
case 'D':
default:
result = false;
}//end switch
return result;
}//end method isCorrect
default
A
D
B
It's not possible to return that message with this method.
Which of the following would be a valid return value for the following method?
public static String getMessage()
{
int answer=0;
System.out.print("Enter a Number from 1-5: ")
answer = keyboard.nextInt();
switch (answer)
{
case 1:
return ____________ ;
break;
case 2:
return ____________ ;
break;
case 3:
return ____________ ;
break;
case 4:
return ____________ ;
break;
case 5:
return ____________ ;
break;
default:
return ____________ ;
}//end switch
}//end method getMessage
1
'5'
'You chose 2'
"You chose 5. The squared value of 5 is 25."
What is returned by the following method if the user enters 4?
public static String getMessage()
{
int answer=0;
System.out.print("Enter a Number from 1-5: ")
answer=keyboard.nextInt();
switch (answer)
{
case 1:
return "You entered 1. It's a great number, but it's not the lucky guess for you." ;
break;
case 2:
return "You entered 2. Twice as nice...or doubly wrong? Wanna double down?";
break;
case 3:
return "You entered 3. Third time just wasn't a charm for you. More like three strikes...well, you know the rest.";
break;
case 4:
return "You entered 4. Duck...there's a golf ball coming your way!";
break;
case 5:
return "You entered 5. High Five, Dude! You win the prize...whatever that is." ;
break;
default:
return "You don't take direction well, do you? That wasn't 1-5. Wanna try again?";
}//end switch
}//end method getMessage
An unlucky result.
A statement about possible double trouble.
Something the baseball player at bat doesn't want to hear.
A warning about impending pain headed toward you.
A hand-slapping congratulatory message
What is wrong with the following code?
getMessage();
public static String getMessage()
{
int answer=0;
System.out.print("Enter a Number from 1-5: ")
answer=keyboard.nextInt();
switch (answer)
{
case 1:
return "You entered 1. It's a great number, but it's not the lucky guess for you." ;
break;
case 2:
return "You entered 2. Twice as nice...or doubly wrong? Wanna double down?";
break;
case 3:
return "You entered 3. Third time just wasn't a charm for you. More like three strikes...well, you know the rest.";
break;
case 4:
return "You entered 4. Duck...there's a golf ball coming your way!";
break;
case 5:
return "You entered 5. High Five, Dude! You win the prize...whatever that is." ;
break;
default:
return "You don't take direction well, do you? That wasn't 1-5. Wanna try again?";
}//end switch
}//end method getMessage
There are too many return statements that conflict with each other.
The method invoking statement doesn't catch the returned value and do anything with it.
No input is collected from the user.
Everything is fine with this code.
What is wrong with the following code?
int result = getMessage();
public static String getMessage()
{
int answer=0;
System.out.print("Enter a Number from 1-5: ")
answer=keyboard.nextInt();
switch (answer)
{
case 1:
return "You entered 1. It's a great number, but it's not the lucky guess for you." ;
break;
case 2:
return "You entered 2. Twice as nice...or doubly wrong? Wanna double down?";
break;
case 3:
return "You entered 3. Third time just wasn't a charm for you. More like three strikes...well, you know the rest.";
break;
case 4:
return "You entered 4. Duck...there's a golf ball coming your way!";
break;
case 5:
return "You entered 5. High Five, Dude! You win the prize...whatever that is." ;
break;
default:
return "You don't take direction well, do you? That wasn't 1-5. Wanna try again?";
}//end switch
}//end method getMessage
There are too many return statements that conflict with each other.
The method invoking statement doesn't catch the return data and do anything with it.
There is a type mismatch between the return data and the variable that is catching it.
Everything is fine with this code.
What is wrong with the following code?
String result = getMessage(5);
public static String getMessage()
{
int answer=0;
System.out.print("Enter a Number from 1-5: ")
answer=keyboard.nextInt();
switch (answer)
{
case 1:
return "You entered 1. It's a great number, but it's not the lucky guess for you." ;
break;
case 2:
return "You entered 2. Twice as nice...or doubly wrong? Wanna double down?";
break;
case 3:
return "You entered 3. Third time just wasn't a charm for you. More like three strikes...well, you know the rest.";
break;
case 4:
return "You entered 4. Duck...there's a golf ball coming your way!";
break;
case 5:
return "You entered 5. High Five, Dude! You win the prize...whatever that is." ;
break;
default:
return "You don't take direction well, do you? That wasn't 1-5. Wanna try again?";
}//end switch
}//end method getMessage
There is no returned data.
Nothing catches the returned data.
There is no method invoking statement.
The method doesn't take any parameters, so the method invoking statement is invalid.
What is wrong with the following code?
String result = getMessage();
public static String getMessage()
{
int answer=0;
System.out.print("Enter a Number from 1-5: ")
answer=keyboard.nextInt();
switch (answer)
{
case 1:
return "You entered 1. It's a great number, but it's not the lucky guess for you." ;
break;
case 2:
return "You entered 2. Twice as nice...or doubly wrong? Wanna double down?";
break;
case 3:
return "You entered 3. Third time just wasn't a charm for you. More like three strikes...well, you know the rest.";
break;
case 4:
return "You entered 4. Duck...there's a golf ball coming your way!";
break;
case 5:
return "You entered 5. High Five, Dude! You win the prize...whatever that is." ;
break;
default:
return "You don't take direction well, do you? That wasn't 1-5. Wanna try again?";
}//end switch
}//end method getMessage
The method is missing a method invoking statement.
The method is missing a parameter list.
The method doesn't return anything.
Everything is fine with this code.
FileWriter fw = new FileWriter("names.txt", true);
PrintWriter outData = new PrintWriter(fw);
outData.println("Michael Tirrito");
outData.close();
PrintWriter outData = new PrintWriter("names.txt");
outData.println("Michael Tirrito");
String name = " ";
File inData = new File("names.txt");
name = inData.nextLine();
String name = " ";
File inData = new File("addressBlock.txt");
name = inData.nextLine();
Converting Binary Numbers Back to Decimal Numbers and Picking the Character they Represent
Please convert the Binary Number 010001002 back to it's Decimal (base-10) Number. (Hint: Only the 1-bit values matter here.)
Then look up the base-10 number on the provided Unicode & Ascii Character Map to determine what character is represented by 01000100.
Choose the answer that matches the correct Decimal Number & Character.
(This demonstrates your understanding that all characters are stored in the computer as Base-2 Binary Numbers that have been converted from Base-10 Decimal Numbers.)
Below is an 8-bit conversion table that may help you convert between two numbering systems: Base-10 Decimal and Base-2 Binary. A binary (base-2) number of 01000100 has been provided in the table.
12810 6410 3210 1610 0810 0410 0210 0110 Base-10 (Decimal)
0 1 0 0 0 1 0 0 Base-2 (Binary)
8-bit Conversion Table: Converting between Decimal Number System and Binary Number System
UNICODE16 ASCII10 CHARACTER UNICODE16 ASCII10 CHARACTER
004816 4810 0 009716 9710 a
004916 4910 1 009816 9810 b
005016 5010 2 009916 9910 c
005116 5110 3 010016 10010 d
005216 5210 4 010116 10110 e
005316 5310 5 010216 10210 f
005416 5410 6 010316 10310 g
005516 5510 7 010416 10410 h
005616 5610 8 010516 10510 i
005716 5710 9 010616 10610 j
005816 5810 : 010716 10710 k
005916 5910 ; 010816 10810 l
006016 6010 < 010916 10910 m
006116 6110 = 011016 11010 n
006216 6210 > 011116 11110 o
006316 6310 ? 011216 11210 p
006416 6410 @ 011316 11310 q
006516 6510 A 011416 11410 r
006616 6610 B 011516 11510 s
006716 6710 C 011616 11610 t
006816 6810 D 011716 11710 u
006916 6910 E 011816 11810 v
007016 7010 F 011916 11910 w
007116 7110 G 012016 12010 x
007216 7210 H 012116 12110 y
007316 7310 I 012216 12210 z
007416 7410 J 012316 12310 {
007516 7510 K 012416 12410 |
007616 7610 L 012516 12510 }
007716 7710 M 012616 12610 ~
007816 7810 N 012716 12710 [DEL]
007916 7910 O
008016 8010 P
008116 8110 Q
008216 8210 R
008316 8310 S
008416 8410 T
008516 8510 U
008616 8610 V
008716 8710 W
008816 8810 X
008916 8910 Y
009016 9010 Z
009116 9110 [
009216 9210 \
009316 9310 ]
009416 9410 ^
009516 9510 _
0096169610 `
7210 = H (Capital H)
6810 = D (Capital D)
9610 = ` (accent character)
10010 = d (lowercase d)
True or False:
The Four Steps of the Problem Solving Phases, in sequential order, include:
1. Analysis and Specification
2. Algorithm Development
3. Implementation
4. Maintenance
True
False
True or False:
The following is a list of the Four Generations of Computer Hardware:
1. First Generation: Vacuum Tubes
2. Second Generation: Transistors
3. Third Generation: Integrated Circuits
4. Fourth Generation: Microcomputer on a Chip (Microprocessor)
True
False
What kind of code is contained in a Java Class File after compiling your source code?
Executable Code
Binary Code
Batch Code
Byte Code
Given the following method header, select the appropriate method call:
public static boolean isApproved(int age)
boolean sellAlcohol = isApproved(19);
String sellAlcohol = isApproved("Twenty-One");
int sellAlcohol = isApproved(18);
isApproved(21);
Consider the following code:
int num = 15;
while (num > 0)
num = num - 3;
System.out.println(num);
When does num get printed by this code?
Every time the loop body is entered.
Every time the loop iterates, regardless of the condition test
Immediately after the loop terminates
Never
Which of these job duties would a Web Developer perform?
Create and Manage User Accounts on Windows Server using an Active Directory Domain.
Troubleshooting user computing issues via telephone, chat or email.
Write source code with a programming language like Java by analyzing an Algorithm.
Write HTML, CSS and/or JavaScript code in a file or series of files.
Which of these job duties would an Applications Programmer perform?
Create and Manage User Accounts on Windows Server using an Active Directory Domain.
Troubleshooting user computing issues via telephone, chat or email.
Write source code with a programming language like Java by analyzing an Algorithm.
Write HTML, CSS and/or JavaScript code in a file or series of files.
Which of these job duties would a Network Administrator perform?
Create and Manage User Accounts on Windows Server using an Active Directory Domain.
Troubleshooting user computing issues via telephone, chat or email.
Write source code with a programming language like Java by analyzing an Algorithm.
Write HTML, CSS and/or JavaScript code in a file or series of files.
Which of these job duties would a Helpdesk Technician perform?
Create and Manage User Accounts on Windows Server using an Active Directory Domain.
Troubleshooting user computing issues via telephone, chat or email.
Write source code with a programming language like Java by analyzing an Algorithm.
Write HTML, CSS and/or JavaScript code in a file or series of files.
What is the smallest integer-based data type that can be assigned to a variable if its value can be as large as 1,000?
byte. 1 byte. Integers in the range of -128 to +127
short. 2 bytes. Integers in the range of -32,768 to +32,767
int. 4 bytes. Integers in the range of -2,147,483,648 to +2,147,483,647
long. 8 bytes. Integers in the range of -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
int
byte
short
long
What is the smallest integer-based data type that can be assigned to a variable if its value can be as large as 100?
byte. 1 byte. Integers in the range of -128 to +127
short. 2 bytes. Integers in the range of -32,768 to +32,767
int. 4 bytes. Integers in the range of -2,147,483,648 to +2,147,483,647
long. 8 bytes. Integers in the range of -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
int
byte
short
long
What is the smallest integer-based data type that can be assigned to a variable if its value can be as large as 50,000?
byte. 1 byte. Integers in the range of -128 to +127
short. 2 bytes. Integers in the range of -32,768 to +32,767
int. 4 bytes. Integers in the range of -2,147,483,648 to +2,147,483,647
long. 8 bytes. Integers in the range of -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
int
byte
short
long
What is the smallest integer-based data type that can be assigned to a variable if its value can be as large as 3,000,000,000,000?
byte. 1 byte. Integers in the range of -128 to +127
short. 2 bytes. Integers in the range of -32,768 to +32,767
int. 4 bytes. Integers in the range of -2,147,483,648 to +2,147,483,647
long. 8 bytes. Integers in the range of -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
int
byte
short
long
A computer contains several types of primary and secondary memory, such as Registers, Cache, RAM, BIOS ROM and SSD. Look at the image presented here of a typical CPU architecture, including internal and external memory components.
What is true about RAM memory?
Its closest to the Arithmetic Logic Unit compared to other memory.
Its furthest from the Control Unit compared to other memory.
It's further from the Arithmetic Logic Unit than the GPU, but closer than Cache.
It's further from the Arithmetic Logic Unit than Cache, but closer than BIOS.
A computer contains several types of primary and secondary memory, such as Registers, Cache, RAM, BIOS ROM and SSD. Look at the image presented here of a typical CPU architecture, including internal and external memory components.
What is true about SSD memory?
Its closest to the Arithmetic Logic Unit compared to other memory.
Its furthest from the Control Unit compared to other memory.
It's further from the Arithmetic Logic Unit than the GPU, but closer than Cache.
It's further from the Arithmetic Logic Unit than Cache, but closer than BIOS.
A computer contains several types of primary and secondary memory, such as Registers, Cache, RAM, BIOS ROM and SSD. Look at the image presented here of a typical CPU architecture, including internal and external memory components.
What is true about cache and register memory?
They are the closest to the Arithmetic Logic Unit and Control Unit compared to other memory.
They are furthest from the Control Unit and Arithmetic Logic Unit compared to other memory.
They are further from the Arithmetic Logic Unit and Control Unit than the RAM, but closer than the GPU.
They are further from the Arithmetic Logic Unit and Control Unit than the GPU, but closer than BIOS.
Why was Grace Hopper an important female historical figure in Computer Science?
She was one of few females working in Computer Science during WWII.
She was credited with coining the term, "Computer Bug".
She worked on the programming of the Harvard Mark I military weapons trajectory calculating computer.
She worked as a programmer on the Analytical and Difference Engines.
All of the above, except programming the Analytical and Difference Engines.
Why was Charles Babbage an important historical figure in Computer Science?
He was considered the father of modern day PCs.
He invented the concepts of the Difference Engine.
He invented the concepts of the Analytical Engine.
He invented the concepts of machines that would have their own storage and memory components, provisions for programming the device to automate tasks by providing it a set of instructions, and other concepts found in modern day PC hardware.
All of the above.
Why was Herman Hollerith an important historical figure in Computer Science?
He was considered the father of modern day PCs.
He invented a revolutionary census tabulating computer based on punch cards.
He left the US Census Bureau and founded the company known today as IBM.
He made the first mechanical binary programmable computer.
Just the two answer choices about inventing the revolutionary census tabulating computer and being the founder of the modern-day IBM corporation.
Why was Konrad Zuse an important historical figure in Computer Science?
He worked on the hardware of the WWII Weapons Trajectory Calculating Computer known as the Harvard Mark I.
He built the Eniac and Univac computer systems.
He was considered the Father of Modern Day PCs.
He made the first mechanical binary programmable computer.
All of the Above
True or False:
If you are making a program that contains a menu of 10 choices that the user can choose from, then you need to use a programming structure that can perform multiple-choice decision making. Since If and If/Else statements are primarily binary decision making structures, it would be best to use a Switch to accomplish this, as it can have an unlimited number of case paths.
True
False
True or False:
An array's data values can only be accessed by index positions that are integer-based. Indices cannot be specified as Strings, Booleans, Doubles or any other non-integer data types.
True
False
True or False:
An if statement's condition test MUST include the == Equality Operator if you are testing for an exact equality match. It specifically cannot be based on the = Assignment Operator, or the logic of the decision structure will fail since this causes it to always take the true path even when it should be taking the false path.
True
False
