Lab5. Wooseok Kim

Similar documents
Lab5. Wooseok Kim

Selected Questions from by Nageshwara Rao

Java Simple Data Types

Computational Expression

ECE 122. Engineering Problem Solving with Java

Protection Levels and Constructors The 'const' Keyword

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Key Java Simple Data Types

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects

Java Simple Data Types

CS 101 Fall 2006 Midterm 1 Name: ID:

CS260 Intro to Java & Android 03.Java Language Basics

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Example packages from Java s standard class library:

PROGRAMMING FUNDAMENTALS

Section 2.2 Your First Program in Java: Printing a Line of Text

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

Computational Expression

Final Exam. COMP Summer I June 26, points

Introduction to Programming Using Java (98-388)

CSCI 2010 Principles of Computer Science. Basic Java Programming. 08/09/2013 CSCI Basic Java 1

Methods CSC 121 Fall 2016 Howard Rosenthal

Objects and Classes -- Introduction

Programming overview

Use the static method range of class EnumSet (declared in package java.util) to access a range of an enum s constants.

A variable is a name for a location in memory A variable must be declared

Formatting Output & Enumerated Types & Wrapper Classes

Programming with Java

Methods CSC 121 Spring 2017 Howard Rosenthal

1 Shyam sir JAVA Notes

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

ECE 122. Engineering Problem Solving with Java

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

An Introduction To Writing Your Own Classes CSC 123 Fall 2018 Howard Rosenthal

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Array. Prepared By - Rifat Shahriyar

Following is the general form of a typical decision making structure found in most of the programming languages:

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Introduction to Java Applications

Midterm Exam CS 251, Intermediate Programming March 6, 2015

B.V. Patel Institute of BMC & IT, UTU 2014

Java 2 Programmer Exam Cram 2

2.5 Another Application: Adding Integers

Assumptions. History

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

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

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Chapter 2 C++ Fundamentals

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Java Bytecode (binary file)

All classes in a package can be imported by using only one import statement. If the postcondition of a method is not met, blame its implementer

CS 11 java track: lecture 1

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

ICSE Class 10 Computer Applications ( Java ) 2014 Solved Question Paper

CHAPTER 7 OBJECTS AND CLASSES

Full file at

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

AP Computer Science A

CMSC 132: Object-Oriented Programming II

COE318 Lecture Notes Week 3 (Week of Sept 17, 2012)

Do not start the test until instructed to do so!

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

( &% class MyClass { }

APCS Semester #1 Final Exam Practice Problems

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

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

CompSci 125 Lecture 02

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Fall 2017 CISC124 9/16/2017

Review for Test 1 (Chapter 1-5)

Computer Programming, I. Laboratory Manual. Final Exam Solution

Example: Tax year 2000

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

Objects and Classes Lecture 2

VARIABLES AND TYPES CITS1001

Motivation was to facilitate development of systems software, especially OS development.

Using Classes and Objects. Chapter

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

JAVA Ch. 4. Variables and Constants Lawrenceville Press

Example Program. public class ComputeArea {

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java

Class Libraries and Packages

Methods (Deitel chapter 6)

Problem Grade Total

Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

Methods (Deitel chapter 6)

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

Introduction to Java

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Computational Expression

Prelim One Solution. CS211 Fall Name. NetID

Transcription:

Lab5 Wooseok Kim wkim3@albany.edu www.cs.albany.edu/~wooseok/201

Question Answer Points 1 A or B 8 2 A 8 3 D 8 4 20 5 for class 10 for main 5 points for output 5 D or E 8 6 B 8 7 1 15 8 D 8 9 C 8 10 B 8

Question Answer Points 11 D 8 12 B 8 13 A 8 14 A or B or D 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextint( 21 ) + 20 20 10 for 21 10 for 20 20 25 10 for correct substring 10 for correct call to length() 5 for correct output

Question 1 Comments should be A) rephrase the code it explains in English B) be insightful and explain what the instruction s intention is C) only be included in code that is difficult to understand D) Be used to define variables whose names are not easy to understand E) all of the above

Question 2 A unique aspect of Java that allows code compiled on one machine to be executed on a machine of a different hardware platform is Java s A) bytecodes B) syntax C) use of objects D) use of exception handling E) all of the above

Question 2

Question 3 An error in a program that results in the program outputting $100 instead of the correct answer, $250 is A) A programmer error B) A syntax error C) A run-time error D) A logical error E) A snafu

