CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

Similar documents
Chapter 1 - Introduction. Copyright 2014 by John Wiley & Sons. All rights reserved. 1

ICOM 4015: Advanced Programming

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

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

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

Object-Oriented Programming

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

SDKs - Eclipse. SENG 403, Tutorial 2

Getting started with Java

Full file at

CHAPTER 1 Introduction to Computers and Java

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

Preview from Notesale.co.uk Page 3 of 36

AP Computer Science Unit 1. Programs

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

2/9/2012. Chapter One: Introduction. Chapter Goals

Chapter Goals. Chapter One: Introduction. Prerequisites. What Is Programming?

TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

PROGRAMMING FUNDAMENTALS

Darrell Bethea May 25, 2011

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

Computer Science is...

First Java Program - Output to the Screen

Java Bytecode (binary file)

Introduction. Arizona State University 1

Conditional Execution

Introduction to JAVA

CS111: PROGRAMMING LANGUAGE II

Chapter 1: Introduction to Computers and Java

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

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Course Outline. Introduction to java

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

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

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

CSC 1214: Object-Oriented Programming

CS111: PROGRAMMING LANGUAGE II

Week 2: Data and Output

Intro to Programming in Java Practice Midterm

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

Which statement regarding computer programs is correct? Which statement best describes a computer program?

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

Primitive Data, Variables, and Expressions; Simple Conditional Execution

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

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Introduction to Software Development (ISD) David Weston and Igor Razgon

1. An operation in which an overall value is computed incrementally, often using a loop.

CHAPTER INTRODUCTION. Final Draft Oct. 15, Slides by Donald W. Smith TechNeTrain.com. Copyright 2013 by John Wiley & Sons. All rights reserved.

Chapter Goals. Contents. 1.1 Computer Programs

Introduction to Java Applications

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Programming with Java

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

1. Download the JDK 6, from

Darrell Bethea May 20, 2011

CS 177 Recitation. Week 1 Intro to Java

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Introduction To Java Programming

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

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

AP Computer Science A Summer Assignment 2017

Introduction To Java Programming

Chapter 2: Programming Concepts

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

Selected Questions from by Nageshwara Rao

What did we talk about last time? Examples switch statements

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

St. Edmund Preparatory High School Brooklyn, NY

Lecture 5: Methods CS2301

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Full file at

Table of Contents Date(s) Title/Topic Page #s. Abstraction

Chapter 1 Introduction to Computers and C++ Programming

CS11 Java. Fall Lecture 1

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

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

Introduction To Java Programming

Introduction to Java Unit 1. Using BlueJ to Write Programs

Full file at

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

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

Definite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting

Chapter 1: Introduction to Computers and Programming

Introduction To Java Programming

Introduction To Java Programming

CSCI 1226 Sample Midterm Exam

Lesson 01 Introduction

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Chapter Goals. Contents INTRODUCTION

COMP 110 Project 1 Programming Project Warm-Up Exercise

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x );

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

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

4. If the following Java statements are executed, what will be displayed?

Building Java Programs

An overview of Java, Data types and variables

CHAPTER 2 Java Fundamentals

Transcription:

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 1. For each Java expression in the left hand column, indicate its value in the right hand column. Be sure to show a constant of the appropriate type. For example, 7.0 rather than 7 for a double, Strings in quotes, etc. 3* 2 + 4 * 3 17 % 9-20 % (26 / 7) 2 + 5 + "2" + 2 + 5 2.5 + 5 / 2 + (3 / 0.5) 3 * (2 + 4) * 2 / 10 2. Multiple Choice (a) An example of an output device that interfaces between computers and humans is a) a keyboard. b) a mouse. c) a speaker. d) a microphone. (b) Which one of the following typically provides data persistence without electricity? I. The CPU s memory II. The hard disk III. Secondary storage a) I, II only b) I, III only c) II, III only d) I, II, III (c) High-level programming languages a) Are made up primarily of ones and zeros b) Are independent of the underlying hardware c) Are not standardized d) Use syntax that is close to the underlying hardware s instruction set

(d) What is one of the benefits of using a high-level programming language like Java? a) Its syntax is very similar to the hardware instruction set b) No tools other than a text editor are required for programming c) Statements in the high-level language are just like English d) Problems solved in a high-level language are independent of the underlying computer hardware (e) What is the difference between an editor and a compiler? a) An editor converts program files into an executable program; a compiler allows program files to be written and stored b) An editor allows program files to be written and stored; a compiler produces an organized list of files c) An editor allows program files to be written and stored; a compiler produces an indexed database of terms and keywords d) An editor allows program files to be written and stored; a compiler converts program files into an executable program (f) Every statement in Java must be terminated with a) the semi-colon character ;. b) a carriage return. c) System.out.println(). d) an escape sequence. (g) These two lines of code do not produce the same output. Why? System.out.println(7 + 3); System.out.println("7 + 3"); a) Arithmetic calculations cannot take place within the println method call. b) In fact, the two statements do produce the same output. c) The quotes cause the second expression to be treated as a string. d) Because there are no escape characters. (h) Which statement starts the declaration of a class in Java? a) public static void main(string[] args) b) public class Classname c) System.out.println("Hello, World!"); d) Java class

