CSC 130

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the name of the utility that formats comments into a set of documents that you can view in a Web browser? Select one: a. javadoc b. javac c. javad d. java

A

What is the result of evaluating the following expression? (45 / 6) % 5 Select one: a. 2 b. 7 c. 2.5 d. 3

A

What term is used to refer to a sequence of characters enclosed in quotation marks? Select one: a. string b. object c. comment d. method

A

What term is used to refer to an instruction in a method? Select one: a. statement b. constant c. comment d. object

A

When you declare a method, you also need to provide the method _______________________, which consists of statements that are executed when the method is called. Select one: a. body b. header c. return type d. access specifier

A

Which of the following options is a legally correct expression for inverting a condition? Select one: a. if (!(a == 10)) b. if (!a == 10) c. if (a !== 10) d. if (a ! 10)

A

Which operator constructs object instances? Select one: a. new b. instanceof c. void d. construct

A

When was Java officially introduced? Select one: a. 1989 b. 1995 c. 2005 d. 2000

B

Which of the following expressions represents a legal way of checking whether a value assigned to the num variable falls in the range 100 to 200? Select one: a. if (num >= 200 && num <= 100) b. if (num >= 100 && num <= 200) c. if (num >= 100 || num <= 200) d. if (num >= 200 || num <= 100)

B

What is the correct order of the steps in the program development process: i. Develop and describe the algorithm ii. Translate the algorithm into Java. iii. Understand the problem. iv. Compile and test the program. v. Test the algorithm with different inputs. Select one: a. i, ii, iii, iv,v b. i, ii, iv, v, iii c. iii, i, v, ii,iv d. i, iii, v, ii, iv

C

What is the value of Math.abs(-2)? Select one: a. -2 b. 0 c. 2 d. 4

C

What is the value of the following expression? 3 x 5 / 2 x 5 Select one: a. 1.5 b. 30 c. 35 d. 37.5

C

Which is the Java equivalent of the following mathematical expression? c = √(a^2 + b^2) Select one: a. c = Math.sqrt(a x 2 + b x 2); b. c = Math.sqrt(a x 2) + Math.sqrt(b x 2); c. c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); d. c = Math.sqrt(Math.pow(a, 2)) + Math.sqrt(Math.pow(b, 2));

C

Which of the following is a mutator method for the Udacity Rectangle class? Select one: a. getHeight b. toString c. translate d. getY

C

Which of the following statements about objects is correct? Select one: a. An object defines the methods for a class. b. Every object is a sequence of instructions. c. Every object belongs to a class. d. All entities, even numbers, are objects.

C

Which of the following statements is correct about constants? Select one: a. Constants are written using capital letters because the compiler ignores constants declared in small letters. b. The data stored inside a constant can be changed using an assignment statement. c. You can make a variable constant by using the final reserved word when declaring it. d. Constant variables can only be changed through the Math library.

C

Choose the method header that goes with this method comment. /** * Raises the salary of the employee * @param percentRaise salary percentage raise */ Select one: a. public void raiseSalary(double percent) b. public double raiseSalary(double percent) c. public double raiseSalary(double percentRaise) d. public void raiseSalary(double percentRaise)

D

Evaluate the given pseudocode to calculate the efficiency of a vehicle's fuel consumption using the following test values: The trip odometer reading (odometer) = 300 The amount to fill the gas tank (amount) = 15 input odometer input amount output odometer / amount What is the final output? Select one: a. 15 b. 10 c. 30 d. 20

D

How do you compute the length of the string str? Select one: a. length(str) b. length.str c. str.length d. str.length()

D

What is the output of the following code snippet? int s1 = 20; if (s1 <= 20) { System.out.print("1"); } if (s1 <= 40) { System.out.print("2"); } if (s1 <= 20) { System.out.print("3"); } Select one: a. 1 b. 2 c. 3 d. 123

D

What is the output of the following code snippet? public static void main(String[] args) { int var1 = 10; int var2 = 2; int var3 = 20; var3 = var3 / (var1 % var2); System.out.println(var3); } Select one: a. 0 b. 4 c. 20 d. There will be no output due to a run-time error.

D

What is the purpose of the assignment operator (=)? Select one: a. to check for inequality b. to check for identity c. to check for equality d. to change the value of a variable

D

An instance variable declaration consists of which of the following parts? Select one: a. the return type, the name of the method, and a list of the parameters (if any). b. an access specifier, the type of the instance variable, and the name of the instance variable. c. an access specifier, a list of the parameters (if any), and the body of the method. d. the type of the instance variable, an access specifier, a list of the parameters (if any),and the body of the method.

