Project 3: Implementing a List Map

Similar documents
CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

CMPSCI 187 / Spring 2015 Hanoi

Problem 1: Building the BookCollection application

CMPSCI 187 / Spring 2015 Hangman

Problem 1: Building and testing your own linked indexed list

Implement an ADT while using Subversion

Lab Exercise 1 Using EGit and JUnit

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

TOOLS AND TECHNIQUES FOR TEST-DRIVEN LEARNING IN CS1

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

PROBLEM SOLVING 11. July 24, 2012

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm)

Lab Exercise Test First using JUnit

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics

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

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

10 Java Collections; Equality, JUnit

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

Using git for Homework

CMPSCI 187 / Spring 2015 Sorting Kata

CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, :30pm)

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

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CSCI 200 Lab 3 Using and implementing sets

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

Programming Project 1

CS 051 Homework Laboratory #2

CS 134 Programming Exercise 2:

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

CSCI Lab 9 Implementing and Using a Binary Search Tree (BST)

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

CS 134 Programming Exercise 3:

Lab 1: Setup 12:00 PM, Sep 10, 2017

Homework #10 due Monday, April 16, 10:00 PM

Barchard Introduction to SPSS Marks

CHAPTER 1 COPYRIGHTED MATERIAL. Finding Your Way in the Inventor Interface

Barchard Introduction to SPSS Marks

LeakDAS Version 4 The Complete Guide

Stage 11 Array Practice With. Zip Code Encoding

18-Dec-09. Exercise #7, Joongle. Background. Sequential search. Consider the following text: Search for the word near

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

FILE ORGANIZATION. GETTING STARTED PAGE 02 Prerequisites What You Will Learn

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

Using Photoshop Actions in Batches

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

Project 1 Balanced binary

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

For this chapter, switch languages in DrRacket to Advanced Student Language.

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

Using the Computer for Essays

Lab Exercise 6: Abstract Classes and Interfaces CS 2334

Quartus II Tutorial. September 10, 2014 Quartus II Version 14.0

2. Getting Started When you start GeoGebra, you will see a version of the following window. 1

Comp Assignment 4: Commands and Graphics

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

CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, :30pm)

CS 4349 Lecture October 18th, 2017

CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Lab Android Development Environment

Project 2 Heap. Out: March 16 In: March Mechanics: Installing, Handing In, Demos, and Location of Documentation

Lab 5: Dreamweaver CS5, Uploading your Web site

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable

Project 6: Assembler

D Programming Language

Inf1-OP. Inf1-OP Exam Review. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. March 16, School of Informatics

CS61BL Summer 2013 Midterm 2

Text Input and Conditionals

SECTION 2: HW3 Setup.

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

1. Introduction EE108A. Lab 1: Combinational Logic: Extension of the Tic Tac Toe Game

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections

Project 5 - The Meta-Circular Evaluator

Download Free Pictures & Wallpaper from the Internet

Keep Track of Your Passwords Easily

EDGE, MICROSOFT S BROWSER

Text Generator Due Sunday, September 17, 2017

SharePoint 2010 Site Owner s Manual by Yvonne M. Harryman

Classes Classes 2 / 36

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018

Title of Resource Introduction to SPSS 22.0: Assignment and Grading Rubric Kimberly A. Barchard. Author(s)

CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L

CSCI 161: Introduction to Programming I Lab 1a: Programming Environment: Linux and Eclipse

A Quick-Reference Guide. To access reddot:

Migrating SharePoint From 2007 to 2010

ASSIGNMENT 5 Objects, Files, and More Garage Management

Input, output, and sequence

Use signatures in Outlook 2010

Burning CDs in Windows XP

Assignment 5: Part 1 (COMPLETE) Sprites on a Plane

CS159 - Assignment 2b

Introduction to Excel

Professor Program. Grading Scantron Exams

Overview of Eclipse Lectures. Module Road Map

Homework 2: Imperative Due: 5:00 PM, Feb 15, 2019

Code::Blocks Student Manual

Chapter 6 Introduction to Defining Classes

