Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

lcricket LTE 10:10 79% a ecat.montana.edu Purpose The purpose of this lab is to

ID: 3707028 • Letter: L

Question

lcricket LTE 10:10 79% a ecat.montana.edu Purpose The purpose of this lab is to better understand greedy algorithms and unit testing with JUnit. Background: The change-making problem, also known as minimum coin change problem, addresses the question of finding the minimum number of coins (of certain denominations) that add up to a given amount of money.(https://en.wikipedia.org/wiki/Chan? . For this lab, we will be extending the problem to find the denomination of each coin in the minimum number of coins that add up to the given amount of money. What to do: Make a class to hold JUnit tests with at least four test cases for the method described below One test case should expect an Exception when an empty array of coins is sent in as a parameter o Make a class to hold one method that has two parameters: an array of coins for a coin system for example 1,5, 10, 25 for the smaller, commonly-used coins in US currency) and an int, the amount for which to make change. The method should return a list of the coins that add up to the amount. For example, for the US coin system and ar amount of 42, the method would return a list including 25, 10, 5,1,1 . The method should throw an Exception if the array of coins sent in as a parameter is empty The greedy method should repeatedly choose the largest denomination of coin possible and deduct that coin from the original amount and add that coin to the list of coins to return o o There should be no main method in your code. Execution should be triggered only by the JUnit test cases Using the following as a template, place a comment near the top of each java file you create containing accurate information about the author, date, and overview of the program Date: cDate you submitted the assignsent> Overvlew:

Explanation / Answer

Please find the Java code for Change Making problem using Greedy Algorithms:-

import java.util.Vector;

public class GreedyCoinChange {

void findMin(int coins[], int Value) throws Exception{

if (coins.length == 0){

throw new Exception("The Coin Array cannot be blank!!");

}

// Initialize result

Vector<Integer> ans = new Vector<Integer>();

// Traverse through all denomination

for (int i = coins.length - 1; i >= 0; i--){

// Find denominations

while (Value >= coins[i])

{

Value -= coins[i];

ans.add(coins[i]);

}

}

// Print result

for (int i = 0; i < ans.size(); i++)

System.out.println(ans.get(i) + " ");

}

}