Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with Java Methods for Piggy Bank program public class PiggyBank { public final static int[] COINS_VALUES = {1, 5, 10, 25}; // coins values

Help with Java Methods for Piggy Bank program

public class PiggyBank { public final static int[] COINS_VALUES = {1, 5, 10, 25}; // coins values in cents // coins names public final static String[] COINS_NAMES = {"PENNY", "NICKEL", "DIME", "QUARTER"}; public final static String NO_SUCH_COIN = "N/A"; // N/A string private final static Random RAND_GEN = new Random(100); // generator of random integers

/** * Returns the name of a specified coin value * * @param coin represents a coin value in cents. * @return the String name of a specified coin value if it is valid and N/A if the coin value is * not valid */ public static String getCoinName(int coin) { Insert code

}

/** * Returns the balance of a piggy bank in cents * * @param coins an oversize array which contains all the coins held in a piggy bank * @param size the total number of coins stored in coins array * @return the total value of the coins held in a piggy bank in cents */ public static int getBalance(int[] coins, int size) {

Insert code

}

/** * Returns the total number of coins of a specific coin value held in a piggy bank * * @param coinValue the value of a specific coin * @param coins an oversize array which contains all the coins held in a piggy bank * @param size the total number of coins stored in coins array * @return the number of coins of value coinValue stored in the array coins */ public static int getSpecificCoinCount(int coinValue, int[] coins, int size) {

Insert code }

/** * Displays information about the content of a piggy bank * * @param coins an oversize array storing the coins held in a piggy bank * @param size number of coin held array coins */ public static void printPiggyBank(int[] coins, int size) {

Insert code

}

/** * Adds a given coin to a piggy bank. This operation can terminate successfully or unsuccessfully. * For either cases, this method displays a descriptive message for either cases. * * @param coin the coin value in cents to be added to the array coins * @param coins an oversize array storing the coins held in a piggy bank * @param size the total number of coins contained in the array coins before this addCoin method * is called. * @return the new size of the coins array after trying to add coin. */ public static int addCoin(int coin, int[] coins, int size) {

Insert code

}

/** * Removes an arbitrary coin from a piggy bank. This method may terminate successfully or * unsuccessfully. In either cases, a descriptive message is displayed. * * @param coins an oversize array which contains the coins held in a piggy bank * @param size the number of coins held in the coins array before this method is called * @return the size of coins array after this method returns successfully */ public static int removeCoin(int[] coins, int size) {

Insert code

}

/** * Removes all the coins in a piggy bank. It also displays the total value of the removed coins * * @param coins an oversize array storing the coins held in a piggy bank application * @param size number of coins held in coins array before this method is called * @return the new size of the piggy bank after removing all its coins. */ public static int emptyPiggyBank(int[] coins, int size) {

Insert code }

/** * Removes the least number of coins needed to fulfill a withdrawal request * * @param amount amount to withdraw given in cents * @param coins an oversize array storing the coins held in a piggy bank * @param size number of coins stored in coins array before this method is called * @return perfect size array of 5 elements, index 0 stores the new size of the piggy bank after * this method returns. Indexes 1, 2, 3, and 4 store respectively the number of removed * quarters, dimes, nickels, and pennies. */ public static int[] withdraw(int amount, int[] coins, int size) {

Insert code

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago

Question

Describe the options and trends in management education

Answered: 1 week ago