B

Assume the following variable has been declared and given a value as shown: String str = "0123456789"; Which is the value of str.length()? Select one: a. 9 b. 10 c. 11 d. 12

B

Documentation ______________________ can be used to describe the classes and public methods of programs. Select one: a. components b. comments c. constants d. commands

B

Private instance variables ____________________. Select one: a. can only be accessed by methods of a different class. b. can only be accessed by methods of the same class. c. cannot be accessed by methods of the same class. d. can only be accessed by the constructor of the class.

B

The name of the constructor is always the same as the name of the ________________. Select one: a. access specifier b. class c. instance variable d. parameter variable

B

The two strings "Aardvark" and "Aardvandermeer" are exactly the same up to the first six letters. What is their correct lexicographical ordering? Select one: a. They cannot be compared lexicographically unless they are the same length b. "Aardvandermeer" is first, then "Aardvark" c. "Aardvark" is first, then "Aardvandermeer" d. The shorter word is always first

B

What are the values of num1 and num2 after this snippet executes? double num1 = 4.20; double num2 = num1 * 10 + 5.0; Select one: a. num1 = 4.20 and num2 = 42.0 b. num1 = 4.20 and num2 = 47.0 c. num1 = 42.0 and num2 = 42.0 d. num1 = 42.0 and num2 = 47.0

B

What is the name of the = operator in Java? Select one: a. inequality b. assignment c. identity d. equality

B

Assume that the variable count has been declared as type int. Which statement adds 10 to count? Select one: a. count = 10; b. count == count + 10; c. count = count + 10; d. count + 10;

C

Assuming that the user inputs a value of 25 for the price and 10 for the discount rate in the following code snippet, what is the output? public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter the price: "); double price = in.nextDouble(); System.out.print("Enter the discount rate: "); double discount = in.nextDouble(); System.out.println("The new price is " + price - price * (discount / 100.0)); } Select one: a. The new price is 25 b. The new price is 15 c. The new price is 22.5 d. The new price is 20.0

C

By convention, variables begin with a(n) ______________________. Select one: a. uppercase letter b. digit c. lowercase letter d. dollar sign

C

Given this method implementation, fill in the blank in the method comment. /** * Gets the current balance of the bank account * _____________________ the current balance */ pubic double getBalance() { return balance; } Select one: a. return b. double c. @return d. balance

C

In an airline reservation system, the number of available seats in an airplane is required. Which data type should be used to store this value? Select one: a. double b. float c. int d. long

C

What does an object store data in? Select one: a. files b. methods c. instance variables d. access specifiers

C

What is an object? Select one: a. A sequence of instructions. b. Any value stored in a variable. c. An entity in your program that is manipulated by calling methods. d. Any input to a method.

C

Which statement best describes a computer program? Select one: a. A program is a sequence of comments. b. A program can decide what task it is to perform. c. A program is a sequence of instructions and decisions that the computer carries out. d. A program can only perform one simple task.

C

You should provide documentation comments for __________________________. Select one: a. only classes b. only methods with parameters c. every class, every method, every parameter, and every return value d. only methods with return values

C

What is the output of the following code snippet? System.out.printf("%5.3f", 20.0); Select one: a. 20 b. 20.0 c. 20.00 d. 20.000

D

A method header consists of which of the following parts? Select one: a. the return type, the name of the method, and a list of the parameters (if any) b. an access specifier, the type of the instance variable, and the name of the instance variable c. the type of the instance variable, an access specifier, and a list of the parameters (if any) d. an access specifier, a return type, a method name, and list of the parameters (if any)

D

A set of values and the operations that can be carried out with those values are called ____________. Select one: a. literals b. numbers c. values d. types

D

By convention, classes begin with a(n) ________________. Select one: a. lowercase letter b. dollar sign c. digit d. uppercase letter

D

Suppose a phone number, stored as a ten-character string (of digits only) called phoneNumber must be converted into a string that has parentheses around the area code. Which statement below will do that? Select one: a. String newNumber = "(" + phoneNumber.substring(3, 0) + ")"; b. String newNumber = "(" + ")" + phoneNumber; c. String newNumber = "(" + phoneNumber.substring(1, 3) + ")" + phoneNumber.substring(3, 7); d. String newNumber = "(" + phoneNumber.substring(0, 3) + ")" + phoneNumber.substring(3, 10);

D

Suppose one needs an if statement to check whether an integer variable pitch is equal to 440 (which is the frequency of the note "A" to which strings and orchestras tune). Which condition is correct? Select one: a. if (pitch - 440 = 0) b. if ((pitch !< 440) && (pitch !> 440)) c. if (pitch = 440) d. if (pitch == 440)

