PreTest.doc. That was so much fun, lets do it again :^) Name Period. 1 Beeper. 25. How many Beepers are in Karel BeeperBag?

Size: px
Start display at page:

Download "PreTest.doc. That was so much fun, lets do it again :^) Name Period. 1 Beeper. 25. How many Beepers are in Karel BeeperBag?"

Transcription

1 Name Period That was so much fun, lets do it again :^) Assume the following World for each code segment. Fill in the table below, identifying the street, avenue and direction of the Robot. Street Avenue Direction 1. Robot karel = new Robot(4, 3, North, 2) 4 3 North 2. if (karel.frontisclear()) if (karel.nexttoabeeper ()) karel.pickbeeper(); if (karel.nexttoabeeper()) karel.pickbeeper(); 7. if (karel.facingwest()) if (!karel.frontisclear()) 12. if(karel.facingeast() && karel.anybeepersinbeeperbag()) 13. if (karel.frontisclear()) if ( karel.facingeast() ) 14. How many Beepers are in karel s beeper bag? 1 Beeper Using the original World in the previous table, fill in the table below. Assume turnright has been defined Street Avenue Direction 15. Robot karel = new Robot(5, 8, West, 5) 16. if (karel.frontisclear()) 17. if (!karel.frontisclear()) 18. if (karel.frontisclear()) if ( karel.facingsouth() && karel.frontisclear() ) karel.turnleft() if (karel.nexttoabeeper()) karel.pickbeeper(); if (karel.anybeepersinbeeperbag()) 23. if (karel.facingeast()) if (karel.frontisclear() karel.turnright(); karel.turnright(); if ( karel.facingnorth() ) karel.turnright(); 24. if (karel.anybeepersinbeeperbag()) 25. How many Beepers are in Karel BeeperBag? pretest.doc

2 Consider the following four Robot classes with the constructor deleted. public class TinRobot extends Robot /* constructor not shown */ public void moveforward(int num) for(int j = 0; j < num; j++) public void oilme() if (nexttoabeeper()) pickbeeper(); if (nexttoabeeper()) pickbeeper(); public class H20_Robot extends TinRobot /* constructor not shown */ public void drink() oilme(); moveforward(3); public void fly() turnleft(); if (frontisclear()) public class RedRobot extends SmartRobot /* constructor not shown */ public void turnaround() turnleft(); turnleft(); public void hopback() turnaround(); turnaround(); public class FishRobot extends RedRobot /* constructor not shown */ public void swim() turnleft(); public void shuffle() putbeeper(); facenorth()); putbeeper(); Consider the following code fragments that construct Robots. TinRobot sn = new TinRobot(3, 4, North, 3); RedRobot rover = new RedRobot(7, 3, West, 12); H20_Robot water = new H20_Robot(5, 1, East, 2); FishRobot bait = new FishRobot (12, 6, South, 8); For each line of code below, circle if it compiles without error and draw a line through it if it is a compiler error! sn. rover.turnleft(); water.drink(); bait.oilme(); sn.oilme(); rover.moveforward(7); water.moveforward(123); bait.turnaround(); sn.drink(); rover.turnaround(); water.hopback(); bait.shuffle(); sn.turnaround(); rover.shuffle(); water.pickbeeper(); bait.putbeeper(); sn.swim(); rover.fly(); water. bait.swim(); sn.fly(); rover.facenorth(); water.fly(); bait.fly(); Fill in the table below, identifying the street, avenue, direction of the Robot and the number of beepers the Robot has in beeper bag. Assume no walls & 1 Beepers every where. Assume the Robot declarations above Street Avenue Direction Num Beep s 26. sn. 4 4 North rover.turnaround(); 7 3 East water.putbeeper(); 5 1 East bait South sn.moveforward(3); 31. sn. 32. sn.turnleft(); 33. sn.oilme(); 34. sn.oilme(); 35. rover.turnaround(); 36. rover.hopback(); 37. rover.putbeeper(); 38. rover.hopback(); 39. rover.turnleft(); 40. water.fly(); 41. water. moveforward(5); 42. water.putbeeper(); 43. water.drink(); 44. water.fly(); 45. bait.swim(); 46. bait.shuffle(); 47. bait.turnleft(); 48. bait.turnaround(); 49. bait.shuffle();

