Homework 09. Collecting Beepers

Similar documents
Slide 1 CS 170 Java Programming 1 Testing Karel

Slide 1 CS 170 Java Programming 1

Slide 1 CS 170 Java Programming 1 Duration: 00:00:49 Advance mode: Auto

Structured Programming

The purpose of this tutorial is to introduce you to the Construct 2 program. First, you will be told where the software is located on the computer

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

Click the buttons in the interactive below to learn more about using Mail view in Outlook 2010.

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

ACM INTERNATIONAL COLLEGIATE PROGRAMMING CONTEST. California State University, Sacramento s. Contestant s Guide

contain a geometry package, and so on). All Java classes should belong to a package, and you specify that package by typing:

Lab 1: Introduction to Java

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

CS112 Lecture: Introduction to Karel J. Robot

Checking Out and Building Felix with NetBeans

Tips from the experts: How to waste a lot of time on this assignment

CS 170 Java Tools. Step 1: Got Java?

Tips from the experts: How to waste a lot of time on this assignment

Using Eclipse and Karel

Laboratory Assignment #3 Eclipse CDT

Cmpt 101 Lab 1 - Outline

Café Soylent Green Chapter 12

Introduction to Computation and Problem Solving

Express Yourself. Writing Your Own Classes

Slide 1 Java Programming 1 Lecture 2D Java Mechanics Duration: 00:01:06 Advance mode: Auto

You will always have access to the training area if you want to experiment or repeat this tutorial.

MICROSOFT VISUAL STUDIO AND C PROGRAMMING

There are four (4) skills every Drupal editor needs to master:

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

USING DRUPAL. Hampshire College Website Editors Guide

CAL 9-2: Café Soylent Green Chapter 12

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

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

New Matrix Features Version 5.5. Count on the Fly. Contact Carts Navigation Bar Improvements Goggles Market Watch Widget Stats

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

d95f-41eb-addd- 5e6eff41b083

Computer Science AP 2017 Summer Assignment Mrs. McFarland

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

Deadline. Purpose. How to submit. Important notes. CS Homework 9. CS Homework 9 p :59 pm on Friday, April 7, 2017

Lab 4 CSE 7, Spring 2018 This lab is an introduction to using logical and comparison operators in Matlab.

Process Document Student Records: Enroll Using Quick Enroll

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

Writing and Running Programs

Copied from: on 3/20/2017

Basic Fiction Formatting for Smashwords in OpenOffice L. Leona Davis. Copyright 2012 L. Leona Davis All Rights Reserved

Embed a Google File in a Google Site Page

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

AP Computer Science A Summer Assignment

ECE QNX Real-time Lab

CMSC 201 Spring 2018 Lab 01 Hello World

Here we will look at some methods for checking data simply using JOSM. Some of the questions we are asking about our data are:

Google Docs Website (Sign in or create an account):

CS112 Lecture: Defining Instantiable Classes

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Accessing Your Website Your Username and Password Personalizing Your Profile

CS201 - Assignment 3, Part 1 Due: Friday February 28, at the beginning of class

Slide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto

Announcements. 1. Forms to return today after class:

ADOBE DREAMWEAVER CS4 BASICS

How to Upgrade Your Site to the New User Interface

2007, 2008 FileMaker, Inc. All rights reserved.

the NXT-G programming environment

CS 1301 Lab 2 Introduction to Webservers at GaTech

Following a tour is the easiest way to learn Prism.

Web API Lab. The next two deliverables you shall write yourself.

Slide 1 CS 170 Java Programming 1 Arrays and Loops Duration: 00:01:27 Advance mode: Auto

Creating Accessible Excel Tutorial

Adding Content to Blackboard

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

Laboratory 1: Eclipse and Karel the Robot

Embedding Graphics in JavaDocs (netbeans IDE)

Com S 227 Assignment Submission HOWTO

SharePoint User Manual

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

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

MITOCW watch?v=flgjisf3l78

Lesson 5C MyClass Methods. By John B. Owen All rights reserved 2011, revised 2014

CS Fall Homework 5 p. 1. CS Homework 5

SharePoint SITE OWNER TRAINING

Handout 4: Version Control Reference

Week 2: The Clojure Language. Background Basic structure A few of the most useful facilities. A modernized Lisp. An insider's opinion

PBWORKS - Student User Guide

2 The Stata user interface

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

Week - 01 Lecture - 04 Downloading and installing Python

Confluence User Training Guide

Using Inspiration. Math & Life. Money. utilities, mortgage. Making Change. Budgeting. House Bills. Restaurant Bill. Bus Charge.

FanBuzz Business-Enterprise-Create A New fan Page

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

