Lab5. Wooseok Kim

Similar documents
Lab5. Wooseok Kim

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Selected Questions from by Nageshwara Rao

Java Simple Data Types

Java Simple Data Types

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

Computational Expression

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

ECE 122. Engineering Problem Solving with Java

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Introduction to Java Applications

Example packages from Java s standard class library:

Key Java Simple Data Types

Protection Levels and Constructors The 'const' Keyword

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

Formatting Output & Enumerated Types & Wrapper Classes

Computational Expression

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

Objects and Classes -- Introduction

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

Methods CSC 121 Fall 2016 Howard Rosenthal

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

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

Programming overview

S8352: Java From the Very Beginning Part I - Exercises

CompSci 125 Lecture 02

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

Lec 3. Compilers, Debugging, Hello World, and Variables

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Methods CSC 121 Spring 2017 Howard Rosenthal

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Array. Prepared By - Rifat Shahriyar

Preview from Notesale.co.uk Page 3 of 36

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Chapter 4 Defining Classes I

PROGRAMMING FUNDAMENTALS

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

Fall 2017 CISC124 9/16/2017

Java Bytecode (binary file)

We now start exploring some key elements of the Java programming language and ways of performing I/O

Full file at

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

CS 101 Fall 2006 Midterm 1 Name: ID:

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

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

CS 231 Data Structures and Algorithms, Fall 2016

CS 11 java track: lecture 1

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

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Introduction to Programming Using Java (98-388)

AP Computer Science A

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

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Object Oriented Programming. Java-Lecture 1

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

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

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

2.5 Another Application: Adding Integers

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

Classes and Objects Part 1

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

( &% class MyClass { }

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

Java: Comment Text. Introduction. Concepts

CS 302: Introduction to Programming

Class Libraries and Packages

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

x++ vs. ++x x=y++ x=++y x=0; a=++x; b=x++; What are the values of a, b, and x?

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

Final Exam. COMP Summer I June 26, points

What did we talk about last time? Examples switch statements

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Primitive Data, Variables, and Expressions; Simple Conditional Execution

Defining Classes and Methods

Lecture 02, Fall 2018 Friday September 7

Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal

CHAPTER 7 OBJECTS AND CLASSES

Software and Programming 1

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Chapter 1 Introduction to Java

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

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Prelim One Solution. CS211 Fall Name. NetID

1 Shyam sir JAVA Notes

Text User Interfaces. Keyboard IO plus

CS260 Intro to Java & Android 03.Java Language Basics

Java for Non Majors Spring 2018

Programming with Java

Input. Scanner keyboard = new Scanner(System.in); String name;

Object-Oriented Programming

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

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

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Administration. Classes. Objects Part II. Agenda. Review: Object References. Object Aliases. CS 99 Summer 2000 Michael Clarkson Lecture 7

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1

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

Transcription:

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

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

Question Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextint( 19 ) + 22 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 The line of Java code "// System.out.println("Hello");" will A) do nothing B) cause Hello to be outupt C) cause a syntax error D) cause (Hello) to be output E)there is no way to know without executing this line of code

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 Which character below is not allowed in an identifier? A) $ B) _ C) 0 (zero) D) q E) ^

Question 4 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 4 B) A syntax error Compile Error C) A run-time error 12 / 0 =? D) A logical error Incorrect Answer

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

Question 5 (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 6 Following Java naming convention, which of the following would be the best name for a class about store customers? A) StoreCustomer B) Store Customer C) storecustomer D) STORE_CUSTOMER E) Store-Customer

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

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

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

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

Question 9 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 10 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 11 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

Question 12 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 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 Mistyping println as printn will result in A) A syntax error B) A runtime error C) a logical error D) no error at all E) Converting the statement into a comment

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 22 (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