3 Consider the World shown to the Right and the following SmarterRobot declaration! Recall SmarterRobot as the following additional methods: turnaround() and turnright(). SmarterRobot bot = new SmarterRobot (3, 3, North, 5); Fill in the table below, identifying the street, avenue, direction and number of Beepers in beeper Bag. Street Avenue Direction Num Beep s 50. if (!bot.frontisclear()) bot.turnaround(); if (!bot.nexttoabeeper()) 53. bot.turnaround(); 54. if (bot.nexttoabeeper()) bot.putbeeper (); if ( bot.frontisclear() ) bot.turnright(); if (bot.nexttoabeeper()) 59. if (bot.nexttoabeeper()) 1 Beeper Just continue with what you are doing Current status 1 1 West 7 Your Robot should be here 60. /* what command List all commands */ 1 1 East if (bot.nexttoabeeper() ) 62. /* what command List all commands */ 1 3 North while(bot.frontisclear()) 64. /* what command List all commands */ 6 3 East if bot.facingnorth() ) bot.putbeeper(); bot.turnright()) 67. while(bot.frontisclear()) 68. /* what command List all commands */ 1 4 East while(!bot.nexttoabeeper()) bot.putbeeper() 70. bot.facenorth() bot.turnleft(); for(int k = 0; k < 15; k++)) bot.turnleft(); 75. while(bot.anybeepersinbeeperbag()) bot.putbeeper() 76. How many Beepers are on corner (1, 7)

4 77. if ( * 10 <= 2 * Math.pow(3, 3)) System.out.println("A winner"); System.out.println("A loser"); 78. if ( (4 * <= 6 * 7) && (3 * -2 > 3 * -3)) System.out.println("I love karel"); System.out.println("I love Alice"); 79. if ( (4 * 15 <= 7 * 7) && (3 * 7 >= 5 * 4) ) System.out.println("I love math"); System.out.println("I love comp sci"); Use the following variables to answer questions #80-83 int num = 10, value = 25, negnum = -10, x = 25; 80. if ( num > x + negnum) System.out.println(num + " wins"); System.out.println(num + " loses"); 81. if ( 3 * num > x - negnum) System.out.println("2 * " + num + " wins"); System.out.println(negNum + " wins"); 82. if ( (2 * num!= -negnum + 5) &&!(value / num == 2) ) System.out.println("AND wins" ); System.out.println("AND Loses"); 83. if ( (x % 2 == 0) (value % 15 - x < 0) ) System.out.println("OR wins"); System.out.println("OR Loses"); 84. if ( (2 < -1) (5 > -6) && (7 < 11)) System.out.println("I am really confused"); System.out.println("No, I am not confused"); 85. if ( (-2 < -1) (-5 > -5) (7 < -11)) System.out.println("I love if statements"); System.out.println("I love conditionals"); 86. if ( (-2 < -1) && (5 > -6) && (7 < 11)) System.out.println("Fight on"); System.out.println("whine more"); 87. if ( -2 < -1 ) if ( (2-3 * -4) > (3 * 5 - (3-8) ) ) System.out.println("A nested if"); System.out.println(" in nested if"); System.out.println("Failed nested if"); 88. if ( 2 < -1 ) if ( (2-3 * -4) < (3 * 5 - (5-7) ) ) System.out.println("Another if" ); System.out.println("then- if"); if ( (2-3 * 4) < (3 * 5 - (25-7) ) ) System.out.println("-then if"); System.out.println("^2 nested if"); 89. if ( % 11 > 11 / 2) System.out.println("a toughie"); System.out.println("an easy one!"); 90. System.out.print("A"); System.out.println(" cat in"); System.out.print("the ); System.out.println("hat"); System.out.println("is a"); System.out.print("Dr."); System.out.println("Seuss"); System.out.print("Book");

5 Consider the following class definition: public class Functions public int fun1(int a, int b) return 5 * a - 3 * b - 7; public int fun2(int x, int y) int ans = 2 * x + y - 1; if (x <= y) ans = x * ans + y; ans = y * ans + x; return 10 + ans / 2; Give the output for the following code segments. Also assume SOP is System.out.println() 91. System.out.println( myf.fun1(0, 0) ); System.out.println( myf.fun1(2, 5) ); System.out.println( myf.fun1(4, 7) ); System.out.println( myf.fun1(11, 3) ); System.out.println( myf.fun1(-2, -5) ); 92. System.out.println( myf.fun2(0, 0) ); System.out.println( myf.fun2(2, 5) ); System.out.println( myf.fun2(-2, -5) ); 93. System.out.println( myf.myfun(0, 0, 0) ); public int myfun(int x, int y, int z) int ans = 0; if (x > y && x < z) ans = 2 * x + y - z; ans = x + 2 * y + z; ans--; return ans; System.out.println( myf.myfun(2, 5, 1) ); System.out.println( myf.myfun(2, 1, 3) ); 94. System.out.println( myf.morefun(2, 5) ); System.out.println( myf.morefun(8, 3) ); System.out.println( myf.morefun(6, 3) ); public double morefun(int val, int num) double ans = Math.pow(val, num) - val % num; if (ans < 100) ans = ans % 100.; ans++; return ans; public String wordmaker(string str, int s) String ans = "pre" + str; if (s % 2 == 0) ans = str + "ing"; ans = str + "s"; return ans; 95. System.out.println( myf.wordmaker("fop", 0)); System.out.println( myf.wordmaker("ict", 1)); System.out.println( myf.wordmaker("troy", 3)); System.out.println( myf.wordmaker("fresh", 2)); Use the following variables to answer questions #96-98 Functions myf = new Functions(); int value = 20, negnum = -10; 96. System.out.println(myF.fun1(myF.fun1(value, 20), negnum)); 97. System.out.println(myF.fun1(myF.fun2(value, 1), myf.fun2(5, 1))); 98. System.out.println(myF.myFun(2 * 3 + 1, (5 + 2 * 4) % 5, / 3));