Module 1: Introduction RStudio

NetLogo Lab 3 Tutorial: Finding Peaks

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto

Guided Tour (Version 3.3) By Steven Castellucci as Modified by Brandon Haworth

AP Computer Science A Summer Assignment

Introduction to IntelliJ

How to Create Greeting Cards using LibreOffice Draw

How to Create an e-book. A Step-by-Step Illustrated Guide

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Tracking changes in Word 2007 Table of Contents

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

Transcription:

Homework 09 Collecting Beepers Goal In this lab assignment, you will be writing a simple Java program to create a robot object called karel. Your robot will start off in a world containing a series of beepers arranged in a square. Your goal is to instruct your robot to pick up all the beepers and then turn himself off. You will also write simple test cases to demonstrate that your program works correctly. Learning Objectives Familiarity with BlueJ projects Familiarity with creating a simple class Familiarity with writing simple method calls Familiarity with Karel's world Familiarity with interactive methods in BlueJ Exposure to recording simple unit tests Exposure to the Checkstyle style checker Part I: Basic Robot Control In Part I of this assignment, you will write a robot program that will direct Karel to navigate around his world and pick up all the beepers. The starting point of the world is shown below. Procedure 1. Create a Java class for your solution a. Start BlueJ on your machine. If you are working at home, make sure you have the version of BlueJ we've customized at OCC. (Ask me for help if necessary.) Create a new project in your home directory with a name of your choice (maybe hw09). A new BlueJ project is initially empty, containing no classes. b. Create a new class using the "New Class" button. Give your class the name "CollectBeepers" and choose the "Karel robot task class" template. c. Double-click on the newly created class to open an edit window. Consider resizing it to make it longer, so you can see more of the code. Read the comments carefully (they are in green). Fill in the "@author" and "@version" information in the first comment block near the top of the file. OCC CS 170. Based on material developed for CS 1705 by Stephen Edwards at Virginia Tech. Used by Permission Page 1 of 5

