# Using OOP language JavaGiven a currency with denominations of 100, 50, 20, 10, 5 and 1 write a method MakeChange that takes an integer amount representing the total change to make and return an integer representing the smallest possible number of bills to return.  For example, a call of MakeChange(135) would result in a return value of 4 (1 one hundred bill, 1 twenty bill, 1 ten bill and 1 five bill).  As part of a final solution please provide unit tests done as well as any test cases ran.

Question
51 views

Using OOP language Java

Given a currency with denominations of 100, 50, 20, 10, 5 and 1 write a method MakeChange that takes an integer amount representing the total change to make and return an integer representing the smallest possible number of bills to return.  For example, a call of MakeChange(135) would result in a return value of 4 (1 one hundred bill, 1 twenty bill, 1 ten bill and 1 five bill).  As part of a final solution please provide unit tests done as well as any test cases ran.

check_circle

Step 1

Program Description

We define a class called MakeChange which has a private static method called makeChange which computes the total number of bills. The method computes the minimum total number of bills by using the modulus operator and division operator to extract the count and to compute the remainder amount after extraction of the number of bills using current denomination value. The extraction process is repeated for each denomination value starting with the highest value. In order to do this the bill denomination values are stored in an array and a while loop is used to iterate over the array and do the extraction and count.

Step 2

Java Program

class MakeChange{

//static method to be called from the static main method to calculate

//no. of bills

private static int makeChange(int x){

//variable to keep count of no. of bills

int count = 0;

//array to contain the denomination of the bills

int bills[] = {100,50,20,10,5,1};

//array index to be used to iterate over the denomination values

int i = 0;

//declare and initialize the temp1 variable to extract and store

//the no. of bills using current denomination value

int temp1 = 0;

//declare and initialize the count variable to store the total

//count of the number of bills

count = 0;

//declare and initialize the temp2 variable to store the

//remainder value after deducting the bills of the current

//denomination value from the total value

int temp2 = x;

...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in