/** * TestProgram is used as the test driver for Program 1 in CS 160. * * @author John Paxton * @version October 29, 2008 */ public class TestProgram { public static void main (String [] args) { GringottsAccount harrysAccount; // Harry Potter's Gringott's Account GringottsAccount hermionesAccount; // Hermione Granger's Account GringottsAccount ronsAccount; // Ron Weasley's Account // Create an account owned by Harry Potter that has // 555 Galleons, 444 Sickles and 333 Knuts. harrysAccount = new GringottsAccount("Harry Potter", 555, 444, 333); // Print information regarding Harry's account. System.out.print(harrysAccount); // Convert Harry's entire account to Knuts. There // are 17 Sickles in a Galleon and 29 Knuts in a Sickle. harrysAccount.convertToKnuts(); System.out.print(harrysAccount); // Convert Harry's account back so that it uses as many Galleons // as possible. The remaining money should use as many Sickles // as possible. harrysAccount.convertToGalleons(); System.out.print(harrysAccount); // Create an account owned by Hermione Granger. The number // of initial galleons, sickles and knuts should all be 0. hermionesAccount = new GringottsAccount("Hermione Granger"); System.out.println(hermionesAccount); // Change the number of Galleons that Hermione has to 150. hermionesAccount.setGalleons(150); // Change the number of Sickles that Hermione has to 100. hermionesAccount.setSickles(100); // Change the number of Knuts that Hermione has to 200. hermionesAccount.setKnuts(200); System.out.println(hermionesAccount); // Make a deposit of 1 Galleon, 2 Sickles and 3 Knuts into // Hermione's account. hermionesAccount.makeDeposit(1, 2, 3); System.out.println(hermionesAccount); ronsAccount = new GringottsAccount("Ron Weasley"); // This will give Ron a negative account balance. That is OK. ronsAccount.makeDeposit(-1, 0, 0); System.out.println(ronsAccount); ronsAccount.convertToKnuts(); System.out.println(ronsAccount); ronsAccount.convertToGalleons(); System.out.println(ronsAccount); } }