Multiple Choice Questions (20 points)

Similar documents
J a v a Quiz (Unit 3, Test 0 Practice)

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Part I. Multiple Choice Questions (2 points each):

LAB4 Making Classes and Objects

Java Basics: Data Types, Variables, and Loops

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

C++FA 5.1 PRACTICE MID-TERM EXAM

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Sample CSE8A midterm Multiple Choice (circle one)

1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.

Java Crash Course Part I

CS170 Lab 11 Abstract Data Types & Objects

Introduction to Java

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Section 6 Spring 2013

AP Computer Science Java Subset

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Pemrograman Dasar. Basic Elements Of Java

Basic Java Syntax. Program Structure

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Solutions to Quick Check Questions. Defining Your Own Classes Part 1

Term Project: Roulette

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Understanding class definitions

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Part 1 Foundations of object orientation

Sources: On the Web: Slides will be available on:

Java Interview Questions and Answers

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Chapter 13 - Inheritance

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Introduction to Java. CS 3: Computer Programming in Java

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

An Incomplete C++ Primer. University of Wyoming MA 5310

Comp151. Definitions & Declarations

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Computer Programming I

CMPT 183 Foundations of Computer Science I

Basic Object-Oriented Programming in Java

CSC 221: Computer Programming I. Fall 2006

java Features Version April 19, 2013 by Thorsten Kracht

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Semantic Analysis: Types and Type Checking

C++ INTERVIEW QUESTIONS

Chapter 1 Java Program Design and Development

The C Programming Language course syllabus associate level

Using Files as Input/Output in Java 5.0 Applications

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Java Programming Fundamentals

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

CmpSci 187: Programming with Data Structures Spring 2015

C++ Programming Language

AP Computer Science Java Mr. Clausen Program 9A, 9B

Building Java Programs

Contents. 9-1 Copyright (c) N. Afshartous

Moving from CS 61A Scheme to CS 61B Java

Explain the relationship between a class and an object. Which is general and which is specific?

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

AP Computer Science Static Methods, Strings, User Input

Crash Course in Java

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

CS 111 Classes I 1. Software Organization View to this point:

Computer Science 217

objectives chapter Define classes that act like blueprints for new objects, made of variables and methods. Explain encapsulation and Java modifiers.

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

History OOP languages Year Language 1967 Simula Smalltalk

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

CS 106 Introduction to Computer Science I

Math Games For Skills and Concepts

public static void main(string[] args) { System.out.println("hello, world"); } }

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Many applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may

Conditional Statements Summer 2010 Margaret Reid-Miller

Threads 1. When writing games you need to do more than one thing at once.

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

Iteration CHAPTER 6. Topic Summary

Programming Languages CIS 443

Variables, Constants, and Data Types

WRITING DATA TO A BINARY FILE

LOOPS CHAPTER CHAPTER GOALS

Prime Time: Homework Examples from ACE

csce4313 Programming Languages Scanner (pass/fail)

Object-Oriented Programming in Java

CMSC 202H. ArrayList, Multidimensional Arrays

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

The Interface Concept

CS114: Introduction to Java

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

Transcription:

CSC142 Midterm 1 1 Multiple Choice Questions (20 points) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Fill the correct bubble on your scantron sheet. Each correct answer is worth 1 point. Each question has EXACTLY one correct answer. 1. Mae's accounting service helps each customer figure their tax owed. The customer's first name, middle initial and last name go on the form. The number of dependents is needed, along with the total income for the year. Mae charges a fee of 1.5% of total income for the service. Which one of the following would be the best suitable type for a variable that stores the number of dependents of the customer? A. double B. int C. char D. String E. None of the above 2. Still referring to question 1, which one of the following would be a suitable type for a variable, that stores the last name of the customer? A. double B. int C. char D. String E. None of the above

CSC142 Midterm 1 2 3. Still referring to the situation described in question 1, suppose the program which Mae uses has a method which, given the total income and the number of dependents (and no other information) computes and returns the tax owed. Such a method (choose the best answer) A. would have more than two parameters and a void return type. B. would have two parameters and a double return type. C. would have less than two parameters and an int return type. D. would have a void return type. E. None of the above 4. Still referring to the problem described in question 1, what would be the best way to represent the 1.5% fee as a constant in the program? A. public double fee=0.015; B. private double fee=0.015; C. public final String FEE="0.015"; D. public final double FEE=0.015; E. public final long FEE=0.015; 5. Which of the following is TRUE about the switch statement in Java? A. A default sends execution immediately to the end of the switch statement. B. A break sends execution immediately to the end of the switch statement. C. A case sends execution immediately to the end of the switch statement. D. A break sends execution immediately to the end of the next case. E. The statements in a switch continue to execute as long as the condition at the top of the switch remains true.