D

The output of a method is called its ____________________ value. Select one: a. implicit b. explicit c. parameter d. return

D

To use a class in another package you need to ___________ it. Select one: a. export b. overload c. rewrite d. import

D

What does API stand for? Select one: a. Applet Programming Interface b. Application Programmer Interaction c. Application Programming Instance d. Application Programming Interface

D

What does the following statement sequence print? String str = "Harry"; int n = str.length(); String mystery = str.substring(0, 1) + str.substring(n - 2, n); System.out.println(mystery); Select one: a. Ha b. Har c. Hy d. Hry

D

What kind of operator is the <= operator? Select one: a. Ternary b. Arithmetic c. Inequality d. Relational

D

What statement is used to specify the value that a method gives back to its caller? Select one: a. new b. public c. private d. return

D

Which of the following conditions is true only when the integer variable number is even? Select one: a. number / 2 == 0 b. number > 2 c. number / 2 > 1 d. number % 2 == 0

D

Which one of the following memory types provides storage that persists without electricity? Select one: a. primary storage b. RAM c. memory d. secondary memory

D

You should declare all instance variables as ________________________. Select one: a. protected b. class c. public d. private

D

A class declaration consists of which of the following parts? Select one: a. an access specifier, the keyword class, the name of the class, declaration of instance variables, constructors, and methods. b. an access specifier, a return type, a method name, a list of parameters (if any), and the body of the method. c. the keyword class, the name of the class, declarations for instance variables, constructors and methods. d. an access specifier, the name of the class, a list of the parameters (if any), and the body of the constructor.

A

A company applies a discount based on the size of the order. If the order is over $50, the discount is 5%. If the order is over $100, the discount is 10%. Otherwise, there is no discount. If the integer variable order contains the size of the order, which of the following will assign the double variable discount the correct value? Select one: a. if (order > 100) discount = 0.10; else if (order > 50) discount = 0.05; else discount = 0; b. if (order > 100) discount = 0.10; if (order > 50) discount = 0.05; else discount = 0; c. if (order > 100) discount = 0.10; if (order > 50) discount = 0.05; if (order <= 50) discount = 0; d. if (order > 50) discount = 0.05; else if (order > 100) discount = 0.10; else discount = 0;

A

Assume the following variable has been declared and given values as shown: String name = "Mamey, Jean"; Which statement will print the name as "Jean Mamey"? Select one: a. System.out.print(name.substring(7) + " " + name.substring(0, 5)); b. System.out.print(name.substring(8, 4) + " " + name.substring(1, 5)); c. System.out.print(name.substring(8) + " " + name.substring(1, 4)); d. System.out.print(name.substring(2) + " " + name.substring(1));

A

Assume the following variables have been declared and given values as shown: String str = "0123456789"; String sub = str.substring(3, 4); Which is the value of sub? Select one: a. 3 b. 34 c. 345 d. 3456

A

Assume the following variables have been declared and given values elsewhere: boolean completedProject; int programsDone; double classPercentage; A student will pass programming class if and only if they have a percentage of 70.0% or higher and have either completed the project or they have done 5 or more programs. Which of the following statements assigns the Boolean variable passProgramming correctly? Select one: a. passProgramming = (classPercentage >= 0.7) && (programsDone >= 5 || completedProject); b. passProgramming = (classPercentage >= 0.7) && (programsDone >= 5) && (completedProject); c. passProgramming = (classPercentage >= 0.7) || (programsDone >= 5) || (completedProject); d. passProgramming = ((classPercentage >= 0.7) && (programsDone >= 5 )) && completedProject;

A

Assuming that the user provides 99 as input, what is the output of the following code snippet? int a; int b; Scanner in = new Scanner(System.in); System.out.print("Please enter a number: "); b = in.nextInt(); if (b > 300) { a = b; } else { a = 0; } System.out.println("a: " + a); Select one: a. a: 0 b. a: 99 c. a: 100 d. a: 300

A

Consider the following code snippet. What is the potential problem with the if statement? double average; average = (g1 + g2 + g3 + g4) / 4.0; if (average == 90.0) { System.out.println("You earned an A in the class!"); } Select one: a. Using == to test the double variable average for equality is error-prone. b. The conditional will not evaluate to a Boolean value. c. The assignment operator should not be used within an if-statement conditional. d. Literals should never be used in if statement conditionals.

A

Fill in the blank in the following method comment. /** Deposits money into the bank account @param _______________ the amount to deposit */ public void deposit(double amount) { balance = balance - amount; } Select one: a. amount b. balance c. deposit d. money