Transcription:

Project 3: Implementing a List Map CSCI 245 Programming II: Object-Oriented Design Spring 2017 Devin J. Pohly (adapted from Thomas VanDrunen) This project has two main goals: To give you practice in implementing a linked-based structure and to illustrate the workings of a map (as an example of an abstract data type). Introduction You already have worked with linked lists in CSCI 235 (or the equivalent), and we have reviewed them briefly in class. However, most students require a bit more practice at the beginning of CSCI 245 in order to have this programming technique mastered. We have recently introduced the idea of an abstract data type (ADT) in class. One of the most important things to understand is how an ADT s definition is independent of its implementation: any ADT can have many implementations with very different underlying implementation strategy. For the map ADT we have seen in class two two implementations: one using a HashMap from the Java API and one using two parallel ArrayLists. In this project you will implement a map using a linked list. Near the end of the semester we will see a more efficient implementation of a map using a technique called hashing. Secondary goals of this project include gaining more familiarity with Eclipse and JUnit. Keep in mind that this project is running in parallel with Project 2, and they are very different kinds of projects pursuing very different goals of this course. Project 2 requires you to design a set of classes and their interaction, and students designs will vary considerably; moreover, you are responsible for your own testing. This project, on the other hand, will feel much more like a lab (except that project-quality documentation is required): this description will lead you through a well-defined series of steps, correct submissions to this project will all look very similar, and all the tests are provided for you. Successful students will spread their work on Project 2 over several days as they reflect on the requirements and try out several designs; this project can be done in one sitting. Setup Unpack the starter code found at: ~devinpohly/public/csci245/project3.tar.gz Then open Eclipse and make a new project for this. When you make a new project, be sure that you uncheck the Use default location box and that the location you use is the project3 folder. Like this: 1

PROJECT 3 CSCI 245 SPRING 2017 2 To make sure you have it right, when you hit the next button on the wizard, the next screen should look like this (note the single hmllm package, project3 as the default output folder, no separate folders for source or bin ): You ll find three files in the hmllm package: HomemadeMap.java, the interface defining the map ADT; we used this same interface in class. HomemadeLLMap.java, a class implementing HomemadeMap, intended to be a linked-list implementation. It contains only method stubs; your task is to finish this class.

PROJECT 3 CSCI 245 SPRING 2017 3 HMLLMTest.java, the JUnit test class for testing your project. You may also decide to write your own driver for HomemadeLLMap to make testing more intuitive for you. You don t need to turn that file in if you do write one. Open HMLLMTest. This is the JUnit test class, containing a sequence of tests for your project. You shouldn t modify this file, and in fact you can inspect it on only an as-needed basis when you need to figure out why tests fail. Run the test by a clicking on the green circle-triangle; Eclipse will determine to run this as a JUnit test. You will see the results of running the tests, something like this: (The order of the tests may vary from one run to another.) You ll notice that one of the tests (emptyget) passes out of the box (by luck), but the others all fail. As you work through the sections below, your project will pass more and more tests. You ll know you re done when you get the green bar. Now go back to Package Explorer and open HomemadeLLMap. Your tasks The main idea is to keep the information about the associations in nodes of a linked list. Each node will contain the information about one association (a key and a value). When a new association is put in the map, a new node is added to the list. When a key s value is updated, the appropriate node must also be modified. When an association is removed, the corresponding node must be snipped out of the list. Etc. A node class Since you re implementing this using a linked list, you ll need a node class. Write one. It can be pretty similar to the examples we ve seen in class, except that it will have two datum instance variables. Write appropriate

