Question: Write a Patron.java program using Jrasp and Dr.java to test it. The Patron constructor will be used to initialize all attributes of the Patron object.
Write a Patron.java program using Jrasp and Dr.java to test it.
The Patron constructor will be used to initialize all attributes of the Patron object.
The adjustBalance will update the current balance of the patron. For example if the current balance of a Patron is 2.0 and the amount is 4.5, this method should assign 6.50 to this.balance and return 6.50.
The equals method checks whether two patrons have the same id number. If the given object is a Patron, compare this.idNumber with the other patron's idNumber. If the given object is an Integer, compare this.idNumber with the Integer.
The toString method should return a String representation of the Patron. If a patron is initialized with the following parameters ("bob", "eee", 2, 5.5), it should return a String exactly as follows: "Name: bob, Email: eee, ID: 2, Balance: $5.50."
/////////////////////////////////////////////////////////////////////////////////////////////////////////
Code for PatronTest Case
import junit.framework.TestCase; /** * Tests Patron: currently one test method. * * @author * @version * */ public class PatronTest extends TestCase { /** A single test for Patron. **/ public void testPatron() { Patron aPatron1 = new Patron("Dee A. B. Weikle", "weikleda@jmu.edu", 2, 1.50); assertEquals("Patron: toString", "Name: Dee A. B. Weikle," + " Email: weikleda@jmu.edu, ID: 2, Balance: $1.50.", aPatron1.toString()); Patron aPatron2 = new Patron("Dee A. B. Weikle", "weikleda@jmu.edu", 2, 1.50); assertTrue("Patron: equals", aPatron1.equals(aPatron2)); aPatron1.adjustBalance(2.50); assertEquals("Patron: toString", "Name: Dee A. B. Weikle," + " Email: weikleda@jmu.edu, ID: 2, Balance: $4.00.", aPatron1.toString()); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