A

Information hiding makes it simpler for the implementor of a class to _______________________. Select one: a. change the private implementation b. change the method headers c. change the name of the class d. change the public interface

A

The public constructors and methods of a class form the public ___________ of the class. Select one: a. interface b. initialization c. implementation d. encapsulation

A

What are the two parts of an if statement? Select one: a. A condition and a body b. A check and an increment c. An increment and a body d. An increment and a return value

A

What is the name of the type that denotes floating-point numbers that can have fractional parts? Select one: a. double b. floatingPoint c. int d. integer

A

Which of the following corresponds to a valid constructor header for the Player class? Select one: a. public Player() b. private Player() c. public void Player() d. private void Player()

A

Which of the following declares a variable that will store a welcome message? Select one: a. String welcome; b. double welcome; c. Char welcome; d. int welcome;

A

Which of the following statements about methods is correct? Select one: a. A method is a sequence of instructions that accesses the data of an object. b. A method name is unique across the entire program. c. A method can be called on any object in any class. d. Methods are stored in variables.

A

Which of the following statements about test programs is true? Select one: a. Test programs verify that methods have been implemented correctly. b. A tester class does not contain the main method. c. You do not have to display the expected results. d. Writing test programs is not an important skill.

A

Assume the following variables have been declared and given values as shown: int i = 2345; double m = 67.8; What will be printed by the statement below? System.out.printf("Values are %10d and %7.2f", i, m); Select one: a. Values are 2345 and 67.8 b. Values are 2345 and 67.80 c. Values are %10d and %7.2f 2345 67.8 d. Values are %10d and %7.2f i j

B

Assuming that the user inputs "Joe" at the prompt, what is the output of the following code snippet? public static void main(String[] args) { System.out.print("Enter your name "); String name; Scanner in = new Scanner(System.in); name = in.next(); name += ", Good morning"; System.out.print(name); } Select one: a. The code snippet does not compile because the += operator cannot be used in this context. b. Joe, Good morning c. , Good morning d. Joe

B

Consider the following division statements: I. 22 / 7 II. 22.0 / 7 III. 22 / 7.0 Which of the following is correct? Select one: a. All three statements will return an integer value. b. Only I will return an integer value. c. Only I, II will return an integer value. d. Only I and III will return an integer value.

B

What happens to the fractional part when a division is performed on two integer variables? Select one: a. The fractional part is rounded off to the nearest integer value. b. The fractional part is discarded. c. Two integers cannot be used in division; at least one of the operands should be a floating-point number. d. Instead of using an integer division, you should use the modulus operator to perform floating-point division.

B

What is another term used to describe an error causing a program to take an action that the programmer did not intend? Select one: a. syntax error b. logic error c. mistake d. compile-time error

B

What is the name of the file that contains Java source code for the class BankAccount? Select one: a. BankAccount b. BankAccount.java c. BankAccount.class d. BankAccount.txt

B

What is the name of the type that denotes whole numbers? Select one: a. double b. int c. whole d. integer

B

What is the output of the following code snippet? final int MIN_SPEED = 45; final int MAX_SPEED = 65; int speed = 55; if (!(speed < MAX_SPEED)) { speed = speed - 10; } if (!(speed > MIN_SPEED)) { speed = speed + 10; } System.out.println(speed); Select one: a. 45 b. 55 c. 65 d. 50

B

What is the process of hiding object data and providing methods for data access called? Select one: a. documentation b. encapsulation c. instantiation d. abstraction

B

What is the result of the following expression? double d = 2.5 + 4 x -1.5 - (2.5 + 4) x -1.5; Select one: a. 24.375 b. 6.25 c. 12.375 d. 6

B

What is the term used to describe an error detected by the compiler that is a violation of the programming language rules? Select one: a. logic error b. compile-time error c. run-time error d. typo

B

Which of the following declares a variable that will store a measurement with fractional parts? Select one: a. int measure; b. double measure; c. String measure; d. integer measure;

B

Which statement best describes the portability characteristic of Java? Select one: a. It is easy to copy Java source code from one machine to another. b. The same Java class files will run on different operating systems without change. c. It is easy to compile Java source code on different operating systems. d. It is easy to change a Java program so that it will work on different operating systems.

B

What is the declared return type for a method that does not have a return value? Select one: a. String b. There is no declared return type when a method does not return a value. c. void d. A method must return a value.

C

What is the output after running the following code snippet? int number = 600; if (number < 200) { System.out.println("Low spender"); } else if (number < 500) { System.out.println("Spending in moderation"); } else if (number < 1000) { System.out.println("Above average!"); } else { System.out.println("High Roller!"); } Select one: a. Low spender b. Spending in moderation c. Above average! d. High Roller!

C

What is the output of the following code snippet? public static void main(String[] args) { double a; a = Math.sqrt(9.0) + Math.sqrt(16.0); System.out.println(a); } Select one: a. 25.0 b. 337.0 c. 7.0 d. 19.0

C

What is the purpose of the following algorithm? num = 0; repeat the following steps for 10 times input var1 if var1 > num then num = var1 end of if end of repeat print num Select one: a. To print out the 10 numbers b. To search for a particular number among 10 numbers c. To find the highest among 10 numbers d. To find the smallest among 10 numbers

C

What term is used to refer to a sequence of steps for solving a problem that is unambiguous, executable, and terminating? Select one: a. documentation b. pseudoprogram c. algorithm d. comments

C

What term is used to refer to information passed in to a method on a call? Select one: a. class b. object c. parameter d. comment

C

What translates high level descriptions into machine code? Select one: a. interpreter b. assembler c. compiler d. linker

C

Which of the following statements will assign the largest value of three integer variables a, b, and c to the integer variable maximum? Select one: a. maximum = Math.max(a, b, c); b. maximum = Math.max(a, b); maximum = Math.max(b, c); maximum = Math.max(a, c); c. maximum = Math.max(a, b); maximum = Math.max(maximum, c); d. maximum = Math.max(a, b) + Math.max(b, c) + Math.max(a, c);

C

Assuming that a user enters 5 as the age, what is the output of the following code snippet? int age = 0; Scanner in = new Scanner(System.in); System.out.print("Please enter your age: "); age = in.nextInt(); if (age < 10) { System.out.println("Kid"); } if (age < 30) { System.out.print("Young"); } if (age < 70) { System.out.print("Aged"); } if (age < 100) { System.out.print("Old"); } Select one: a. Kid b. Kid Young c. Kid YoungAged d. Kid YoungAgedOld

D

Assuming that the user enters 23 and 45 as inputs for num1 and num2, respectively, what is the output of the following code snippet? public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); String num1 = in.next(); System.out.print("Enter another number: "); String num2 = in.next(); System.out.println(num1 + num2); } Select one: a. 23 b. 4523 c. 68 d. 2345

D

How do you extract the first 5 characters from the string str? Select one: a. substring(str, 5) b. substring.str(0,5) c. str.substring(5) d. str.substring(0,5)

D

If greeting is a String object, which method call is incorrect? Select one: a. greeting.length(); b. greeting.toLowerCase(); c. greeting.toUpperCase(); d. greeting.println();

D

In Java, every statement must end with this symbol. Select one: a. . b. ) c. ! d. ;

D

What is a Java library? Select one: a. A collection of Java source code that has been programmed and can be reused. b. A collection of books in Java. c. A collection of electronic documentation in Java. d. A collection of code that has been programmed and translated by someone else, ready for you to use in your program.

D

What is a storage location in the computer's memory called that has a type, name, and contents? Select one: a. identifier b. literal c. label d. variable

D

What is a tester class? Select one: a. A class that constructs objects. b. A class that invokes one or more methods. c. A class that is named Tester. d. A class with a main method that contains statements to run methods of another class.

D

What is the correct way to invoke methods on variables in Java that are strings? Select one: a. Methods can only be invoked on string constants, not on variables. b. For each method there is a special operator that must be used. c. There are no methods available in Java for string variables. d. Invoke them using the variable name and the dot (.) notation.

D

What is the name of the type that denotes a string of characters? Select one: a. charString b. Characters c. char d. String

D

What is the output of the following Java statement? System.out.println("4 + 6"); Select one: a. 10 b. 6 c. 4 d. 4 + 6

D

Which statement is true about a Java program? Select one: a. Java forces the programmer to use a particular layout for readability. b. Java requires that at most one statement appear on one line. c. The first method that is executed in a Java program is called Main. d. Java is case sensitive.

D

Which statement is true about the following Java statement: System.out.Println("Welcome!"); Select one: a. There are multiple errors. b. There are no errors. c. There is a run-time error. d. There is a compile-time error.

D


Conjuntos de estudio relacionados

American Literature: The Literary Realism Movement

View Set

Study Guide Accounting Principles 1 Ch. 3&4

View Set

История Казахстана. ИА

View Set

4 - Life Insurance Premiums, Proceeds and Beneficiaries.

View Set

Chapter 56: Managements of Patients with Dermatologic Problems

View Set