6 Give the output for the following code segments. Also assume SOP is System.out.println() 99. public void loops1() for(int j = 1; j <= 10; j = j + 2) int value = 2 * j + 1; System.out.println(j + " " + value); 100.public void loops2() for(int j = 0; j < 5; j++) int value = j * j - 3; System.out.println(j + " " + value); 101.public void loops3() for(int j = 5; j <= 11; j = j + 2) int k = 1; while(k < j) System.out.println(j + " : " + k); K = k + 3; 102.public void loops4() for(int j = 1; j <= 100; j = j * 3) int k = 1; while(k <= j) k = k 1; System.out.println(j + : + k); k = k + 20; 103.loops5(98045); public void loops5(int j) while(j > 0) int num = j % 10; System.out.println(num); j = j / 10; 104.Calculate twice. Once for loops6(5) & for loops6(9); public void loops6(int j) int ans = 1; while(j > 0) ans = ans * j; j--; System.out.println(ans); 105.Calculate twice. Once for loops7(2, 8) & for loops7(4, 9); public void loops7(int j, int k) for(int ind = 0; ind < j; ind++) for(int inner = ind; inner < k; inner = inner+2) if ( 2 * ind - inner > 0) System.out.print( positive ); System.out.print( negative ); System.out.println( is it over yet? );

7 Consider the following nested loops which instantiate (construct) Robots which put a beeper on their corner before being turned off. Robot karel; for (int j = 0; j < 20; j = j + 3) for (int k = 1; k < 10; k = k + 4) karel = new Robot(j + 1, 2 * k + 1, East, 9); True/false: A beeper has been put at the following corner locations (street, avenue). (1,1) (5, 5) (4, 15) (19, 11) (10, 19) (1, 3) (19, 10) (16, 11) (15, 9) (17, 11) For each set of output, write a (for/while) loop that generates the same output * 3 * 5 * 7 * 9 * 11 * 13 = correctanswer //== Sample written questions Consider the partially define class. You will implement the three methods collectbeepersinrow, movetosecondcornerwithabeeper and task public class PreTestRobot extends SmarterRobot public PreTestRobot (int st, int ave, Direction dir, int num) super(st, ave, dir, num); public void directionalmove() /* to be implement by you in part A */ public void movetosecondcornerwithabeeper() /* to be implement by you in part B */ public void task() /* to be implement by you in part C */ <somevalue> = correctanswer A. Implement the method directionalmove which moves the Robot as follows: If the Robot is facing East or West, the Robot should move in its current direction forward 5 corners. Otherwise, the Robot should move in its current direction forward 3 corners. You may assume that there will be NO walls in the way! public void directionalmove() * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = correctanswer //== 1024

8 B. Implement the method movetosecondcornerwithabeeper which causes the Robot forward (without turning) until the Robot is on a corner with at least one beeper. The Robot should repeat this process a second time. If the Robot starts on a corner with a beeper, that is consider to be the first corner encountered by the Robot. Therefore, the minimum distance this method may move a Robot is one corner! public void movetosecondcornerwithabeeper () C. Implement the method task which causes the Robot to perform the following maneuvers! i. Starting at its current location, if the Robot is facing East or West, the Robot should move in its current direction forward 5 corners. Otherwise, the Robot should move in its current direction forward 3 corners. You may assume that there will be NO walls in the way! ii. At the end of step I, if there is a wall in front of the Robot, the Robot should turn right, otherwise the Robt should turn left. iii. The Robot should move forward (without worrying about walls) to the second corner that has at least one beeper on it. If the Robot is on a corner with a Beeper, this qualifies as the first corner. iv. The Robot should move East one corner and then empty its beeper bag. In implementing the task method, you may assume that (and should use) directionalmove and movetosecondcornerwithabeeper work as intended regardless of what you wrote. public void task()

Numeric answers: select letters to total to your answer. For example 3 = d and e, 11 = b, d and e & 17 = a and e. a) 16 b) 8 c) 4 d) 2 e) 1

Numeric answers: select letters to total to your answer. For example 3 = d and e, 11 = b, d and e & 17 = a and e. a) 16 b) 8 c) 4 d) 2 e) 1 Name Period Fill in the table below, identifying the street, avenue and direction of the Robot. (Assume no walls) Answer using the following key Directions: a) North b) South c) East d) West Numeric answers:

More information

AP CS A Karel J Robot Review Sheet Chapters 5-6

AP CS A Karel J Robot Review Sheet Chapters 5-6 AP CS A Karel J Robot Review Sheet Chapters 5-6 Name: Date: Per: 1. List the 8 primitive predicates that can be used in an if clause: 2. In order for a new class (subclass) that you write to be able to

