Implement a Class and its Unit Test in Eclipse Using JUnit | C SC 127A, Exams of Computer Science

Material Type: Exam; Class: Introduction to Computer Science; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Spring 2008;

Typology: Exams

Pre 2010

Uploaded on 08/31/2009

koofers-user-bya
koofers-user-bya 🇺🇸

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
127B Section 24- or 25-Jan 2008
In today's section you are asked to
Implement a class and its unit test in Eclipse using JUnit.
Set up Eclipse to submit your Eclipse Project to WebCat from one of our lab machines.
oYou will need to read your email to get your WebCat user name and password
oYou should have received this sometime late Wednesday night
Submit your Eclipse project to WebCat using the Submit option
oDo this 15 minutes before your section ends even if your code is wrong
You can resubmit
oIf you do not get 100% during section, submit by Monday 12:45 pm (not a second later) for
the 3pts (0-32% is 0 pts, 33-65% is 1 pt, 66%-90% is 2pts, > 90% is 3pts)
oNote: The Submit option is available in the lab, but you will need to add this plugin on your
home machine (instructions appear under the WebCat link from our home page).
1. Implement class PiggyBank
oStart Eclipse and create a project named PiggyBank
oImplement class PiggyBank, an object to which pennies, nickels and dimes can be
added. Each PiggyBank object keeps track of how much money is in the PiggyBank. A
PiggyBank can be raided anytime to reduce the total amount of money to 0.00. Make
sure you include a unit test PiggyBankTest that tests all methods. Also make sure the
unit test name ends with Test. Do not name it TestPiggyBank (or you will get 0%) The
PiggyBank class must have the following methods:
/**
* Construct a PiggyBank with no money.
*/
public PiggyBank()
/**
* Return the amount of money in this PiggyBank as a dollars and cents
* amount. After construction or a smash, getTotal() must return 0.0.
*/
public double getTotal()
/**
* Add the given number of pennies to this PiggyBank.
* @param penniesToAdd The number of pennies added to this PiggyBank.
*/
public void addPennies(int penniesToAdd) {
total += penniesToAdd;
}
/**
* Add the given number of nickels this PiggyBank.
* @param nickelsToAdd The number of nickels to add to this PiggyBank.
*/
public void addNickels(int nickelsToAdd)
pf3
pf4
pf5

Partial preview of the text

Download Implement a Class and its Unit Test in Eclipse Using JUnit | C SC 127A and more Exams Computer Science in PDF only on Docsity!

127B Section 24- or 25-Jan 2008

In today's section you are asked to

  • Implement a class and its unit test in Eclipse using JUnit.
  • Set up Eclipse to submit your Eclipse Project to WebCat from one of our lab machines.

o You will need to read your email to get your WebCat user name and password

o You should have received this sometime late Wednesday night

  • Submit your Eclipse project to WebCat using the Submit option

o Do this 15 minutes before your section ends even if your code is wrong

 You can resubmit

o If you do not get 100% during section, submit by Monday 12:45 pm (not a second later) for

the 3pts (0-32% is 0 pts, 33-65% is 1 pt, 66%-90% is 2pts, > 90% is 3pts)

o Note: The Submit option is available in the lab, but you will need to add this plugin on your

home machine (instructions appear under the WebCat link from our home page).

1. Implement class PiggyBank

o Start Eclipse and create a project named PiggyBank

o Implement class PiggyBank, an object to which pennies, nickels and dimes can be

added. Each PiggyBank object keeps track of how much money is in the PiggyBank. A

PiggyBank can be raided anytime to reduce the total amount of money to 0.00. Make

sure you include a unit test PiggyBankTest that tests all methods. Also make sure the

unit test name ends with Test. Do not name it TestPiggyBank (or you will get 0%) The

PiggyBank class must have the following methods:

  • Construct a PiggyBank with no money. / public PiggyBank() /*
  • Return the amount of money in this PiggyBank as a dollars and cents
  • amount. After construction or a smash, getTotal() must return 0.0. / public double getTotal() /*
  • Add the given number of pennies to this PiggyBank.
  • @param penniesToAdd The number of pennies added to this PiggyBank. / public void addPennies( int penniesToAdd) { total += penniesToAdd; } /*
  • Add the given number of nickels this PiggyBank.
  • @param nickelsToAdd The number of nickels to add to this PiggyBank. */ public void addNickels( int nickelsToAdd)
  • Add the given number of dimes to this PiggyBank.
  • @param dimesToAdd The number of dimes to add to this PiggyBank. / public void addDimes( int dimesToAdd) /*
  • Simulate a complete raid on this PiggyBank. After a smash message, this
  • PiggyBank has no money. */ public void smash()

2. Get Ready to Submit your Project to WebCat

o Read your email to get for your Web-Cat password

o Login at this url: https://web-cat.cs.vt.edu/Web-CAT/WebObjects/Web-CAT.woa

o Change your password to something you will remember until May 7th

o From Eclipse, select Window > Preferences > Electronic Submission

o Using your Web-Cat login name and your own email address, fill in the four fields (see

next page) using this long url for the Assignment definition URL:

https://web-cat.cs.vt.edu/Web-CAT/WebObjects/Web-CAT.woa/wa/assignments/eclipse?institution=Arizona

4. Interpreting Results

This result shows that rick would only get an 80% for this project.

Why? Scroll down and click on the plus to the left both of these headings

Estimate of Problem Coverage (80%) Interpreting Your Correctness/Testing Score (80/100)

You should the hints and score explanation on the next page. It appears this student turned

in a project where an assertion failed when testing add pennies. This is indicated by the

following message Rick wrote in his tests to give you a hint (also shown on the bottom of the

screenshot on the next page)

The following hint(s) may help you locate some ways in which your solution and your testing may be improved:

  • addPennies failed

This student should fix the code and resubmit.

But if you have 100%, you are done and may leave.

Best wishes.