IT 114 Midterm Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which XXX will prompt the user to enter a value greater than 10, until a value that is greater than 10 is actually input? There may be more than one answer. do { System.out.println("Enter a number greater than 10:"); userInput = scnr.nextInt(); } while XXX;

(!(userInput > 10))

A restaurant gives a discount for children under 10. They also give the discount for adults over 55. Which expression evaluates to true if a discount should be given?

(age < 10) || (age > 55)

Both must be true for a person to ride: (1) At least 5 years old, (2) Taller than 36 inches. Which expression evaluates to true if a person can ride?

(age >= 5) && (height > 36)

Which list correctly defines three parameters of type int, double, and String for createRecord()? public static void createRecord(. . .){};

(int num, double cost, String name)

What are the ways you can create a branch from the command line?

- git branch BranchName - git checkout -b BranchName

Which input value causes "Goodbye" to be output next? int x; x = scnr.nextInt(); while (x >= 0) { // Do something x = scnr.nextInt(); } System.out.println("Goodbye");

-1

What is the output? for (i = 0; i <= 10; ++i) { if (i == 6) continue; else System.out.print(i + " "); }

0 1 2 3 4 5 7 8 9 10

What possible values can x % 10 evaluate to? (x is an integer).

0..9

What is the output? j and k are ints. for (j = 0; j < 2; ++j) { for (k = 0; k < 4; ++k) { if (k == 2) { break; } System.out.print("" + j + k + " "); } }

00 01 10 11

How many items are returned from calcAverage()? public static int calcAverage(int a, int b, int c){. . .}

1

How many objects of type Car are created? Car mustang = new Car(); Car prius; int miles; Truck tundra = new Truck();

1

int x = 0; if(x == 0){ x++; } else if(x == 1){ x++; } else if(x == 2){ x++; } else{ x++; } System.out.println("x = " + x);

1

int x = 0; switch(x){ default: x = 1; break; } System.out.println("x = " + x);

1

What is y after executing the statements? x = 4; y = x + 1; x = 3; y = y * 2;

10

... float a = 1f; float b = 0f; for (int i = 0; i < 10; i++) { b += 0.1f; } System.out.println( (a == b)); ... How many times does this loop iterate? What would the result be for line 8?

10 False

Given a programmer-defined class called Person, what is output? Person barb = new Person(18); Person jessie = new Person(21); change(barb, jessie); System.out.println(barb.getAge()); public static void change(Person p1, Person p2){ p1 = p2; }

18

What is the output? public class Student { private double myGPA; private int myCredits; public void increaseCredits(int amount) { myCredits = myCredits + amount; } public void setCredits(int credits) { myCredits = credits; } public int getCredits() { return myCredits; } public static void main(String [] args) { Student s = new Student(); s.setCredits(6); s.increaseCredits(12); System.out.println(s.getCredits()); } }

18

Given a programmer-defined class called Person, what is output? Person barb = new Person(18); Person jessie = new Person(21); change(barb, jessie); System.out.println(barb.getAge()); public static void change(Person p1, Person p2){ int age = p2.getAge(); p1.setAge(age); }

21

int x = 4; switch(x){ case 0: x = 10; break; case 2: x = 4; break; case 3: x++; break; case 4: --x; case 5: ++x; break; default: x = 0; break; } System.out.println("x = " + x);

4

What is the index of the last element? int[] numList = new int[50];

49

int x = 4; if(x > 2){ x += 5; } else if (x >= 4){ x -= 2; } else{ x = 10; } System.out.println("x = " + x);

9

Which is true regarding how methods work? A method's local variables are discarded upon a method's return; each new call creates new local variables in memory If a method returns a variable, the method stores the variable's value until the method is called again After a method returns, its local variables keep their values, which serve as their initial values the next time the method is called A return address indicates the value returned by the method

A method's local variables are discarded upon a method's return; each new call creates new local variables in memory

Which is true? A mutator is also known as a getter method A mutator may change class fields Private members can be accessed by a class user An accessor is also known as a setter method

A mutator may change class fields

Which is true? A private helper method can call public methods in the same class A private helper method can be called from main( ) in another class A private helper method can not call other private methods in the same class A private helper method can be called by a class user

A private helper method can call public methods in the same class

___ means to have a user interact with an item at a high-level.

Abstraction

git add

Add tells git to track changes of the local working directory

Stack

LIFO collection

Select the true statement. Method stubs can not be compiled A benefit of methods is to increase redundant code A key reason for including methods is to make main() run faster Method stubs are temporary placeholders used during development

Method stubs are temporary placeholders used during development

What is read into string myString for input "One-hit wonder". myString = scnr.next();

One-hit

new FileWriter(file, true);

Opens the file in append mode

new FileWriter(file);

Opens the file in overwrite mode

new FileWriter(file, false)

Opens the file in overwrite mode

For this course, how are we merging branches?

Pull Request via Github.com

Which is true? Reference variables store memory locations Contents of a Double instance can be modified after initialization An instance of String stores data rather than an object reference Instances of programmer-defined objects are immutable

Reference variables store memory locations

var = true;

boolean

Which statement correctly calls calcArea() with two int arguments? public void calcArea(int w, int h); calcArea(4, 12); calcArea( ); calcArea(int w, int h);

calcArea(4, 12);

final

can't be inherited from (if a class) or modified (if a variable)

subclass

child

Mandy designs a Student object that includes a name, address and gpa. This is an example of ___.

data encapsulation

do while

executes code first then loops if condition is true

A class may [ Select ] only one class.

extend

Which declaration assigns a variable with 5 such that the value can not be later changed? final int NUM_ITEMS = 5; int NUM_ITEMS = 5; int numItems = 5; final int = 5;

final int NUM_ITEMS = 5;

var = 1.0f;

float

Which for loop will iterate 100 times?

for (i = 0; i < 100; i++)

A class may [ Select ] any number of classes

implement

var = 1;

int

var = new int[5];

int array

The world population is over 7 billion. Which declaration uses the fewest bits while guaranteeing that worldPopulation can be assigned the value 7 billion without error?

long worldPopulation;

while

loop as long as the condition is true

for(int i=o;i<x;i++)

loops a specific number of times

for(int i : ints)

loops over a collection

Which reads an entire line of text into string myString?

myString = scnr.nextLine();

In calcArea(), width and height are _____ public static void calcArea(int width, int height){};

parameters

superclass

parent

Which is the best stub for a method that calculates an item's tax?

public static double ComputeTax(double itemPrice) { System.out.println("FIXME: Calculate tax"); return 0.0; }

For what values of x will "Medium" be output? If x > 40: Output "Large" Else If x > 20: Output "Medium" Else If x > 10: Output "Small"

Any x from 21 to 40

Queue

FIFO collection

True or False: You can create an instance of an abstract class? (i.e., new AbstractClass())

False

Array

Fixed length collection

For what values of integer x will Branch 3 execute? If x < 10 : Branch 1 Else If x > 9: Branch 2 Else: Branch 3

For no values (never executes)

What will a compiler do for the following code? /* numItems = 2; /* Total items to buy */ rate = 0.5; */

Generate an error.

For which quantity is a double the best type? Planes above a city Boxes on a conveyor belt Height of a building People in a household

Height of a building

What does this code output? System.out.print("I "); System.out.println("want pie.");

I want pie.

Three sock types A, B, C exist in a drawer. Pulled socks are kept and not returned. Which is true?

If the first three pulls are different socks, only one more pull is needed for a match

What will a compiler do for the following three lines of code? // x = 2; // width // y = 0.5 // z = x * y; Total area

Ignore all three lines

The keyword this ___.

Implicitly refers to an object within instance methods

A programmer develops code by repeating short sessions of writing, compiling, and testing until the project is finished. This is an example of _____.

Incremental development

public static void printFeverCheck (double temp) { final double NORMAL_TEMP = 98.6; final double CUTOFF_TEMP = 95; double degreesOfFever; if (temp > NORMAL_TEMP) { degreesOfFever = temp - NORMAL_TEMP; System.out.print("You have " + degreesOfFever + " degrees of fever."); } else if (temp < CUTOFF_TEMP) { degreesOfFever = CUTOFF_TEMP - temp; System.out.print("Your temperature is " + degreesOfFever + " below 95."; } } public static void main(String args[]) { double bodyTemperature; bodyTemperature = 96.0; System.out.print("Checking for fever..."); printFeverCheck(bodyTemperature); }

Checking for fever...v

git commit

Commit persists/confirms the current tracked (added) changes. Note, this makes the files no longer show via "git status".

ArrayList

Dynamic length colletion

Which of the following statements is false? Program execution begins at main(). An output statement outputs a value to the screen. A program executes one statement at a time. Each statement ends with a period.

Each statement ends with a period.

private

available only to the declared class

public

available to all classes

default

available to classes in same package

protected

available to subclasses AND same package

Which is best declared as a constant? The number of leaves on a tree The number of people in a car The number of insects in a room The number of feet in a yard

The number of feet in a yard

var = "bob";

String

var = new String[5];

String array

Choose the statement(s) that generate(s) this output: I wish you were here

System.out.println("I wish"); System.out.println("you were here");

Which is true for comments? The compiler translates comments into ASCII values. The compiler allocates memory for comments along with for variables. The compiler converts comments into a series of machine instructions. The compiler does not generate machine code for comments.

The compiler does not generate machine code for comments.

Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling?

The first error only

What is the purpose of a variable?

To hold a value

True or False: A commit must always have a message (even if it's blank/empty string)

True

True or False: We must manually sync our changes among our local repository and the remote repository

True

A sequence of instructions that solves a problem is called a(n) _____ .

algorithm

static

attributes/method belong to the class rather than each object

public class Inheritance {} abstract class Animal { protected int numberOfLegs = 0; protected String name = ""; public int getNumberOfLegs() { return numberOfLegs; } abstract public void speak(); } class FourLeggedAnimal extends Animal { public FourLeggedAnimal extends Animal { this.numberOfLegs = 4; } @Override public void speak() { System.out.println("I don't know what type of animal I am"); } } class Dog extends FourLeggedAnimal { public Dog(String name) { this.name = name; } @Override public void speak() { System.out.println(name + ": Bark!"); } } Given the code above Dog is a [ ] of Animal. Given the code above Animal is a [ ] of Dog. Given the code above FourLeggedAnimal is a [ ] of Animal. Given the code above FourLeggedAnimal is a [ ] of Dog

subclass superclass subclass superclass

git push

syncs changes from local to remote

git pull

syncs changes from remote to local

If a program compiles without errors, the program is free from _____.

syntax errors

Autoboxing is ___.

the automatic conversion of primitive types to the corresponding wrapper classes

In an instruction like: z = x + y, the symbols x, y, and z are examples of _____.

variables

Which is an example of a process?

x + y

A program should compute two times x. Which statement has a logic error?

y = x * x;

Which statement causes overflow? int x = 3000; int y = 1000; int z;

z = x * y * y;


Kaugnay na mga set ng pag-aaral

Chapter 10 Carrier Wide Area Networks (WANs)

View Set

Chapter 2 Atomic Orbitals, energy, shape, and electron density

View Set

Quiz 12 : Essentials of Networking

View Set

Primerica Session A Chapter 2 Contract Law (Chapter Quiz, Snap Shots, and review questions)

View Set

Sensation and Perception Module 18

View Set

Computer Technology I Glossary 4: Software

View Set

OMIS 360 EXAM 1 Disc Ques Dr. Huynh

View Set

MGMT 4860 - Organizational Design and Change - Midterm Study Guide

View Set