Using change. Find how many values from 1 to 99 require 8 coins. Must use a for
ID: 652910 • Letter: U
Question
Using change. Find how many values from 1 to 99 require 8 coins. Must use a for loop and a counter. Code so far
// a. Find how many values from 1 to 99 require 9 coins. Must use a for loop and a counter.
int count=1;
for (int i=1; i<=99; i++){
int a = i;
int quart = a/25;
a = a%25;
int dime = a/10;
a = a%10;
int nick = i/5;
a = a%5;
int penn = a;
int total= quart+dime+nick+penn;
if (total == 9){
count++;
}
}
System.out.println("The following number determines how many values from 1 to99 requires nine coins: " +count);
// b. Find how many values from 1 to 99 require 8 coins. Must use a for loop and a counter.
int change=1;
for (int i=1; i<=99; i++){
int a = i;
int quart = a/25;
a = a%25;
int dime = a/10;
a = a%10;
int nick = i/5;
a = a%5;
int penn = a;
int total= quart+dime+nick+penn;
if (total == 8){
change++;
}
}
System.out.println("The following number determines how many values from 1 to 99 requires eight coins: " +change);
// c. What is the maximum number of coins needs for change from 1 to 50 cents? Must use a for loop and a variable named maxCoins.
} // end of main
//public static int numberOfCoinsRequired(int changeDue) {
//int amount = changeDue;
// Add code here to complete this method.
//return 0;
}
// end of class
Explanation / Answer
Answer:
//Assuming the coins can be penny (1), nickel (5), dimes (10) and quartz (25) to find minimum coins required to make every value from 1 to 99 using 1 cent increament.
A Program coin9:
import java.io.*;
public class E
{
public static void main(String[] args)
{
int count=1;
for (int i=1; i<=99; i++)
{
int a = i;
int quart = a/25;
a = a%25;
int dime = a/10;
a = a%10;
int nick = i/5;
a = a%5;
int penn = a;
int total= quart+dime+nick+penn;
if (total == 9)
{
count++;
}
}
System.out.println("The following number determines how many values from 1 to99 requires nine coins: " +count);
}}
Answer is 5
B Program coin9
import java.io.*;
public class coin8
{
public static void main(String[] args)
{
int change=1;
for (int i=1; i<=99; i++){
int a = i;
int quart = a/25;
a = a%25;
int dime = a/10;
a = a%10;
int nick = i/5;
a = a%5;
int penn = a;
int total= quart+dime+nick+penn;
if (total == 8){
change++;
}
}
System.out.println("The following number determines how many values from 1 to 99 requires eight coins: " +change);
}}
Answer is 5
C.
Import java.io.*;
Import java.util.*;
Class coinLogic
{
Const int P = 1; //Penny
Const int N = 5; //Nickle
Const int D = 10; //Dime
Const int Q = 25; //Quartz
Const int maxCurr = 50;
Public Static void main (string [ ] args)
{
Int minP_needed = 0;
Int minN_needed = 0;
Int minD_needed = 0;
Int minQ_needed = 0;
For(int i= 1;i<maxCurr; i++)
{
If (maxCurr == P)
{
minP_needed = 1;
}
elseif (maxCurr < N)
{
minP_needed = minC_needed (P, maxCurr)
}
elseif (maxCurr < D)
{
minP_needed = minC_needed (P, N -1);
minN_needed = minC_needed (N, maxCurr);
}
elseif (maxCurr < Q)
{
minP_needed = minC_needed (P, N -1);
minN_needed = minC_needed (N, D -1);
minD_needed = minC_needed (D, maxCurr);
}
Else
{
minP_needed = minC_needed (P, N-1);
minN_needed = minC_needed (N, D-1);
minD_needed = minC_needed (D, Q-1);
var maxValueWithoutQ = (minP_needed * P + minN_needed * N + minD_needed * D);
if (maxCurrTesting > maxValWithoutQ)
{
minQ_needed = (((maxCurr
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.