More information

We know have to navigate between Karel s World view, Karel s Program view and Karel s Execution (or Run) view.

We know have to navigate between Karel s World view, Karel s Program view and Karel s Execution (or Run) view. We know how to write programs using Karel s primitive commands move turnleft pickbeeper putbeeper turnoff We know have to navigate between Karel s World view, Karel s Program view and Karel s Execution

More information

We know how to navigate between Karel s World view, Karel s Program view and Karel s Execution (or Run) view.

We know how to navigate between Karel s World view, Karel s Program view and Karel s Execution (or Run) view. We know how to write programs using Karel s primitive commands move turnleft pickbeeper putbeeper turnoff We know how to navigate between Karel s World view, Karel s Program view and Karel s Execution

More information

CS112 Lecture: Extending Classes and Defining Methods

CS112 Lecture: Extending Classes and Defining Methods Objectives: CS112 Lecture: Extending Classes and Defining Methods Last revised 1/9/04 1. To introduce the idea of extending existing classes to add new methods 2. To introduce overriding of inherited methods

More information

CS112 Lecture: Introduction to Karel J. Robot

CS112 Lecture: Introduction to Karel J. Robot CS112 Lecture: Introduction to Karel J. Robot Last revised 1/17/08 Objectives: 1. To introduce Karel J. Robot as an example of an object-oriented system. 2. To explain the mechanics of writing simple Karel

More information

CS 106A, Lecture 3 Problem-solving with Karel

CS 106A, Lecture 3 Problem-solving with Karel CS 106A, Lecture 3 Problem-solving with Karel suggested reading: Karel, Ch. 5-6 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5

More information

CS 106A, Lecture 3 Problem-solving with Karel

CS 106A, Lecture 3 Problem-solving with Karel CS 106A, Lecture 3 Problem-solving with Karel suggested reading: Karel, Ch. 5-6 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5

More information

1. What does the following code fragment write to the monitor?

1. What does the following code fragment write to the monitor? 1. What does the following code fragment write to the monitor? int sum = 14; if ( sum < 20 ) System.out.print("Under "); else System.out.print("Over "); System.out.println("the limit."); a. Under b. Over

More information

Introduction to Computer Science I Spring 2010 Sample mid-term exam Answer key

Introduction to Computer Science I Spring 2010 Sample mid-term exam Answer key Introduction to Computer Science I Spring 2010 Sample mid-term exam Answer key 1. [Question:] (15 points) Consider the code fragment below. Mark each location where an automatic cast will occur. Also find

More information

Quarter 1 Practice Exam

Quarter 1 Practice Exam University of Chicago Laboratory Schools Advanced Placement Computer Science Quarter 1 Practice Exam Baker Franke 2005 APCS - 12/10/08 :: 1 of 8 1.) (10 percent) Write a segment of code that will produce

More information

Before we start: Any questions on Karel?

Before we start: Any questions on Karel? Control Flow Before we start: Any questions on Karel? Newspaper Karel Any trouble implementing this task? Karel can also repair Karlův! That s fun!... but a robot should get prepared for the dangers of

More information

Robots. Byron Weber Becker. chapter 6