d. Near the bottom of the file, you will see two comments in red. The first is on a line like this: World.startFromURL( /*# place URL for world description here */ ); Replace everything between the parentheses with this URL in double quotes: "http://csjava.occ.cccd.edu/~gilberts/worlds/hw09.kwld". Your program will be able to read the description of the initial world state right off the course web site. e. Compile your program. Fix any syntax errors. After successful compilation, create an instance of your class on the object bench (refer to the BlueJ tutorial, Chapter 3, available from BlueJ's help menu if you don't remember how to do this). Right-click on your instance and invoke the task() method to see what happens (you may need to move windows around and bring Karel's world window to the front in order to see it). You have just executed your first method call on a live object. 2. Create a robot within your class a. The remaining comment asks you to "add your statements here". Delete it and replace it with this line to create a new robot: karel = new OCRobot(); b. Compile your class, create a new instance of it on the object bench, and invoke the task() method again. What is different? 3. Navigate to the first beeper a. Choose which beeper you want to pick up first. Add method calls to orient and move karel until the robot is over your chosen beeper. You can recompile your class and re-run the task() at any time to check your progress. You can also adjust the speed control that is visible when Karel's world window is open if you want the robot to move faster (initially, it runs at the slowest speed). b. Direct karel to pick up the beeper. 4. Pick up the remaining beepers a. Devise a path through the remaining beepers. Add method calls to direct karel to navigate to each beeper and pick it up in turn. Feel free to re-compile and re-run your robot task at any time to check your progress. b. Once you have added enough method calls to cause karel to pick up all the beepers, add another to turn the robot off. OCC CS 170. Based on material developed for CS 1705 by Stephen Edwards at Virginia Tech. Used by Permission Page 2 of 5

Part II: Testing In Part II of this lab assignment, you will create your own tests to demonstrate that your robot does what is required. Procedure 1. Create a class to hold your tests a. First, make sure that BlueJ's testing features are enabled. click Tools->Preferences... from BlueJ's main menu, then select the Miscellaneous tab. Make sure that "Show unit testing tools" is checked (it is at the bottom, under "Unit test settings"). Click "OK". b. Right-click your existing class and select "Create Test Class". This will create a new class to hold your tests. It will have the same name as the original, with "Test" added on the end. you can add as many tests to this one class as you like. 2. Create a test fixture a. A "test fixture" is a fancy name for a collection of objects that you want to check against some criteria. Normally, that means the objects have already been created, and that you've already sent them the methods needed to get them into the state you want to check. We'll create three objects, all on the object bench. First, create an instance of your main task class on the object bench. Then execute its task() method so that it creates your robot and then directs it to complete its work. b. Now, we want to get a reference to your robot on the object bench. Right-click your task object and invoke the new robot() method. In the dialog that follows, BlueJ will show a reference to your karel object. Select it in the list, then click the "Get" button to add your robot to the object bench. c. Finally, we want to get a reference to the robot's world on the object bench. Right-click your robot object. You'll see all of its basic methods available. Choose the "inherited from TestableRobot" submenu, then invoke the getworldasobject() method (it may be under a "more..." submenu). As before, "Get" the resulting object reference to add the robot's world to the object bench. d. Right-click the test class you created. Select "Object Bench to Test Fixture." This will record all of the objects you have on the object bench inside the test class. Now, each test that you add to this test class will be run with the current configuration of objects as its starting point. In other words, each test will be executed with three objects available, in the state after your robot task has been executed. 3. Create a test case a. A "test case" is one particular test you want to check. Normally, a test case includes a statement of what actions to perform, together with a statement of how to check whether those actions had the desired effect. Here, you've already done the first part in setting up the test fixture. Now you need to decide what to check. First, let's check that karel has some beepers. OCC CS 170. Based on material developed for CS 1705 by Stephen Edwards at Virginia Tech. Used by Permission Page 3 of 5

b. Right-click your test class and select "Create Test Method...". Give your method a meaningful name indicating what it checks. You will notice that your object bench reverts to the stored "test fixture" state for this test class and the red "recording" light on the left of BlueJ's main window comes on. c. Any actions you take now are being "recorded" as part of your test case. Right-click on your robot, and under "inherited from TestableRobot", invoke the assertbeepersinbeeperbag() method. d. Finish your test case by clicking "End" on the left of BlueJ's main window. Your test class should be recompiled automatically. Open the test class in an edit window and look through its source. Can you read it? While you have the test class open, go ahead and fill in the comments at the top of the class, just like you did with your regular robot task class. 4. Run your test a. You can run your tests by right-clicking on your test class and selecting "Test All" (run all tests in this class), or using the "Run Tests" button on the left of BlueJ's main menu (run all tests in all test classes). You can also run individual tests one at a time by right-clicking on a test class. Run your test now. b. Look at the "Test Results" dialog that opens. It lists your tests one by one in the top half, together with a "progress bar" that moves left to right as each test is executed. The bar will turn red if any test case fails. Clicking on the test case in the top half of the window will produce a description of what/how it failed in the bottom half. 5. Add more tests a. Think about what else you'd like to check to ensure that karel did the job required. Brainstorm with other students. Come up with at least three other conditions that will help ensure Karel did his job. Note that the robot object provides many methods useful for "checking" conditions in a test case. These methods are often called assertions, and are named using a pattern like assert<condition>(), for checking whether some condition is true. You can invoke these under the "inherited from TestableRobot" submenu available from your robot object. There is a similar "inherited from TestableWorld" submenu available from the world object, and it provides numerous assertions about the state of the world (rather than the state of the robot itself). b. Practice recording new test cases for the checks you have come up with. Run each test after recording it. You can also directly edit the test class source code to modify or add to an existing test case, or even to add entirely new test cases. Remember that all of the test cases are evaluated with the same collection of objects in the same state--the "test fixture". To write tests for a different collection of objects as well, usually you need to create a new test class. Also, when running lots of tests, the "speed control" that is visible when Karel's world window is shown is very useful--try turning the speed to the fastest possible speed. c. Create a test case that fails. Run it. What happens? How can you tell what went wrong in that test? OCC CS 170. Based on material developed for CS 1705 by Stephen Edwards at Virginia Tech. Used by Permission Page 4 of 5

6. Check your Style Make sure that you have first followed the lecture and configured the Checkstyle plug-in by adding cs1705_checks.xml on the Checkstyle configuration page: Then, on BlueJ's main menu, select Tools->Checkstyle... from the main menu. Check the style for the CollectBeepers class and make sure you fix any issues. You don't have to correct the issues the Checkstyle points out in your test class (mostly missing Javadoc statements) since that file was automatically written for you. 7. Submit your assignment Create a PDF document named LastFirst_hw09.pdf. Your homework should have your name on the top of the page along with these items, in this order: a. A screenshot of your completed robot task after all of the beepers have been collected and the robot shut off b. A screenshot of the JUnit test window showing that you've passed your tests as expected. c. A screenshot of the Checkstyle window showing no problems. d. Copy and paste the source code for both your CollectBeepers and your test program into your document. See the class Web page for instructions on submitting your assignment. OCC CS 170. Based on material developed for CS 1705 by Stephen Edwards at Virginia Tech. Used by Permission Page 5 of 5