CSC142 Midterm 1 3 6. Among these expressions, which is(are) of type String? A. "0" B. "ab"+"cd" C. '0' D. A and B E. A, B and C 7. The interface of a class refers to A. the list of all of the fields and methods of the class B. the list of all of the public fields and public methods of the class C. the list of all the private fields and public methods of the class D. the list of all the private fields and private methods of the class E. the comments written in the code of the class. 8. Consider the following code fragment Rectangle r1 = new Rectangle(); r1.setcolor(color.blue); Rectangle r2 = r1; r2.setcolor(color.red); After the above piece of code is executed, what are the colors of r1 and r2 (in this order)? A. Color.blue Color.red B. Color.blue Color.blue C. Color.red Color.red D. Color.red Color.blue E. Can't tell. There is not enough information.

CSC142 Midterm 1 4 9. What is the type and value of the following expression? (notice the integer division) -4 + 1/2 + 2*-3 + 5.0 A. int -5 B. double -4.5 C. int -4 D. double -5.0 E. None of the above 10. What is printed by the following statement? System.out.print("Hello,\nworld!"); A. Hello, \nworld! B. Hello, world! C. Hello, world! D. "Hello, \nworld!" E. None of the above.

CSC142 Midterm 1 5 11. In the class Car, you want to create an instance method isspeeding to check whether an object to type Car is speeding or not. One of the instance fields of the Car class is a double variable speed equal to the current speed of the Car object. The class also lists a constant static double field SPEED_LIMIT, equal to the legal speed limit for the driving conditions of the Car object. What method signature would be best for isspeeding? A. public void isspeeding(double speed) B. public boolean isspeeding() C. public boolean isspeeding(double speed, double SPEED_LIMIT) D. public isspeeding() E. public boolean isspeeding(speed, SPEED_LIMIT)

CSC142 Midterm 1 6 12. Consider the two methods (within the same class) public int foo(int a, String s) { s = "Yellow"; a=a+2; return a; } public void bar() { int a=3; String s = "Blue"; a = foo(a,s); System.out.println("a="+a+" s="+s); } What is printed? A. a=3 s=blue B. a=5 s=yellow C. a=3 s=yellow D. a=5 s=blue E. The code doesn't compile. In Java, it is forbidden to use the same name for a local variable in two different methods. 13. Using the Java class uwcse.graphics.oval, which statement would you write to create a circle of radius 20, centered at x=100 and y=100. A. new Oval(80,80,40,40); B. new Oval(80,80,20,20); C. new Oval(60,60,40,40); D. new Oval(120,120,20,20); E. new Oval(100,100,20,20);

CSC142 Midterm 1 7 14. Which of the following variable declaration would NOT compile in a Java program? A. int var; B. int VAR; C. int var1; D. int var_1; E. int 1_var; 15. Using De Morgan s law, how would you rewrite the following conditional statement (i.e. is rewrite the statement using && instead of ) ( c!='n' && z+2<=5 ) A.!(c!='n' z+2<=5) B.!(c=='n' z+2>=5) C.!(c!='n' z+2<=5) D.!(c=='n' z+2>5) E.!(c=='n' z+2<5) 16. In a Java program, you read the following statement that compiles and executes. Cookie cookie = new Cookie("chocolate chips"); What can you conclude? A. Cookie is the name of a class. B. cookie is a primitive type variable. C. The Cookie class must have a constructor that has one formal parameter of type String. D. A and C E. A, B and C

CSC142 Midterm 1 8 17. You are programming a game of dice. You need to generate a random integer that can be 1, 2, 3, 4, 5, or 6. Which of the following expression would you select? Recall that Math.random() returns a random double >=0 and <1 A. Math.random()*6 B. ((int)math.random())*6+1 C. (int)(math.random()*6)+1 D. (int)(math.random()+6) E. (int)(math.random()*6) 18. Consider the following class definition: public class MyClass{ private int value; public void setvalue(int i){ /* code */ } // Other methods... } The method setvalue assigns the value of i to the instance field value. What could you write for the implementation of setvalue? A. value = i; B. this.value = i; C. value == i; D. A and B E. A, B and C.

CSC142 Midterm 1 9 19. What will the following program fragment output? Integer i = new Integer(5); Integer j = new Integer(5); if (i==j) System.out.println( Equal ); else System.out.println( Not equal ); A. Equal B. Not equal C. Equal Not equal D. The program doesn't compile because == can't be used with references. E. The program doesn t execute because i and j are not correctly initialized. 20. Consider the following truth table for a logical operator "implies" P Q P implies Q T T T F F T F F T F T T Which of the following java conditional expressions would reproduce the above truth table? A. P Q B. (!P) && (!Q) C. (!P) Q D. P && (!Q) E. (!P) && Q