(i) Which Java statement does not contain an error? a) System.out.print(; b) System.out.print() c) System.out.printl(); d) System.out.println(); (j) What kind of error is created by the following code snippet? System.outt.println("Hello"); a) No error: the code is correct b) Logic error: the program will run until it comes to this statement c) Syntax error: the program will not compile d) Exception: the statement will generate an exception (k) Which one of the following code snippets compiles without errors and displays the output Hello Good Day! on the screen? a) System.out.print("Hello "); System.out.println("Good Day!"); b) System.out.print("Hello ); System.out.println("Good Day!"); c) System.out.print("Hello "); System.out.println("Good Day!") d) System.out.print("Hello "); System.out.println(Good Day!"); (l) The source code for a Java program is stored in a file a) that ends with a.class suffix b) that can have any valid file name c) that ends with a.java suffix d) that has no suffix (m) A Java "class" file a) contains Java source code b) contains instructions to the Java virtual machine c) is an internal file created by the Integrated Development Environment (IDE) d) is the translation of the Java source code into C++

3. Written Solution What is the output of running the following Java programs (Be precise in showing the output including spaces and new lines). public class P1 { public static void main(string args[]) { int num=9465,d1,d2,d3,d4; d4 = (num / 1000) % 10; d3 = (num / 100) % 10; d2 = (num / 10) % 10; d1 = (num / 1) % 10; System.out.print("d4 = "); System.out.println(d4); System.out.print("d3 = "); System.out.println(d3); System.out.print("d2 = "); System.out.println(d2); System.out.print("d1 = "); System.out.println(d1); public class P2 { public static void main(string args[]) { double p=8.0, q=6.0, r=12.0, num1, num2; num1 = p + q / r; num2 = p * q + p * r % 2; System.out.print("num1 = "); System.out.println(num1); System.out.print("num2 = "); System.out.println(num2);

4. Write a Java program that computes the maximum and average of 3 numbers that are read from keyboard input. A sample run is shown below: Welcome to Maximum Calculator Enter first number (integer): 80 Enter second number (integer): 85 Enter third number (integer): 88 Maximum Score is: 88 Average Score is: 84.33

5. You have been asked to develop an algorithm to calculate the total cost of a purchase order that contains several T shirts. The cost of each T shirt and the tax rate is known. The standard shipping charge for the entire order is $5.75, and the special delivery charge is $23.65. In addition, there is no tax on the shipping cost. Which of the following is the correct pseudocode for the required algorithm? a) For each T shirt on the purchase order: Order cost = order cost + T shirt cost Total purchase order cost = order cost + tax rate + 5.75 b) For each T shirt on the purchase order: Order cost = order cost + T shirt cost If standard shipping Shipping cost = 5.75 Else Shipping cost = 23.65 Total purchase order cost = order cost * tax rate + shipping cost c) If standard shipping Shipping cost = 5.75 Else Shipping cost = 23.65 For each T shirt on the purchase order: Order cost = order cost + T shirt cost + shipping cost Total purchase order cost = order cost * tax rate d) If special delivery Shipping cost = 5.75 Else Shipping cost = 23.65 For each T shirt on the purchase order: Order cost = order cost + T shirt cost Total purchase order cost = order cost * tax rate + shipping cost

6. Imagine you are planning to purchase a new cable TV dish. You are considering two cable TV dishes that have different purchase prices. Each channel service provider charges a different rate for each month that the cable TV dish is used. To determine which cable TV dish is the better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cable TV dish. What are all of the inputs that you need for this algorithm? a) The cost of each cable TV dish and the rate for each month for using each cable TV dish b) The cost of each cable TV dish and the number of months provided with each cable TV dish c) The cost of each cable TV dish, the rate per month for using each cable TV dish, and the number of months provided with each cable TV dish d) The cost of each cable TV dish, the rate per month for using each cable TV dish, and the number of months you would use the cable TV dish. 7. What is the purpose of the following algorithm? somenum = 0 Repeat the following steps 50 times Input variable1 if variable1 > somenum somenum = variable1 Print somenum a) To find the largest of 50 numbers b) To print out the 50 numbers c) To find the smallest of 50 numbers d) To search for a particular number among 50 numbers 8. Write an algorithm to find minimum and maximum of n numbers.