Unformatted text preview:

Handout P1IntroductionGetting startedIntroducing Continuous TestingProblemsProblem 1: RatNum (24 points)Problem 2: RatPoly (45 points)Problem 3: RatPolyStack (30 points)Problem 4: PolyCalc (1 point)Reflection (1 point)Provided classesHintsErrataQ & A6.170 Laboratory in Software Engineering Spring 2005 Problem Set 1: Java and Coding to Specification Due: Thursday, September 22, 2005 at 1:00 PM Handout P1 Quick links: • Specifications • Provided source code (in the assignments section) • Problem set submission (in the assignments section) Contents: • Introduction • Getting started • Introducing Continuous Testing • Problems o Problem 1: RatNum (24 points) o Problem 2: RatPoly (45 points) o Problem 3: RatPolyStack (30 points) o Problem 4: PolyCalc (1 point) • Provided classes o Hints o Errata o Q & A We recommend that you read the entire problem set before you begin work. Introduction In this problem set, you will practice reading and interpreting specifications, as well as reading and writing Java source code. You will implement a pair of classes that will complete the implementation of a graphing polynomial calculator, and you will answer questions about both the code you are given and the code you have written. To complete this problem set, you will need to know: 1. Basic algebra (rational and polynomial arithmetic) 2. How to read and write basic Java codeo code structure and layout (class and method definition, field and variable declaration) o method calls o operators for:  object creation: new  field and method access: .  assignment: =  comparison: ==, !=, <, >, <=, >=  arithmetic: +, -, *, / o control structure: loops (while and for) and conditional branches (if, else) 3. How to read procedural specifications (requires, modifies, effects) Getting started Checkout the ps1 module from your repository. If you don't remember how to do this, take a look at the Problem Set Procedure document. Then, work through the problems below. Use the provided Specifications to help you fill in the missing methods. By the end of the problem set, you should have the following files ready to submit in your ps1 directory: • doc/problem1.txt • src/RatPoly.java • src/RatPolyStack.java • doc/problem4.txt • doc/reflection.txt You are free to work from home if that makes your life easier, but keep in mind that your final code MUST run correctly on Athena. Once everything is in order, read the Problem Set Submission instructions, which will tell you how to run a final check of your code and turn it in. Introducing Continuous Testing In Problem Set 0, your were introduced to JUnit testing. In this problem set, we will introduce another tool that will make testing easier and more effective -- the Eclipse Continuous Testing plugin. This tool is already installed on Athena and all you need to do is to enable it. Continuous testing builds on the automated developer support in Eclipse to make it even easier to keep your Java code well-tested. With continuous testing enabled, as you edityour code, Eclipse runs your tests quietly in the background, and notifies you if any of them fail or cause errors. It is most useful in situations where you would already have a test suite while you are changing code: when performing maintenance, refactoring, or using test-first development. 1. To enable Continuous Testing, right click on the project folder in the Package Explorer and select Properties. Courtesy of The Eclipse Foundation.2. Next, simply enable "Informed Testing" and "Continuous Testing" and click OK. Courtesy of The Eclipse Foundation.3. When you next click on the JUnit view, you will see a test called CT Launch for Project ps1. Continuous testing will automatically run all the JUnit tests in the problem set and highlight all the tests that failed. You can also run specific tests like you did in Problem Set 0. The results for these tests can be accessed separately in the Result dropdown and Continuous Testing will not override them. Continuous Testing tries to use only spare cycles on your machine when you don't need them and should in general not have any effects on Eclipse's performance. It is possible however that for the older slower Athena machines, you might experience a noticeable slowdown in performance. If so, simply uncheck the two check boxes "Informed Testing" and "Continuous Testing" to disable Continuous Testing. Courtesy of The Eclipse Foundation.Read the specifications for RatNum, a class representing rational numbers. Then read over the staff-provided implementation, RatNum.java. You may find it helpful to peruse the code in RatNumTest.java to see example usages of the RatNum class (albeit in the context of a test driver, rather than application code). Answer the following questions, writing your answers in the file doc/problem1.txt 1. What is the point of the one-line comments inside the add, sub, mul, and div methods (right before the call to checkRep())? 2. add, sub, mul, and div all require that "arg != null". This is because all of the methods access fields of 'arg' without checking if 'arg' is null first. But the methods also access fields of 'this' without checking for null; why is "this != null" absent from the requires-clause for the methods? 3. RatNum.div(RatNum) checks whether its argument is NaN (not-a-number). RatNum.add(RatNum) and RatNum.mul(RatNum) do not do that. Explain. 4. Why is RatNum.parse(String) a static method? What alternative to static methods would allow one to accomplish the same goal of generating a RatNum from an input String? 5. The checkRep() method is called at the beginning and end of most methods. Why is there no checkRep() call at the beginning of the constructor? 6. Imagine that the representation invariant were weakened so that we did not require that the numer and denom fields be stored in reduced form. This means that the method implementations could no longer assume this invariant held on entry to the method, but they also no longer were required to enforce the invariant on exit. The new rep invariant would then be: // Rep Invariant for every RatNum r: ( r.denom >= 0 ) Which method or constructor implementations would have to change? Please list them. For each changed piece of code, describe the changes informally, and indicate how much more or less complex the result would be (both in terms of code clarity, and also in terms of execution


View Full Document

MIT 6 170 - Study Notes

Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?