PROJECT 3 CSCI 245 SPRING 2017 4 getter (accessor) and setter (mutator) methods. Hint: In my in-class examples, I usually do not make the datum instance variable to be mutable. In this case there will be no need to make the key mutable, but it will be convenient to make the value mutable. Make sure this class is fully documented. Don t get lazy. What instance variable or variables need to be added to HomemadeLLMap? Unfortunately the existence of the node class by itself and instance variable(s) to HomemadeLLMap don t change the outward behavior of the HomemadeLLMap class, so don t bother running the tests yet. The containskey() method Write this method for searching the list for a given key. Since you haven t implemented put() yet, at this point we can test this only on an empty list; rerun the tests (under the JUnit tab, click the icon with the green circle-triangle and little golden arrow) and make sure emptycontainskey passes. The put() method Write the method for adding a new association to this map. There are two scenarios: Is this association for a new key not already present in the map (easier), or is this a new association for an old key, overwriting a previous s put value for this key (harder). When you write this, putcontainskey should pass. (Unfortunately this does not confirm total correctness of put(), since its effects on the map can t be observed until get() is also written. Refactoring Did you notice similarity is some of the code of containskey() and put()? Both, if done right, include code for searching the list for a node with a given key. Pull this code out into a private helper method that takes a key and returns a node containing that key, or null if no such node exists. Rewrite containskey() and put() to use this helper method. Rerun the tests: this won t make any new tests pass, but you must confirm that you didn t break anything that was working before. The get() method Now write the method for retrieving the value associated with a given key. In principle this should be very simple because it can use the helper method you made in the previous step. However, it s possible that mistakes you made in earlier steps will become visible now for example, does put() work correctly in both scenarios described above? Rerun the tests: your goal is the pass emptyget, putget, and putrepalce in addition the previously passed tests. The keyiterator() method This step will be more challenging than the previous ones. This method must return an object, and instance of some class that implements the Iterator interface, that encapsulates the process of walking over the nodes in this list and gives access to the keys. So, you ll need to write such a class; the keyiterator() method merely will instantiate that class and return the instance. You can use Eclipse to help you get started. Pretend the iterator class already exists and instantiate it. Of course Eclipse will flag that as an error, but if you click on the error thing on the left border of the editor tab, you ll see that one of Eclipse s suggestions is Create class MapIterator (or whatever you called the class):

PROJECT 3 CSCI 245 SPRING 2017 5 Selecting that suggestion will lead you to a wizard for making a new class and, eventually, the code for a class that implements Iterator and has method stubs already provided. Finish this class. (Hints: The remove() method can throw an UnsupportedOperationException. If you get stuck on this, the NodeIterator from the in-class examples is nearly identical to what you need to do here. But don t look there unless you are stuck. You need to think through this one yourself. Even if you do need to look at the NodeIterator code from class, take this time to make sure you understand it.) Also, make sure your new class is properly documented. The tests emptyiterator, populatediterator, and replacediterator will exercise what you did in this step. Make sure these (and the earlier tests) pass. The remove() method The last step also is challenging. Given a key, remove the association for that key. This is hard because it requires you to snip out a node. There are five scenarios to think about: What if the list is empty? What if the node we re removing is the first one in the list? What if the node we re removing is somewhere in the middle of the list? What if the node we re removing is the last one in the list? What if the list isn t empty, but no node in the list has the key we re looking for? (Just because you have these five scenarios does not mean you will need to check for and have separate code for all five. Once you have mastered the problem you ll notice that elegant solutions can handle several of these seamlessly.)

PROJECT 3 CSCI 245 SPRING 2017 6 When this is done correctly, your code should pass the last four tests (emptyremove, populatedremove, populatedremovespurious, and removeiterator, as well as all the older tests. I got the green bar, so that means I m guaranteed to get full credit for this project, right? No. You still could be docked for incomplete documentation or glaring inefficiencies. (This project description was written to steer you away from glaring inefficiencies, but still...) Submission and grading Please turn in the completed HomemadeLLMap.java file plus the node class and iterator class you wrote by attaching them all to an email to the instructor (devin.pohly@wheaton.edu) and Cc the TA (caleb.clark@wheaton.edu). DUE: 11:59pm, Wednesday, September 28 Grading for this project will follow this approximate proportion (the right to make minor adjustments in point distribution is reserved): Correctness: 6 (This should be straightforward since you have all the test cases.) Documentation / coding style: 3 (How well does your code adhere to the documentation and style principles?) Efficiency: 3 (Are there any glaring inefficiencies? )