Question 3 B) A syntax error Compile Error C) A run-time error 12 / 0 =? D) A logical error Incorrect Answer

Question 4 Write a Java program that will display on two separate lines your name and your major.

Question 4 (Grading Guideline) 5 points for having the keyword class and a reasonable class name in the right place 2 points each for static, void, main(), String[], args 5 points for output the name and the major

Question 5 Consider the following statement: This statement will output lines of text A) 1 B) 2 C) 3 D) 4 E) 5

Question 5 1st line 2nd line 3rd line 4th line

Question 5 1st line 2nd line 3rd line 4th line Real output has 5 lines because of /r /r: Carrage Return

Question 6 If x is an int and y is a float, all of the following are legal except which assignment statement? A) y = x; B) x = y; C) y = (float) x; D) x = (int) y; E) all of the above are legal

Question 6 If x is an int and y is a float, all of the following are legal except which assignment statement? A) y = x; B) x = y; int < float C) y = (float) x; D) x = (int) y; E) all of the above are legal

Question 7 What will be the result of a in the following assignment statement? Assume b = 5 and c = 10.

Question 7 (Grading Guideline) 15 pionts Up to 10 points partical credit if they have some correct work

Question 8 Which library package would you import to use NumberFormat and DecimalFormat? A) java.beans B) java.io C) java.lang D) java.text E) java.util

Question 9 QuestionNineAndTen computes A) The correct average of x, y and z as a double B) The correct average of x, y and z as an int C) The average of x, y, and z as a double, but the result may not be accurate D) The sum of x, y and z E) The remainder of the sum of x, y and z divided by 3

Question 9 QuestionNineAndTen computes C) The average of x, y, and z as a double, but the result may not be accurate int = x + y + z int = int / 3 However, average is double

Question 10 What is output if x = 0, y = 1 and z = 1? A) 0 B) 0.0 C) 0.66666666 D) 0.66666667 E) 0.67 double average = (0 + 1 + 1) / 3 = 2 / 3 = 0.0 if int average? The answer is 0

Question 11 In order to create a constant, you would use which of the following Java reserved words? A) private B) static https://www.javatpoint.com/static-keyword-in-java C) int D) final E) class

Question 12 In Java, a variable of type boolean will store either a 0 or a 1 A) true B) false

Question 12 In Java, a variable of type boolean will store either a 0false or a 1true A) true B) false

Question 13 In Java, a variable may contain A) a primitive value or an object reference B) a package C) a method D) a class E) any of the above

Question 14 (Dropped) What happens if you attempt to use a variable before it has been initialized? A) A syntax error may be generated by the compiler B) A runtime error may occur during execution C) A garbage or uninitialized value will be used in the computation D) A value of zero is used if a variable has not been initialized E) Answers A and B are correct

Question 14 (Dropped) What happens if you attempt to use a variable before it has been initialized? A) A syntax error may be generated by the compiler B) A runtime error may occur during execution D) A value of zero is used if a variable has not been initialized

Question 15 What is the function of the dot operator? A) It serves to separate the integer portion from the fractional portion of a floating point number B) It allows one to access the data within an object when given a reference to the object C) It allows one to invoke a method within an object when given a reference to the object D) It is used to terminate commands (much as a period terminates a sentence in English) E) Both B and C are correct

Question 16 In Java, instantiation means A) noticing the first time something is used B) creating a new object of the class C) creating a new alias to an existing object D) launching a method E) none of the above

Question 17 An alias when A) Two different reference variables refer to the same physical object B) Two different numeric variables refer to the same physical object C) Two different numeric variables contain identical values D) Two variables have the same names E) none of the above

Question 18. An API is A) an Abstract Programming Interface B) an Application Programmer s Interface C) an Application Programming Interface D) an Abstract Programmer s Interface E) an Absolute Programming Interface

Question 19. Complete the following assignment statement that generates a random number between 20 (inclusive) to 40 (inclusive).

Question 20 Given a String object Computer Science whose object reference is major, use the object reference to invoke proper String instance methods to create a substring containing Sci, calculate the length of the substring, display both the substring and its length on the same line. String major = new String( Computer Science ); String substringofmajor; //Store the substring of major int lengthofmajor; //Store the length of the substring

Question 20

Question 20 (Grading Guideline) 25 points 10 for correct substring call take off 5 points if the numbers are not correct 10 for correct call to length() 5 for correct output: the substring and it s length must be on the same line