C Sc 127B Assignment 1: Piggybank
Total Page:16
File Type:pdf, Size:1020Kb
C Sc 127B Assignment 1: PiggyBank Colloration Solo: Complete this on your own with help from section leaders only (or the book, slides, or code demos for this course)
You are to implement class PiggyBank. Implement always means that in addition to writing code that appears to work, you should also write tests to "prove" your code works. A PiggyBank object encapsulates the contents of a piggy bank with messages associated with real world actions. For our purposes, the bank should know how many coins are in it and the cash value of those coins (only pennies, nickels and dimes are allowed to save time). Banks can only hold a finite limit of coins. This amount should be 50 for any and all piggy bank objects. The first task is to write a constructor and decide what instance variables you will need (feel free to add them later, if you find the need.) PiggyBank objects need no arguments in their constructors, just initialize your instance variables. Here is a summary of all methods needed with comments specifying the details of the expected behavior: // Construct an empty PiggyBank that can store 50 pennies, nickels, // and/or dimes (no quarters, halves or dollar coins to save time) public PiggyBank()
// A getCapacity() message should return the maximum number // of coins that can be stored in this PiggyBank object. public int getCoinCapacity()
// A getTotalNumberOfCoins() message should return the number of // coins currently in the bank. The coins can be of any type. public int getTotalNumberOfCoins()
// A getTotalCashInBank() message should return the total amount of // cash in the bank. Pennies are $0.01, nickels are $0.05, and dimes // are $0.10 (no quarters, halves, or dollar coins to save time). public double getTotalCashInBank()
// An addPennies message tries to add the given number of pennies to // the bank. It will add as many pennies as can fit and return the // amount added. For example, if the bank is empty and we add 50 // pennies, which is always the capacity a bank can fit, this method // will return 50. If the bank has 20 coins in it and we try to add // 50 coins, the method will return 30, as that is the number that // actually went in. If the bank is full and we try to add 1 penny, // this method will return 0, since no pennies were added. public int addPennies(int penniesEntered)
// An addNickels message is identical to the addPennies, but adds nickels instead. // Remember the return value indicates how many nickels were actually added. public int addNickels(int numberOfNickels)
// An addDimes message is identical to the addPennies, but adds dimes instead. // Remember the return value indicates how many dimes were actually added. public int addDimes(int numberOfDimes)
// A drainTheBank message takes all of the money out of the bank. // The return value must be how much money was drained from the bank. public double drainTheBank()
// This method gives the user the satisfaction of "hearing" the money // in their bank. If the bank has at least one coin in it, return // "*jingle jingle*" will be returned. If the bank is empty, the // String "*cricket cricket*" will be returned. public String shake() Rick will do a code demo in class during Wednesday's lecture to demonstrate Test Driven Development. The result will be the beginning of a unit test that Rick will post to our website on the Code Demos page.
Submit your project to WebCat You will be graded on a scale of 0.0 through 20.0 automatically by WebCat. Here are the instructions for getting the Submit plugin for Eclipse and Submitting your first Webcat project. Read your email to get for your Web-Cat account ID (almost always what comes before @email.arizona.edu) and the randomly generated password Login to WebCat at this url: https://web-cat.cs.vt.edu/Web-CAT/WebObjects/Web-CAT.woa Change your password to a good password that no one else can guess. If you haven't already, download WebCat's submit plugin to make it easy to submit projects: webcat-eclipse-submitter-1.2.1.zip Unzip this archive file. Copy three highlighted folders (beginning with net.sf.webcat) into the Eclipse plugin. For Window, the Eclipse plugin folder should be C:\Program Files\eclipse\ or c:\Program Files\eclipse- SDK-3.6-win32\eclipse\ For the Mac, you should copy these three folders into your folder ending with /Applications/eclipse/plugins
In any system, restart Eclipse, select Window > Preferences > Electronic Submission
Submit your Project to WebCat using the Plugin From Eclipse, select Window > Preferences > Electronic Submission Using your own Default username and your own email address, fill in the four fields using this url for the Assignment definition URL (Recommended: Copy and paste this into the first field): https://web-cat.cs.vt.edu/Web-CAT/WebObjects/Web-CAT.woa/wa/assignments/eclipse?institution=Arizona
Click OK
Submit your project to WebCat
Right click on your project name Select the Submit button (near the bottom of the list of options). WebCat will return the list of published projects under C Sc 127 and 227 Click on the appropriate project name , which should be PiggyBank under 127 (not shown above) Make sure UserName has your correct WebCat user name Type in your WebCat password Click Next and Finish . Webcat will post a page to the Eclipse Web Browser, which may indicate an incorrect password or feedback indicating your code is being examined. Click view your graded results and wait until the report is posted back to you Wait until WebCat posts results back to the Eclipse browser--could take 15-45 seconds If you get 100%, Congratulations!
Interpreting Results
If you get 20 points, great. Otherwise scroll down and click on the plus symbol to the left of Estimate of Problem Coverage and read the hints.
You will also loose points of you do don't execute every line of code. This is known as code coverage. Open files that are not 100% code coverage and look for pink lines that have executed 0 times. To fix this, test your code better. Call each method at least once. Write tests that will cover every branch of code.