Robots. Byron Weber Becker. chapter 6 Using Variables Robots Learning to Program with Java Byron Weber Becker chapter 6 Announcements (Oct 3) Reminder: Reading for today y( (Oct 3 rd ) Ch 6.1-6.4 Reading for Wednesday (Oct 3 rd ) The rest

More information

Introduction to Computer Science Unit 2. Exercises

Introduction to Computer Science Unit 2. Exercises Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the

More information

Asking For Help. BIT 115: Introduction To Programming 1

Asking For Help. BIT 115: Introduction To Programming 1 Asking For Help Start homeworks As Soon As Possible You may post homework questions to Canvas: Please do not cut and paste entire lines of code, but rather ask conceptual questions. You may also ask me

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

Assignment #1: /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th

Assignment #1:  /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th Mehran Sahami Handout #7 CS 06A September 8, 06 Assignment #: Email/Survey and Karel the Robot Karel problems due: :0pm on Friday, October 7th Email and online survey due: :9pm on Sunday, October 9th Part

More information

Specification Load Mountain.java and study its method explore(). Complete the Exercises on the next page.

Specification Load Mountain.java and study its method explore(). Complete the Exercises on the next page. Lab07 Exploration Objective Polymorphism. Background Some other variations on creating an object: Robot karel = new Robot(); Robot lisa; lisa = new Robot(); Robot maria; maria = new Athlete(); Robot maria

More information

Mehran Sahami Handout #7 CS 106A September 24, 2014

Mehran Sahami Handout #7 CS 106A September 24, 2014 Mehran Sahami Handout #7 CS 06A September, 0 Assignment #: Email/Survey and Karel the Robot Karel problems due: :pm on Friday, October rd Email and online survey due: :9pm on Sunday, October th Part I

More information

Introduction to Java

Introduction to Java Introduction to Java Announcements Programming Assignment #1 Out: Karel the Robot: Due Friday, January 20 at 3:15 PM. Email: Due Sunday, January 22 at 11:59PM. Section Assignments Posted Check online at

More information

IS12 - Introduction to Programming

IS12 - Introduction to Programming IS12 - Introduction to Programming Lecture 5: Loops Peter Brusilovsky http://www2.sis.pitt.edu/~peterb/0012-051/ The iterate instruction How to repeat an action known number of times? iterate

More information

Practice Midterm 1 Answer Key

Practice Midterm 1 Answer Key CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages

More information

Programming in Karel. Eric Roberts and Jerry Cain CS 106J April 5, 2017

Programming in Karel. Eric Roberts and Jerry Cain CS 106J April 5, 2017 Programming in Karel Eric Roberts and Jerry Cain CS 106J April 5, 2017 Once upon a time... Rich Pattis and Karel the Robot Karel the Robot was developed by Rich Pattis in the 1970s when he was a graduate

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018 Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment

More information

ASSIGNMENT 4 Classes and Objects

ASSIGNMENT 4 Classes and Objects ASSIGNMENT 4 Classes and Objects COMP-202A, Fall 2010, All Sections Due: Friday, November 19, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all

More information

Assignment #1: and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th due: 11:59pm on Sunday, October 6th

Assignment #1:  and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th  due: 11:59pm on Sunday, October 6th Mehran Sahami Handout #7 CS 06A September, 0 Assignment #: Email and Karel the Robot Karel problems due: :pm on Friday, October th Email due: :9pm on Sunday, October 6th Part I Email Based on a handout

More information

Lecture 11. Instructor: Craig Duckett. Instance Variables

Lecture 11. Instructor: Craig Duckett. Instance Variables Lecture 11 Instructor: Craig Duckett Instance Variables Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section 1: Wednesday,

More information

ASSIGNMENT 3 Classes, Objects and the Robot World

ASSIGNMENT 3 Classes, Objects and the Robot World ASSIGNMENT 3 Classes, Objects and the Robot World COMP-202B, Winter 2009, All Sections Due: Tuesday, March 3, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified, you

More information

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017 Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method

More information

IS12 - Introduction to Programming. Lecture 6: Advanced Programming with Karel. Peter Brusilovsky

IS12 - Introduction to Programming. Lecture 6: Advanced Programming with Karel. Peter Brusilovsky IS12 - Introduction to Programming Lecture 6: Advanced Programming with Karel Peter Brusilovsky http://www2.sis.pitt.edu/~peterb/0012-051/ if inside while Using if inside while will help us to solve a

More information

Computer Science 1 Honors

Computer Science 1 Honors Computer Science 1 Honors Will be Most methods are too complex simply to call them and let them do their job. Methods almost always need more information. For example, a method that finds a square root,

More information

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

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007 Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max

More information

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

Definite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting Unit 2, Part 2 Definite Loops Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting Let's say that we're using a variable i to count the number of times that

More information

Solutions to Midterm Exam

Solutions to Midterm Exam Nick Troccoli Midterm Solutions CS 106A August 2, 2017 Solutions to Midterm Exam Problem 1: Karel the Robot public class FarmerKarel extends SuperKarel { checkrow(); while (leftisclear()) { movetonextrow();

More information

BIT 115: Introduction To Programming LECTURE 3. Instructor: Craig Duckett

BIT 115: Introduction To Programming LECTURE 3. Instructor: Craig Duckett BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett cduckett@cascadia.edu Lecture 3 Announcements By now everyone should be up and running with Java, jgrasp, and the Becker Robots

More information

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

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

Developing and Reusing Methods

Developing and Reusing Methods Developing and Reusing Methods 3 In Chapter 2, we wrote new services such as turnright and turnaround. These services were very simple, consisting of only a few steps to accomplish the task. In this chapter,

More information

Practice with variables and types

Practice with variables and types Practice with variables and types 1. Types. For each literal or expression, state its type (String, int, double, or boolean). Expression Type Expression Type 387 "pancakes" true 45.0 "14" 87.98515 "false"

More information

Slide 1 CS 170 Java Programming 1 Testing Karel

Slide 1 CS 170 Java Programming 1 Testing Karel CS 170 Java Programming 1 Testing Karel Introducing Unit Tests to Karel's World Slide 1 CS 170 Java Programming 1 Testing Karel Hi Everybody. This is the CS 170, Java Programming 1 lecture, Testing Karel.

More information

Practice with variables and types

Practice with variables and types Practice with variables and types 1. Types. For each literal or expression, state its type (String, int, double, or boolean). Expression Type Expression Type 387 int "pancakes" String true boolean 45.0

More information

CPSC 219 Extra review and solutions

CPSC 219 Extra review and solutions CPSC 219 Extra review and solutions Multiple choice questions: Unless otherwise specified assume that all necessary variable declarations have been made. For Questions 1 6 determine the output of the print()

More information

Practice Midterm Examination #1

Practice Midterm Examination #1 Eric Roberts Handout #35 CS106A May 2, 2012 Practice Midterm Examination #1 Review session: Sunday, May 6, 7:00 9:00 P.M., Hewlett 200 Midterm exams: Tuesday, May 8, 9:00 11:00 A.M., CEMEX Auditorium Tuesday,

More information

Practice Midterm Examination #2

Practice Midterm Examination #2 Eric Roberts Handout #34 CS 106A February, 2016 Practice Midterm Examination #2 Review session: Monday, February 8, 6:30 8:00 P.M., NVIDIA Auditorium Midterm exams: Tuesday, February 9, 9:00 11:00 A.M.,

More information

Primitive Data, Variables, and Expressions; Simple Conditional Execution

Primitive Data, Variables, and Expressions; Simple Conditional Execution Unit 2, Part 1 Primitive Data, Variables, and Expressions; Simple Conditional Execution Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Overview of the Programming Process Analysis/Specification

More information

Instructor: Craig Duckett

Instructor: Craig Duckett Instructor: Craig Duckett cduckett@cascadia.edu Announcements Assignment 1 Due Lecture 5 by MIDNIGHT I will double dog dare try to have Assignment 1 graded and back to you by Wednesday, January 24 th hopefully

More information

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel Jerry Cain Handout #5 CS 106AJ September 30, 2017 Using JSKarel This handout describes how to download and run the JavaScript version of Karel that we ll be using for our first assignment. 1. Getting started

More information

CoSc Lab # 8 (an array of a class) Due Date: Part I, Experiment classtime, Tuesday, Dec 4 th, 2018.

CoSc Lab # 8 (an array of a class) Due Date: Part I, Experiment classtime, Tuesday, Dec 4 th, 2018. CoSc 10403 Lab # 8 (an array of a class) Due Date: Part I, Experiment classtime, Tuesday, Dec 4 th, 2018. Part II, Program - by midnight, Tuesday, Dec 4 th, 2018. Part I is the Experiment component and

More information

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011 CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011 Name: This exam consists of 12 problems on the following 11 pages. You may use your single- side hand- written 8 ½ x 11 note sheet during the

More information

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool Chapter 3: Selections and Conditionals CS1: Java Programming Colorado State University Motivations If you assigned a negative value for radius in Listing 2.2, ComputeAreaWithConsoleInput.java, the program

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming Casual Dinner for Women in CS Next Thursday, January 24 in Gates 219 at 6:00PM. Good food, great company, and everyone is invited! RSVP through email link (sent out earlier

More information

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Term 1 Unit 1 Week 1 Worksheet: Output Solution 4 Term 1 Unit 1 Week 1 Worksheet: Output Solution Consider the following what is output? 1. System.out.println("hot"); System.out.println("dog"); Output hot dog 2. System.out.print("hot\n\t\t"); System.out.println("dog");

More information

King Saud University College of Computer and Information Sciences Computer Science Department

King Saud University College of Computer and Information Sciences Computer Science Department King Saud University College of Computer and Information Sciences Computer Science Department Course Code: CSC 111 Course Title: Introduction to Programming 1 Semester: Fall 2017-18 Exercises Cover Sheet:

More information

WES-CS GROUP MEETING #9

WES-CS GROUP MEETING #9 WES-CS GROUP MEETING #9 Exercise 1: Practice Multiple-Choice Questions 1. What is output when the following code executes? String S1 = new String("hello"); String S2 = S1 +! ; S1 = S1 + S1; System.out.println(S1);

More information

Laboratory 1: Eclipse and Karel the Robot

Laboratory 1: Eclipse and Karel the Robot Math 121: Introduction to Computing Handout #2 Laboratory 1: Eclipse and Karel the Robot Your first laboratory task is to use the Eclipse IDE framework ( integrated development environment, and the d also

More information

DATA TYPES AND EXPRESSIONS

DATA TYPES AND EXPRESSIONS DATA TYPES AND EXPRESSIONS Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment Mathematical

More information

Programming Karel the Robot

Programming Karel the Robot Programming Karel the Robot Announcements Five Handouts Today: Honor Code Downloading Eclipse Running Karel Programs in Eclipse Programming Assignment #1 Submitting Programming Assignments Please only

More information

CS 307 Midterm 2 Spring 2011

CS 307 Midterm 2 Spring 2011 Points off 1 2 3 4 5 Total off Net Score Exam Number: CS 307 Midterm 2 Spring 2011 Name UTEID login name TA's Name: Dan Muhibur Oliver (Circle One) Instructions: 1. Please turn off your cell phones and

More information

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm CIS 110 Introduction To Computer Programming February 29, 2012 Midterm Name: Recitation # (e.g. 201): Pennkey (e.g. bjbrown): My signature below certifies that I have complied with the University of Pennsylvania

More information

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

L o o p s. for(initializing expression; control expression; step expression) { one or more statements } L o o p s Objective #1: Explain the importance of loops in programs. In order to write a non trivial computer program, you almost always need to use one or more loops. Loops allow your program to repeat

More information

Practice Questions for Chapter 9

Practice Questions for Chapter 9 Practice Questions for Chapter 9 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) An object is an instance of a. 1) A) program B) method C) class

