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
Asked Dec 18, 2019
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

Expert Answer

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

Check out a sample Q&A here.

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

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: what is the cpu time when the number of instructions executed by the program is 500, cycles per inst...

A: CPU time (or CPU Execution time) is the time between the start and the finishing(end) of execution o...

question_answer

Q: 7.10: Tic Tac Toe (sort of) Write a program that will allow two users to playtic-tac-toe. The progra...

A: Program: #include <iostream>using namespace std; void initialize_Board(char board[][3]);void b...

question_answer

Q: Copy and paste the following definition of the class Car in the submission box and then add a method...

A: Program implementation-def is used to declare a method. Here, def is used to declare brake method in...

question_answer

Q: I need help writing a java object oriented code using threads methods. Thank you

A: Program:import java.util.*; public class Main{public static void main(String[] args){try{ final Thre...

question_answer

Q: Which of the following is used to communicate with the network? Southbound API Northbound API Northb...

A: To communicate with the network, better Application program Interface is: Northbound API is supposed...

question_answer

Q: Suppose two integers num1 and num2 have previously been defined and assigned values. give a while st...

A: While Loop: The while loop first check the condition, if the condition is true then it executes its ...

question_answer

Q: I have to add this solution to a conversion code. This chapter is focused on  strings and string man...

A: Program Instructions:  ⦁ Create a Python3 program for the given problem of string slicing, search, a...

question_answer

Q: Explain various types of polymorphism?State differences between them?

A: Polymorphism:Polymorphism is an important feature of object-oriented programming languages.It refers...

question_answer

Q: in c++m given the following, use a range-based for loop to display the contents of the array (use co...

A: Program code: