CS1440 - Exam 1

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

(T / F) The if-else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.

True

(T / F) The java.lang package is automatically imported into all Java programs.

True

(T/ F) If you use a flag in a format specifier, you must write the flag before the field width and the precision.

True

(T/ F) Named constants are initialized with a value and that value cannot change during the execution of the program.

True

(T/ F) The Java API provides a class named Math that contains numerous methods which are useful for performing complex mathematical operations.

True

When a character is stored in memory, it is actually the __________ that is stored. a. Unicode number b. memory address c. floating-point value d. letter, symbol, or number

a.

When an object is created, the attributes associated with the object are called: a. instance fields b. class instances c. instance methods d. fixed attributes

a.

A __________ is a boolean variable that signals when some condition exists in the program. a. sentinel b. flag c. block d. case

b.

A group of related classes is called a(n): a. archive b. package c. collection d. attachment

b.

In the following Java statement, what value is stored in the variable name? String Name = "John Doe"; a. "name" b. the memory address where "John Doe" is located c. the memory address where name is located d. John DoeSd

b.

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

b.

The error in the following code is __________ switch (score) { case (score > 90): grade = 'A'; break; case(score > 80): grade = 'b'; break; case(score > 70): grade = 'C'; break; case (score > 60): grade = 'D'; break; default: grade = 'F'; }

greater than signs

(T / F) All it takes for an OR expression to be true is for one of the subexpressions to be true.

True

(T / F) Each instance of a class has its own set of instance fields.

True

Draw a UML diagram for the class, including the methods you have written

Book -title: String -author: String -publisher: String -copiesSold: int +Book(ti: String, au: String, pu: String, co: int) +getTitle(): String +getAuthor(): String +getPublisher(): String +getCopiesSold(): int +setTitle(ti:String):void +setAuthor(au:String):void +setPublisher(pu:String):void +setCopiesSold(co:int):void

(T / F) A method that gets a value from a class's field but does not change it is known as a mutator method.

False

(T / F) All it takes for an AND expression to be true is for one of the subexpressions to be true

False

(T / F) Both character and string literals can be assigned to a char variable.

False

(T / F) In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.

False

(T / F) The term "default constructor" is applied to the first constructor written by the author of the class.

False

(T / F) When two strings are compared using the String class's compareTo method, the comparison is not case sensitive.

False

The following statement should determine whether count is within the range of 0 through 100. What is wrong with it? ____________________________________ if (count >= 0 || count <= 100)

Not || signs, && signs instead

There are a number of syntax errors in the following program. Locate as many as you can. */ What's wrong with this program? /* public MyProgram { public static void main(String[] args); } Int a, b, c \\ Three integers a = 3 b = 4 c = a + b System.out.println('The value of c is' + C); {

Output: Line 1: comments mark Line 2: missing key word "class" Line 4: semi - colon Line 5: opening brace Line 6: comments mark Line 6, 7, 8, 9: semi - colon Line 10: double quote; capital "C"

Convert the following pseudocode to Java code. Be sure to define the appropriate variables. Store 172.5 in the force variable. Store 27.5 in the area variable. Divide area by force and store the result in the pressure variable. Display the contents of the pressure

Output: double force = 172.5; double area = 27.5; double pressure = force / area; System.out.print("The pressure is: " + pressure);

Please predict the output. double d = 12.9; int i = (int) d; System.out.println(i);

Output: 12

Write a program that generates a random integer within the range of 1 through 10. Then the program should display this number and its Roman numeral version. Java code:

Random r = new Random(); int n = r.nextInt(10) + 1; String s; switch (n); { case 1: s = "I"; break; case 2: s = "II" case 10: s = "x"; } System.out.println("The number is: " + n); System.out.println("The Roman number is: " + s);

(T / F) "Shadowing" is the term used to describe how the field name is hidden by the name of a local or parameter variable.

True

A Java source file must be saved with the extension ________ a. .java b. .javac c. .src d. .class

a.

What does the following UML diagram entry mean? + setHeight(h : double) : void a. a public method with a parameter of data type double that does not return a value b. a private field called setHeight that is a double data type c. a private method with no parameters that returns a double data type d. a public field called Height that is a double data type

a.

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; } a. ans = 60, x = 0, and y = 50 b. ans = 45, x = 50, and y = 0 c. ans = 45, x = 50, and y = 50 d. ans = 60, x = 50, and y = 100

a.

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

a.

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

a.

The following statement should determine whether x is not greater than 20. What is wrong with it? _________________________________________________ if (!x > 20)

after the ! needs to be parenthesis

A constructor is a method that __________ a. returns an object of the class b. never receives any arguments c. performs initialization or setup operations d. removes the object from memory

c.

Class objects normally have __________ that perform useful operations on their data, but primitive variables do not a. fields b. relationships c. methods d. instances

c.

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

d.

Which of the following expressions will generate a random number in the range of 1 through 10? a. myNumber = randomNumbers.nextInt(10); b. myNumber = randomNumbers.nextInt(1) + 10; c. myNumber = randomNumbers.nextInt(11) - 1; d. myNumber = randomNumbers.nextInt(10) + 1;

d.

Look at the following partial class definition, then respond to the questions that follow it: public class Book { private String title; private String author; private String publisher; private int copiesSold; } a. Write a constructor for this class. The constructor should accept an argument for each of the fields

public Book (String ti, String au, String pu, int co) { title = ti; author = au; publisher = pu; copiesSold = co; } public String getTitle () { return title; } public void setTitle(String ti) { title = ti; }

The error in the following code is __________ if (x == 1); y = 2; else if (x == 2); y = 3; else if (x == 3); y = 4;

the = sign


Ensembles d'études connexes

(7th) TCI Ch 28 - QUIZ - Florence

View Set

Chapter 7 - Trust, Justice, and Ethics

View Set

LifePac World History Unit 5:1 England and France

View Set

Social Pyschology 7- Social and Altruism

View Set

Practice T2, EAQ #6 Nursing Process/sexuality, N204 Practice Quizes, Fundamentals Quiz, Health and Physical Assessment, Leadership EAQ's, EAQ NCLEX, Maternity Chap 28, Maternity and Women's Health Nursing - Newborn, Nur 106- Module G2, Pediatric Grow...

View Set

Present Simple vs Present Continuous

View Set