More information

CS112 Lecture: Loops

CS112 Lecture: Loops CS112 Lecture: Loops Objectives: Last revised 3/11/08 1. To introduce some while loop patterns 2. To introduce and motivate the java do.. while loop 3. To review the general form of the java for loop.

More information

Today. Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator

Today. Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator Today Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator BIT 115: Introduction To Programming 1 Something to Remember: In parameter order,

More information

Question 1: public class BlankKarel extends SuperKarel { public void run() { while (frontisclear()) { walkarow(); move(); } walkarow(); // fencepost }

Question 1: public class BlankKarel extends SuperKarel { public void run() { while (frontisclear()) { walkarow(); move(); } walkarow(); // fencepost } Question 1: public class BlankKarel extends SuperKarel { public void run() { while (frontisclear()) { walkarow(); walkarow(); // fencepost public void walkarow() { turnleft(); while(frontisclear() && leftisblocked()

More information

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2013

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2013 CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2013 Name: This exam consists of 5 problems on the following 7 pages. You may use your two- sided hand- written 8 ½ x 11 note sheet during the exam.

More information

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed 1 1 COMP200 INTERFACES OOP using Java, from slides by Shayan Javed Interfaces 2 ANIMAL picture food sleep() roam() makenoise() eat() 3 ANIMAL picture food sleep() roam() makenoise() eat() 4 roam() FELINE

More information

Robots. Byron Weber Becker. chapter 6

Robots. Byron Weber Becker. chapter 6 Using Variables Robots Learning to Program with Java Byron Weber Becker chapter 6 Announcements (Oct 5) Chapter 6 You don t have to spend much time on graphics in Ch6 Just grasp the concept Reminder: Reading

More information

CS 305j Midterm 1 Fall 2007

CS 305j Midterm 1 Fall 2007 Points off 1 2 3 4 5 6 7 Total off Net Score CS 305j Midterm 1 Fall 2007 Your Name Your UTEID Circle you TA's name: Priyanka Jacob Instructions: 1. Please turn off your cell phones 2. There are 7 questions

More information

Chapter 7: Iterations

Chapter 7: Iterations Chapter 7: Iterations Objectives Students should Be able to use Java iterative constructs, including do-while, while, and for, as well as the nested version of those constructs correctly. Be able to design

More information

CIS 110 Introduction To Computer Programming. December 19th, 2011 Final. Answer key

CIS 110 Introduction To Computer Programming. December 19th, 2011 Final. Answer key CIS 110 Introduction To Computer Programming December 19th, 2011 Final Answer key CIS 110 final instructions You have 120 minutes to finish this exam. Time will begin when called by a proctor and end precisely

More information

Final Exam. COMP Summer I June 26, points

Final Exam. COMP Summer I June 26, points Final Exam COMP 14-090 Summer I 2000 June 26, 2000 200 points 1. Closed book and closed notes. No outside material allowed. 2. Write all answers on the test itself. Do not write any answers in a blue book

More information

Lesson 36: for() Loops (W11D1)

Lesson 36: for() Loops (W11D1) Lesson 36: for() Loops (W11D1) Balboa High School Michael Ferraro October 26, 2015 1 / 27 Do Now Create a new project: Lesson36 Write class FirstForLoop: Include a main() method: public static void main(string[]

More information

Practice Midterm Examination

Practice Midterm Examination Nick Troccoli Practice Midterm CS 106A July 18, 2017 Practice Midterm Examination Midterm Time: Monday, July 24th, 7:00P.M. 9:00P.M. Midterm Location: Hewlett 200 Based on handouts by Mehran Sahami, Eric

More information

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

Computer Applications Answer Key Class IX December 2017

Computer Applications Answer Key Class IX December 2017 Computer Applications Answer Key Class IX December 2017 Question 1. a) What are the default values of the primitive data type int and float? Ans : int = 0 and float 0.0f; b) Name any two OOP s principle.

More information

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

Final Exam Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 17 December 2009

Final Exam Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 17 December 2009 Final Exam Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 17 December 2009 NAME (Printed) NAME (Signed) E-mail Exam Rules Show all your work. Your grade will

More information

Using Machine Learning to Model How Students Learn to Program

Using Machine Learning to Model How Students Learn to Program Using Machine Learning to Model How Students Learn to Program (a.k.a. Learning about Learning) Machine Human Mehran Sahami Computer Science Department sahami@cs.stanford.edu Joint work with Chris Piech,

More information

I. True/False: (2 points each)

I. True/False: (2 points each) CS 102 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2008 What is your name?: (2 points) There are three sections: I. True/False..............54 points; (27 questions, 2 points each)

More information

Section Handout #7: Interactors and Classes

Section Handout #7: Interactors and Classes Chris Piech Section #7 CS 106A February 26, 2018 Section Handout #7: Interactors and Classes Portions of this handout by Eric Roberts and Nick Troccoli Overview: these problems will give you practice with

More information

Question Bank. 4. Write a menu driven program to accept two numbers and find a. HCF / GCD b. LCM

Question Bank. 4. Write a menu driven program to accept two numbers and find a. HCF / GCD b. LCM Question Bank 1. Write a program using over loading function with name as area to calculate a. Area of a square (side * side) b. Area of a rectangle (length * breadth) c. Area of a circle. ( * radius *

More information

Final Examination Semester 3 / Year 2007

Final Examination Semester 3 / Year 2007 Southern College Kolej Selatan 南方学院 Final Examination Semester 3 / Year 2007 COURSE : FUNDAMENTALS OF SOFTWARE DESIGN AND DEVELOPMENT COURSE CODE : PROG1003 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE

More information

CS112 Lecture: Repetition Statements

CS112 Lecture: Repetition Statements CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general

More information

Key Points. COSC 123 Computer Creativity. Java Decisions and Loops. Making Decisions Performing Comparisons. Making Decisions

Key Points. COSC 123 Computer Creativity. Java Decisions and Loops. Making Decisions Performing Comparisons. Making Decisions COSC 123 Computer Creativity Java Decisions and Loops Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) A decision is made by evaluating a condition in an if/

More information

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

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

ASSIGNMENT 4 Records and Objects

ASSIGNMENT 4 Records and Objects ASSIGNMENT 4 Records and Objects COMP-202B, Winter 2010, All Sections Due: Wednesday, March 31, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all

More information

1. Find the output of following java program. class MainClass { public static void main (String arg[])

1. Find the output of following java program. class MainClass { public static void main (String arg[]) 1. Find the output of following java program. public static void main(string arg[]) int arr[][]=4,3,2,1; int i,j; for(i=1;i>-1;i--) for(j=1;j>-1;j--) System.out.print(arr[i][j]); 1234 The above java program

More information

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise Tutorial # 4 Q1. Evaluate the logical (Boolean) expression in the following exercise 1 int num1 = 3, num2 = 2; (num1 > num2) 2 double hours = 12.8; (hours > 40.2) 3 int funny = 7; (funny!= 1) 4 double

More information

Computer Science 145

Computer Science 145 Name: Computer Science 145 Final Exam Answer Sheet Fall 2016 1. a b c d 8. 2. a b c d 9. a b c d 3. a b c d e 10. a b c d 4. a b c d 11. 5. a b c d 12. 6. 13. 7. 14. a b c d 15. 16. 17. 1 18. 19. 2 20.

More information

The Basic Parts of Java

The Basic Parts of Java Data Types Primitive Composite The Basic Parts of Java array (will also be covered in the lecture on Collections) Lexical Rules Expressions and operators Methods Parameter list Argument parsing An example

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

More information

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

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name CSC 1051 Algorithms and Data Structures I Final Examination May 12, 2017 Name Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces provided.

More information

COE 211 Computer Programming. Welcome to Exam I Tuesday March 13, 2018

COE 211 Computer Programming. Welcome to Exam I Tuesday March 13, 2018 1 COE 211 Computer Programming Welcome to Exam I Tuesday March 13, 2018 Instructors: Dr. Dima El-khalil Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book. Please do not forget

More information

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts

More information

c Joseph Culberson Janelle Harms Herb Yang

c Joseph Culberson Janelle Harms Herb Yang c Joseph Culberson Janelle Harms Herb Yang June 22, 2011 Contents Preface ix About.................................. ix Target Audience............................ ix Motivation...............................

More information

COSC 123 Computer Creativity. Java Decisions and Loops. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 123 Computer Creativity. Java Decisions and Loops. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Java Decisions and Loops Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) A decision is made by evaluating a condition in an if/else

More information

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

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

More information

Lesson 14 - Activity 1

Lesson 14 - Activity 1 13 Lesson 14 - Activity 1 / Term 1: Lesson 14 Coding Activity 1 Test if an integer is not between 5 and 76 inclusive. Sample Run 1 Enter a number: 7 False Sample Run 2 Enter a number: 1 True / class Lesson_14_Activity_One

More information

Practice Midterm 1. Problem Points Score TOTAL 50

Practice Midterm 1. Problem Points Score TOTAL 50 CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the

More information

Java Review. Fundamentals of Computer Science

Java Review. Fundamentals of Computer Science Java Review Fundamentals of Computer Science Link to Head First pdf File https://zimslifeintcs.files.wordpress.com/2011/12/h ead-first-java-2nd-edition.pdf Outline Data Types Arrays Boolean Expressions

More information