COP 2800 Midterm

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Another term for an object of a class is a(n) access specifier instance member method

instance

Which of the following is a value that is written into the code of a program? a literal an assignment statement an operator a variable

a literal

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase =100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01; 0.0 0.05 0.03 0.01

0.0

Methods that operate on an object's fields are called instance methods instance variables private methods public methods

instance methods

Java requires that the boolean expression being tested by an if statement be enclosed in a set of parentheses a set of braces a set of double quotes a set of brackets

a set of parentheses

Which of the following is a named storage location in the computer's memory? a literal an operator a constant a variable

a variable

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = 0.05; else discountRate = 0.04; else if (purchase > 750) if (cust == 'Y') discountRate = 0.04; else discountRate = 0.03; else discountRate = 0.0; 0.0 0.04 0.05 0.03

0.04

How many times will the following do-while loop be executed? int x = 11; do{ x += 20; } while (x > 100); 0 1 5 4

1

What will be the value of x after the following code is executed? int x, y = 15; x = y--; 14 16 0 15

15

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100){ x += y; y += 20; } 130 210 110 90

210

What will be displayed after the following statements are executed? int y = 10; if (y == 10){ int x = 30; x += y; System.out.println(x); } 40 30 20 The code contains an error and will not compile.

40

Which of the following expressions will determine whether x is less than or equal to y? x <= y x => y x >= y x =< y

x <= y

How many times will the following do-while loop be executed? int x = 11; do{ x += 20; } while (x <= 100); 5 4 3 1

5

What is the result of the following expression? 10 + 5 * 3 - 20 -5 -50 5 25

5

In all but very rare cases, loops must contain, within themselves nested loops a way to terminate arithmetic operators nested decision strucures

a way to terminate

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x); 8.25 4 0 8.0

8.0

The variable used to keep a running total in a loop is called a(n) __________. accumulator sentinel summation integer

accumulator

A loop that repeats a specific number of times is known as a(n) count-controlled infinite conditional pretest

count-controlled

A Java source file must be saved with the extension .java .javac .src .class

.java

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%? "##0.0%" "###.##%" "000.0%" "#0.00%"

"##0.0%"

If you want to use the System.out.printf method to print a string argument , use the __________ format specifier. %d %b %f %s

%s

Which of the following is not a valid Java comment? /** Comment one */ */ Comment two /* // Comment three /* Comment four */

