Question: public static int numOfCoins(int[] coinsList, int value){ /** Write your code here to find out minimum number of coins required to provide the change for

 public static int numOfCoins(int[] coinsList, int value){ /** Write your code

here to find out minimum number of coins required to provide the

public static int numOfCoins(int[] coinsList, int value){

/** Write your code here to find out minimum number of coins required to provide the change for a given value.

This method will have a coinsList array, which can be any set of coin values that should be used to test the code. You cannot hard code this array because the array value will be giving at runtime, and an int value which specifies the value for which we need to calculate the minimum number of coins to be changed. This method should return the number of coins

}

/** Test The Program via Command line or Terminal:

javac -cp .:junit-4.12.jar CoinChangeTest.java

java -cp .:junit-4.12.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore CoinChangeTest

Here the file we will use to test your code:

//Test File:

import static org.junit.Assert.*;

import org.junit.Test;

import java.util.Arrays;

public class CoinChangeTest {

@Test

public void testCoinChange1() {

CoinChange c = new CoinChange();

int[] denomination = {1,5,10,25};

int value = 37;

int answer = 4;

assertEquals(c.NumberofCoins(denomination,value),answer);

}

@Test

public void testCoinChange2() {

CoinChange c = new CoinChange();

int[] denomination = {1,6,10};

int value = 11;

int answer = 2;

assertEquals(c.NumberofCoins(denomination,value),answer);

}

@Test

public void testCoinChange3() {

CoinChange c = new CoinChange();

int[] denomination = {1,6,10};

int value = 13;

int answer = 3;

assertEquals(c.NumberofCoins(denomination,value),answer);

}

@Test

public void testCoinChange4() {

CoinChange c = new CoinChange();

int[] denomination = {1,6,10};

int value = 17;

int answer = 3;

assertEquals(c.NumberofCoins(denomination,value),answer);

}

@Test

public void testCoinChange5() {

CoinChange c = new CoinChange();

int[] denomination = {1,9,15};

int value = 37;

int answer = 5;

assertEquals(c.NumberofCoins(denomination,value),answer);

}

@Test

public void testCoinChange6() {

CoinChange c = new CoinChange();

int[] denomination = {1,9,15};

int value = 54;

int answer = 4;

assertEquals(c.NumberofCoins(denomination,value),answer);

}

}

Possible errors:

testCoinChange1(CoinChangeTest) java.lang.AssertionError: expected: but was: at CoinChangeTest.testCoinChange1(CoinChangeTest.java:15)

testCoinChange2(CoinChangeTest) java.lang.AssertionError: expected: but was: at CoinChangeTest.testCoinChange2(CoinChangeTest.java:24)

testCoinChange3(CoinChangeTest) java.lang.AssertionError: expected: but was: at CoinChangeTest.testCoinChange3(CoinChangeTest.java:33)

coins are minted with denominations of 1,5,10,25cent or denomination = {1,6,10), or denomination-(19,15). An algorithm for making change using the smallest possible number of coins repeatedly returns the biggest coin smaller than the amount to be changed until it is zero. For example, 17 cents will result in the series 10 cents, 5 cents, 1 cent, and 1 cent. Write a program using the dynamic programming formula below to compute the minimum number of coins for making a change for a given value. Use Java language by completing the given method declaration. You must use dynamic programming implementation. Formula: T[i] = 1 + min, jsk T[i-Dj ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!