Beginning Programming (Java) Test 2/Version 1 CMSC 1513 Spring 2013

Similar documents
Programming I Test 2 Version 1 CS 1613 Summer 2011

Lab Exercise 1. Objectives: Part 1. Introduction

CEN 414 Java Programming

Lecture 5: Methods CS2301

Programming with Java

while (/* array size less than 1*/){ System.out.print("Number of students is invalid. Enter" + "number of students: "); /* read array size again */

Tutorial 03. Exercise 1: CSC111 Computer Programming I

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

ITERATION WEEK 4: EXMAPLES IN CLASS

Welcome to the Primitives and Expressions Lab!

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

Lesson 7 Part 2 Flags

A token is a sequence of characters not including any whitespace.

Midterm Examination (MTA)

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Java Classes: Math, Integer A C S L E C T U R E 8

Programming Languages CRN Test 2 Version 1 CMSC 4023 Autumn 2013

CS141 Programming Assignment #5

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

Introduction to Computer Science Unit 2. Notes

Loops. CSE 114, Computer Science 1 Stony Brook University

CSC 1051 Data Structures and Algorithms I

1 Short Answer (15 Points Each)

Java Coding 3. Over & over again!

Control Structures: if and while A C S L E C T U R E 4

CS141 Programming Assignment #6

CAT.woa/wa/assignments/eclipse

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Methods

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Arrays

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

Example. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct.

CSE 114 Computer Science I

Chapter 2 Elementary Programming

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

Chapter 2. Elementary Programming

CS Computers & Programming I Review_01 Dr. H. Assadipour

Chapter 2 ELEMENTARY PROGRAMMING

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

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Programming I Test 2 Revision 1 CS 1613 Spring 2004

Fundamentals of Programming Data Types & Methods

CSC 1051 Data Structures and Algorithms I

Programming I Key 1 COMSC 1613 Autumn 1999

JAVA OPERATORS GENERAL

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Java Classes: Random, Character A C S L E C T U R E 6

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved

Exercise 1: Class Employee: public class Employee { private String firstname; private String lastname; private double monthlysalary;

1 Short Answer (10 Points Each)

Introduction to Computer Science Unit 2. Notes

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

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

Controls Structure for Repetition

Chapter 6 Arrays. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

CS111: PROGRAMMING LANGUAGE II

Chapter 10. Object-Oriented Thinking

AP COMPUTER SCIENCE A

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

Warm up Exercise. What are the types and values of the following expressions: * (3 + 1) 3 / / 2.0 (int)1.0 / 2

Object Oriented Programming. Java-Lecture 6 - Arrays

JAVA Ch. 4. Variables and Constants Lawrenceville Press

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

CMPS 11 Introduction to Programming Midterm 1 Review Problems

CS110 Programming Language I. Lab 6: Multiple branching Mechanisms

CS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux

CS 112 Introduction to Programming

Elementary Programming

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

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

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

What two elements are usually present for calculating a total of a series of numbers?

1 Short Answer (5 Points Each)

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

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Place your name tag here

Chapter Goals. Chapter 5 - Iteration. Calculating the Growth of an Investment

Oct Decision Structures cont d

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

Chapter 5 Lab Methods

Chapter 2 Elementary Programming

Branching. Chapter 5 11/14/16 & 11/15/16

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

CS1150 Principles of Computer Science Arrays

CSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:

Full file at

Chapter 8 Multi-Dimensional Arrays

JAVA Programming Concepts

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Object Oriented Programming. Java-Lecture 1

double float char In a method: final typename variablename = expression ;

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging

Activity 4: Methods. Content Learning Objectives. Process Skill Goals

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Array. Array Declaration:

Prof. Navrati Saxena TA: Rochak Sachan

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

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Transcription:

1. Record your answers on SCANTRON form 882-E (It is green!) 2. Print your name on your scantron in the space labeled NAME. 3. Print CMSC 1513 in the space labeled SUBJECT. 4. Print the date, 3-28-2013, in the space labeled DATE. 5. Print your CRN, 21638, in the space labeled PERIOD. 6. Print the test number and version, T2/V1, in the space labeled TEST NO. 7. Cellular phones are prohibited. The possessor of a cellular phone will receive a zero (0) if the phone rings or is visible during the test. 8. You may use your personal calculator on this test. You are prohibited from loaning your calculator or borrowing a calculator from another person enrolled in this course. 9. Mark the best selection that satisfies the question. If selection b is better that selections a and d, then mark selection b. Mark only one selection. 10. Darken your selections completely. Make a heavy black mark that completely fills your selection. 11. Answer all 18 questions. 12. Record your answers on SCANTRON form 882-E (It is green!) 1

1. (4.2) Which diagram best illustrates the control flow of the while-? a. b. c. d. 2. (4.2) How many times is the test on line 4 executed in diagram below? 1 public class Q02 { 2 public static void main(string[] args) { 3 int count=0; 4 while (count < 10) { 5 System.out.print(count%3+" "); 6 count++; 7 } 8 System.out.println(); a. 10 b. 11 c. 3 d. 4 2

3. (4.2) What is printed by the program in the figure below? 1 public class Q02 { 2 public static void main(string[] args) { 3 int count=0; 4 while (count < 10) { 5 System.out.print(count%3+" "); 6 count++; 7 } 8 System.out.println(); a. 0 1 2 0 1 2 0 1 2 0 b. 0 1 2 3 4 5 6 7 8 9 c. 0 1 2 3 0 1 2 3 0 1 d. 0 1 0 1 0 1 0 1 0 1 4. (4.3) Which diagram best illustrates the control flow of the do-while-? a. b. c. d. 3

5. (4.3) How many times is the test on line 7 executed in diagram below? 1 public class Q05 { 2 public static void main(string[] args) { 3 int count=10; 4 do { 5 System.out.print(count%4+" "); 6 count--; 7 } while (count>0); 8 System.out.println(); a. 10 b. 11 c. 3 d. 4 6. (4.3) What is printed by the program in the figure below? 1 public class Q05 { 2 public static void main(string[] args) { 3 int count=10; 4 do { 5 System.out.print(count%4+" "); 6 count--; 7 } while (count>0); 8 System.out.println(); a. 2 1 0 3 2 1 0 3 2 1 b. 1 2 3 0 1 2 3 0 1 2 c. 3 0 1 2 3 0 1 2 3 0 d. 0 1 2 3 0 1 2 3 0 1 4

7. (4.4) Which diagram best illustrates the control flow of the for-? initialization- initialization- conditional- conditional- increment-decrement- increment-decrement- a. b. initialization- initialization- increment-decrement- increment-decrement- conditional- conditional- c. d. 5

8. (4.3) How many times is the test on line 3 executed in diagram below? 1 public class Q08 { 2 public static void main(string[] args) { 3 for (int count=0;count<10;count++){ 4 System.out.print(count%4+" "); 5 } 8 System.out.println(); a. 10 b. 11 c. 3 d. 4 9. (4.3) What is printed by the program in the figure below? 1 public class Q08 { 2 public static void main(string[] args) { 3 for (int count=0;count<10;count++){ 4 System.out.print(count%4+" "); 5 } 8 System.out.println(); a. 2 1 0 3 2 1 0 3 2 1 b. 1 2 3 0 1 2 3 0 1 2 c. 3 0 1 2 3 0 1 2 3 0 d. 0 1 2 3 0 1 2 3 0 1 6

10. (5.2)What term is used to describe the contents of the diagram below? 1 public static int max (int a, int b) 2 { int result; 3 if (a>b) 4 result=a; 5 else 6 result=b; 7 return result; 8 } a. function b. subroutine c. procedure d. method 11. (5.2)What term is used to describe the value pointed to by the arrow label f in the diagram below? public static int max ( int n, int m ) a b c d e f a. modifier b. specifier c. designator d. signifier 7

12. (5.2)What are items a and b called? public static int max ( int n, int m ) a b c d e f a. formal arguments b. actual parameters c. formal parameters d. actual arguments 13. (5.3)What is printed by the program in the diagram below? 1 public class Q13 { 2 public static int sum(int n){ 3 int t=0; 4 for (int a=0;a<=n;a++) t+=a; 5 return t; 6 } 7 public static void main(string[] args) { 8 System.out.println(sum(10)); a. 55 b. 10 c. 110 d. 11 8

14. (5.3)What is printed by the program in the diagram below? 1 public class Q14 { 2 public static int roman(int v,int d,char m){ 3 while (v>=d){ 4 System.out.print(m); 5 v=v-d; 6 } 7 return v; 8 } 9 public static void main(string[] args) { 10 int v=5324; 11 v=roman(v,1000,'m'); 12 v=roman(v, 500,'D'); 13 v=roman(v, 100,'C'); 14 v=roman(v, 50,'L'); 15 v=roman(v, 10,'X'); 16 v=roman(v, 5,'V'); 17 v=roman(v, 1,'1'); 18 } 1 a. MMMMMCCCXXIV b. MMMMMCCCXX1111 c. MMMMMCCCXXIIII d. MMMMMCCCXX1V 9

15. (5.3)What is the value is assigned to variable v on line 13? 1 public class Q14 { 2 public static int roman(int v,int d,char m){ 3 while (v>=d){ 4 System.out.print(m); 5 v=v-d; 6 } 7 return v; 8 } 9 public static void main(string[] args) { 10 int v=5324; 11 v=roman(v,1000,'m'); 12 v=roman(v, 500,'D'); 13 v=roman(v, 100,'C'); 14 v=roman(v, 50,'L'); 15 v=roman(v, 10,'X'); 16 v=roman(v, 5,'V'); 17 v=roman(v, 1,'1'); 18 } 1 a. 5324 b. 324 c. 24 d. 4 10

16. (5.3) In what order should the values listed be entered to find a monthly payment for a $100,000 loan at 3 APR for 30 years? 1 import java.util.scanner; 2 public class Q16 { 3 public static double Principal(Scanner input){ 4 System.out.print("Enter the principal. "); 5 return input.nextdouble(); 6 } 7 public static double InterestRate(Scanner input){ 8 System.out.print("Enter the APR. "); 9 return input.nextdouble()/1200; 11 public static int Term(Scanner input){ 12 System.out.print("Enter the number of years in the term. "); 13 return (int)math.round(input.nextdouble()*12); 14 } 15 public static double Payment(double P,double i,int n){ 16 return P*i/(1-Math.pow(1+i,-n)); 17 } 18 public static void main(string[] args) { 19 Scanner input=new Scanner(System.in); 20 double P=Principal(input); 21 double i=interestrate(input); 22 int n=term(input); 23 System.out.printf("$%.2f\n",Payment(P,i,n)); 24 } 25 } a. 30 3 100000 b. 100000 30 3 c. 3 100000 30 d. 100000 3 30 11

17. (5.3) What is the monthly payment for a $100,000 loan at 3 APR for 30 years? 1 import java.util.scanner; 2 public class Q16 { 3 public static double Principal(Scanner input){ 4 System.out.print("Enter the principal. "); 5 return input.nextdouble(); 6 } 7 public static double InterestRate(Scanner input){ 8 System.out.print("Enter the APR. "); 9 return input.nextdouble()/1200; 11 public static int Term(Scanner input){ 12 System.out.print("Enter the number of years in the term. "); 13 return (int)math.round(input.nextdouble()*12); 14 } 15 public static double Payment(double P,double i,int n){ 16 return P*i/(1-Math.pow(1+i,-n)); 17 } 18 public static void main(string[] args) { 19 Scanner input=new Scanner(System.in); 20 double P=Principal(input); 21 double i=interestrate(input); 22 int n=term(input); 23 System.out.printf("$%.2f\n",Payment(P,i,n)); 24 } 25 } a. $421.60 b. $417.34 c. $426.02 d. $419.46 12

18. (6.1)What is printed by the program in the diagram below? 1 public class Q18 { 2 public static int roman(int v,int d,char m){ 3 for (int a=0;a<v/d;a++) System.out.print(m); 4 return v%d; 5 } 6 public static void main(string[] args) { 7 int d[]={1000,500,100,50,10,5,1}; 8 char m[]={'m','d','l','c','x','v','i'}; 9 int v=5324; 10 for (int a=0;a<7;a++) v=roman(v,d[a],m[a]); 11 } 12 } a. mmmmmcccxxiiii b. mmmmmlllxxiiii c. mmmmmcccxxiv d. mmmmmlllxxiv 13