Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Similar documents
CS 101 Exam 2 Spring Id Name

This exam is open book. Each question is worth 3 points.

JAVA OPERATORS GENERAL

CS 101 Exam 1 Spring 200 Id Name

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

CS 101 Fall 2005 Midterm 2 Name: ID:

CSC 240 Computer Science III Spring 2018 Midterm Exam. Name

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

Selenium Class 9 - Java Operators

Instance Method Development Demo

Prof. Navrati Saxena TA: Rochak Sachan

coe318 Lab 2 ComplexNumber objects

CS 101 Fall 2006 Midterm 3 Name: ID:

University of Palestine. Mid Exam Total Grade: 100

Key Java Simple Data Types

Java Simple Data Types

Programming Basics. Digital Urban Visualization. People as Flows. ia

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java Simple Data Types

Place your name tag here

CS 101 Spring 2007 Midterm 2 Name: ID:

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

CMPS 11 Intermediate Programming Midterm 2 Review Problems

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Handout 7. Defining Classes part 1. Instance variables and instance methods.

H212 Introduction to Software Systems Honors

CS 302 Week 9. Jim Williams

Day 2 : Intermediate Concepts 1 Examples

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

Methods. Eng. Mohammed Abdualal

CMPS 12A Introduction to Programming Midterm 2 Review Problems

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

AP COMPUTER SCIENCE A

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

Exercise 6 Multiple Inheritance, Multiple Dispatch and Linearization November 3, 2017

CS 201, Fall 2016 Sep 28th Exam 1

More on methods and variables. Fundamentals of Computer Science Keith Vertanen

Java Programming for Selenium

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

CS 113 PRACTICE FINAL

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CMP 326 Midterm Fall 2015

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

Chapter 4 Defining Classes I

Computational Expression

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

Practice Problems: Instance methods

DM503 Programming B. Peter Schneider-Kamp.

b. Suppose you enter input from the console, when you run the program. What is the output?

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

CS 231 Data Structures and Algorithms, Fall 2016

Java Programming Language. 0 A history

CS1083 Week 2: Arrays, ArrayList

Week 14 Lab A Linked List of Integers Maximum Points = 10

Assignment 1 due Monday at 11:59pm

Exam Percentage: / 55 = %

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

CSCI 111 Midterm Spring 2014

CCHS Math Recursion Worksheets M Heinen CS-A 12/5/2013. Recursion Worksheets Plus Page 1 of 6

University of Massachusetts Amherst, Electrical and Computer Engineering

CS180. Exam 1 Review

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

AP CS Unit 3: Control Structures Notes

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

CSCI 355 LAB #2 Spring 2004

CMP-326 Exam 2 Spring 2018 Total 120 Points Version 1

CSIS-120 Final Exam Fall 2015 Name:

CIS 120 Programming Languages and Techniques. Midterm II. November 12, Answer key

Documenting, Using, and Testing Utility Classes

Objects as a programming concept

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

APCS Semester #1 Final Exam Practice Problems

MIDTERM REVIEW. midterminformation.htm

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

Java Review. Java Program Structure // comments about the class public class MyProgram { Variables

Final Exam Practice Questions

AP CS Unit 4: Classes and Objects Programs

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

1. Reference Mystery, 5 points. What output is produced by this program? import java.util.*;

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Roll Number. Common to II Year B.E.CSE & EIE INTERNAL ASSESSMENT TEST - I. Credit 3 R-2017

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Prelim One Solution. CS211 Fall Name. NetID

Transcription:

Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged

The following definitions are in effect throughout the remainder of the test. public class A { private int v1; private int v2; public A(int f1, int f2) { this.v1 = f1; this.v2 = f2; public String tostring() { return "( v1 = " + v1 + " " + v2 + ")"; public class B { private int b; public B() { System.out.println("b = " + b); public Class C { private int c1; static private int c2; public C() { c1 = 0; c2 = 0; public void increment() { ++c1; ++c2; public String tostring() { return "( c1 = " + c1 + " c2 = " + c2 + ")"; Pledged Page 2 of 8 Pledged

2. (8 points) Evaluate the following expressions and give the value. a) 10 == 20 && 20 <= 10 b) && c)! && d) 10 + 10 <= 20 10!= 10 3. (4 points) Complete the truth table for the logical operation some. The logical operation some is if and only if at least one of p and q are. p q p some q 4. (4 points) Complete the truth table for the logical operation less. The logical operation less is if and only if p < q. Hint: <. p q p less q 5. (4 points) What is the output of the following code segment? B myb = new B(); b = Pledged Page 3 of 8 Pledged

6. (3 points) Consider the following code segment. int n1 = 12; int n2 = 144; if (n2 < n1) { n1 = 10; System.out.println("n1 = " + n1); What is its output? n1 = 7. (3 points) Consider the following code segment. String s1 = "wahoo"; String s2 = "wahoo"; if (s2 == s1) { s1 = "UVA"; System.out.println("s1 = " + s1); What is its output? s1 = 8. (3 points) Consider the following code segment. String s1 = new String("wahoo"); String s2 = new String("wahoo"); if (s2.equals(s1)) { s1 = "UVA"; System.out.println("s1 = " + s1); What is its output? s1 = 9. (4 points) Consider the following code segment? C n1 = new C(); C n2 = new C(); n1.increment(); n2.increment() System.out.println( n1.tostring() ); System.out.println( n2.tostring() ); What is its output? ( c1 = c2 = ) ( c1 = c2 = ) Pledged Page 4 of 8 Pledged

10. (4 points) Does the following program compile? Why? public class DemoB { public static void main(string[] args) { B b1 = new B(); B b2 = b1; int v = b1.b; System.out.println( v ); 11. (2 points) Does the following program compile? Why? public class DemoA { public static void main(string[] args) { A a = new A(); System.out.println( a ); 12. (4 points) Rewrite the following code segment using proper indentation. if (n == 1) { i = 1; else { if (n!= 2) { i = 2; else { i = 3; Pledged Page 5 of 8 Pledged

Questions 13 15 consider the following code segment. if ( i!= 4 ) { if ( (i + j) < 6 ) { System.out.println("A"); else { System.out.println ("B"); else if ( i > j ) { System.out.println("C"); else { if ( j == 3 ) { System.out.println("D"); else { System.out.println ("E"); 13. (4 points) If i is 6 and j is 5, what is the output? 14. (4 points) If i is 4 and j is 5, what is the output? 15. (4 points) Give values for i and j that cause D to be displayed. i = j = 16. (8 points) Write a default constructor for class A initializes the instance variables to the int value 1. 17. (6 points) Write an appropriately named accessor for class A that returns the value of the v1 attribute of the invoking object. Pledged Page 6 of 8 Pledged

18. (6 points) Write an appropriately named mutator for class A, which has a single int parameter f1. The mutator sets the v1 attribute of the invoking object to f1. 19. (7 points) Write an equals() method for class A. The method should return if and only if the actual parameter is an A object whose attributes match the attributes of the invoking object. 20. (4 points) Complete the following code segment in the following manner. a1 references a new default constructed A object. a2 references a new A object constructed so that its attributes both equal 10. A a1 = A a2 = Pledged Page 7 of 8 Pledged

21. (10 points) Write a program named ProcessTwo.java. The program prompts and extracts an integer number from standard input. If the first number is less than 5 then the program displays "Wahoo"; otherwise it displays "Cavalier". Commenting and input echoing is not necessary. PLEDGE: Pledged Page 8 of 8 Pledged