*/ Comment two /*

Which of the following statements opens a file named MyFile.txt and allows you to read data from it? Scanner inputFile = new Scanner("MyFile.txt"); File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); File Scanner = new File("MyFile.txt"); PrintWriter inputFile = new PrintWriter("MyFile.txt");

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents? FileWriter fwriter = new FileWriter("MyFile.txt"); PrintWriter outFile = new PrintWriter(fwriter); FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter); PrintWriter outfile = new PrintWriter("MyFile.txt", true); PrintWriter outfile = new PrintWriter(true, "MyFile.txt");

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

A(n) __________ is a dialog box that prompts the user for input. input box user prompt adaptive dialog input dialog

input dialog

__________ refers to the physical components that a computer is made of. Control unit Main memory Hardware Input

Hardware

What does the following code do? Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrintWriter outFile = new PrintWriter(filename); It writes to a file named filename. It allows the user to enter the name of the file that data will be written to. It establishes a connection with a file named filename. Nothing; the code contains a syntax error.

It allows the user to enter the name of the file that data will be written to.

What would be displayed as a result of executing the following code? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y) x = 22, y = 26 x = 22, y = 4 x = 22, y = 88 Nothing. There is an error in the code.

Nothing. There is an error in the code.

Computers can do many different jobs because they are automated reliable electronic programmable

Programmable

Which of the following statements correctly creates a Scanner object for keyboard input? Scanner kbd = new Scanner(System.keyboard); Scanner keyboard = new Scanner(System.in); Scanner keyboard(System.in); Keyboard scanner = new Keyboard(System.in);

Scanner keyboard = new Scanner(System.in);

Enclosing a group of statements inside a set of braces creates an expression a block of statements a relational operator a conditional statement

a block of statements

What will be displayed after the following statements are executed? int x = 65; int y = 55; if (x >= y){ int ans = x + y; } System.out.println(ans); 10 120 100 The code contains an error and will not compile.

The code contains an error and will not compile.

What will be the value of ans after the following statements are executed? int x = 40; int y = 40; if (x = y) ans = x + 10; 30 80 50 The code contains an error and will not compile.

The code contains an error and will not compile.

For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; } The z field is available to code written outside the Sphere class. The radius field is not available to code written outside the Sphere class. The radius, x, y, and z fields are members of the Sphere class. The x field is available to code that is written outside the Sphere class.

The z field is available to code written outside the Sphere class.

Application software refers to programs that make the computer useful to the user. True False

True

Compiled byte code is also called source code True False

True

Encapsulation refers to the combining of data and code into a single object. True False

True

Logical errors are mistakes that cause the program to produce erroneous results True False

True

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application? Describe the problem domain. Write the code. Refine the list of nouns to include only those relevant to the problem. Identify all the nouns.

Write the code.

What is the following statement an example of? import java.util.Scanner; an explicit import statement an unconditional import statement a wildcard import statement a conditional import statement

an explicit import statement

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; } ans = 60, x = 0, and y = 50 ans = 45, x = 50, and y = 0 ans = 45, x = 50, and y = 50 ans = 60, x = 50, and y = 100

ans = 60, x = 0, and y = 50

If you do not provide initialization values for a class's numeric fields, they will cause a runtime error contain an unknown value be automatically initialized to 0 cause a compiler error

be automatically initialized to 0

After the header, the body of the method appears inside a set of braces, { } parentheses, ( ) brackets, [ ] double quotes, " "

braces, { }

One or more objects may be created from a(n) field method instance class

class

A Java program must have at least one of the following: a comment a class definition a System.out.println(); statement a variable declaration

class definition

The __________ loop is ideal in situations where you always want the loop to iterate at least once. for while do-while posttest

do-while

Which of the following statements is invalid? double r = 9.4632E15; double r = 9.4632e15; double r = 2.9X106; double r = 326.75;

double r = 2.9X106;

Variables of the boolean data type are useful for evaluating conditions that are either true or false working with small integers working with very large integers evaluating scientific notation

evaluating conditions that are either true or false

It is common practice in object-oriented programming to make all of a class's fields private methods private fields public fields and methods public

fields private

The __________ statement is used to create a decision structure which allows a program to have more than one path of execution. block if null flag

if

Which is the key word used to import a class? import assume use link

import

You should not define a class that is dependent on the values of other class fields in order to keep it current because it is redundant in order to avoid having stale data because it should be defined in another class

in order to avoid having stale data

If a loop does not contain, within itself, a valid way to terminate, it is called a(n) __________ loop for while do-while infinite

infinite

Validating the results of a program is important to correct runtime errors make sure the program solves the original problem create a model of the program correct syntax error

make sure the program solves the original problem

A(n) __________ is a software entity that contains data and procedures. method class object program

object

Using the blueprint/house analogy, you can think of a class as a blueprint that describes a house and __________ as instances of the house built from the blueprint. methods fields objects attributes

objects

A __________ loop will always be executed at least once. pretest posttest conditional user-controlled

posttest

While __________ is centered on creating procedures, __________ is centered on creating objects. procedural programming, object-oriented programming object-oriented programming, procedural programming routine programming, method programming procedural programming, class programming

procedural programming, object-oriented programming

A cross between human language and a programming language is called the Java Virtual Machine the Java language pseudocode a compiler

pseudocode

__________ operators are used to determine whether a specific relationship exists between two values. Assignment Arithmetic Logical Relational

relational

The end of a Java statement is indicated by a ________. asterisk (*) colon (:) semicolon (;) bracket (})

semicolon (;)

Before entering a loop to compute a running total, the program should first set the accumulator variable to an initial value, often zero set all variables to zero read all the values into main memory know exactly how many values there are to total

set the accumulator variable to an initial value, often zero

Character literals are enclosed in __________ and string literals are enclosed in __________. single quotes, double quotes double quotes, single quotes single quotes, single quotes double quotes, double quotes

single quotes, double quotes

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal? true or false str1 = str2 str1 && str2 str1.equals(str2) str1 += str2

str1.equals(str2)

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2? str1.equalsIgnoreCase(str2) str1.equalsInsensitive(str2) str1 != str2 str1 || str2

str1.equalsIgnoreCase(str2)

Which of the following statements will correctly convert the data type, if x is a float and y is a double? x = float y; x = y; x = (float)y; x = y;

x = (float)y;

Variables are symbolic names made up by the programmer that represent memory locations operators that perform operations on one or more operands reserved words symbolic names made up by the programmer and once created, their values cannot be changed

symbolic names made up by the programmer that represent memory locations

In general, there are two types of files which are encrypted and unencrypted delimited and unlimited text and binary static and dynamic

text and binary

Which of the following is the method you can use to determine whether a file exists? the File class's canOpen method the Scanner class's exists method the File class's exists method the PrintWriter class's fileExists method

the File class's exists method

In the following Java statement, what value is stored in the variable name? String name = "John Doe"; "name" the memory address where "John Doe" is located the memory address where name is located John Doe

the memory address where "John Doe" is located

The scope of a local variable is inside the parentheses of a method header the method in which it is defined inside the class but not inside any method the entire class

the method in which it is defined

When an argument is passed by value the parameter variable holds the address of the argument the parameter variable cannot be changed the parameter variable holds a copy of the value passed to it changes can be made to the argument variable

the parameter variable cannot be changed

Application software refers to key words the operating system pseudocode the programs that make the computer useful to the user

the programs that make the computer useful to the user

A solid-state drive has no moving parts and operates faster than a traditional disk drive. True False

true

A flag may have the values defined or undefined true or false of any range of integers of any Unicode character

true or false

When a character is stored in memory, it is actually the __________ that is stored. Unicode number ASCII code floating-point value letter, symbol, or number

unicode number

Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by using the public access specifier on the class methods using the private access specifier on the class methods using the private access specifier on the class fields using the private access specifier on the class definition

using the private access specifier on the class fields

Key words are words or characters representing values that are defined by the programmer the data names in your program symbols or words that perform operations on one or more operands words that have a special meaning in the programming language

words that have a special meaning in the programming language


Ensembles d'études connexes

Network+ N10-006 (Question Set #5)

View Set

Network Defense Mid Term Study Guide

View Set

Software Testing Interview Questions And Answers

View Set

Chapter 3: Exploring Global Business

View Set

Principles of Finance- Chapter 7

View Set

高職龍騰英文 B3 (B版) L1 It's in Our Blood 單字&片語

View Set