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

import java.util.*; public class project4 { public static void main(String[] arg

ID: 3669822 • Letter: I

Question

import java.util.*; public class project4 { public static void main(String[] args) { Scanner s = new Scanner(System.in); double[][] arr = new double[5][2]; int count; double bill; double paid; double amountowed; int dollar = 0; int quarter = 0; int dime = 0; int nickel = 0; int penny = 0; for (count = 0; count < 5; count++) { System.out.print("Enter bill " + (count + 1) + ": "); bill = Double.parseDouble(s.nextLine()); System.out.print("Enter amound paid for bill " + (count + 1) + ": "); paid = Double.parseDouble(s.nextLine()); arr[count][0] = bill; arr[count][1] = paid; } for (count = 0; count < 5; count++) { amountowed = (arr[count][1] - arr[count][0]); System.out.println("Change for bill " + (count + 1)); while (amountowed > 0) { if (amountowed >= 1) { dollar++; amountowed -= 1; System.out.print("dollar"); } else if (amountowed >= .25) { quarter++; amountowed -= .25; System.out.print("quarter"); } else if (amountowed >= .10) { dime++; amountowed -= .10; System.out.print("dime"); } else if (amountowed >= .05) { nickel++; amountowed -= .05; System.out.print("nickel"); } else if (amountowed >= .01) { penny++; amountowed -= .01; System.out.print("Pennies"); } else{ amountowed = 0; } } System.out.println(); } } } color{red}underline{Output:} Enter bill 1: 6.25 Enter amound paid for bill 1: 10 Enter bill 2: 5.78 Enter amound paid for bill 2: 10 Enter bill 3: 1.11 Enter amound paid for bill 3: 2 Enter bill 4: 5 Enter amound paid for bill 4: 10 Enter bill 5: 13.66 Enter amound paid for bill 5: 15 Change for bill 1 dollardollardollarquarterquarterquarter Change for bill 2 dollardollardollardollardimedimePennies Change for bill 3 quarterquarterquarterdimePenniesPenniesPennies Change for bill 4 dollardollardollardollardollar Change for bill 5 dollarquarternickelPenniesPenniesPennies Hide comments Comments You commented How do you change that to say like 3 pennies instead of penniespenniespennies?

Explanation / Answer

Changes need to be print out of loop. So that they don't don't get print every time, instead they get calculated and at the end result is printed. Below is the modified program.

import java.util.*;
public class HelloWorld
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
double[][] arr = new double[5][2];
int count; double bill; double paid;
double amountowed; int dollar = 0;
int quarter = 0; int dime = 0;
int nickel = 0;
int penny = 0; for (count = 0;
count < 5; count++)
{
System.out.print("Enter bill " + (count + 1) + ": ");
bill = Double.parseDouble(s.nextLine());
System.out.print("Enter amound paid for bill " + (count + 1) + ": ");
paid = Double.parseDouble(s.nextLine());
arr[count][0] = bill;
arr[count][1] = paid;
}
for (count = 0; count < 5; count++)
{
amountowed = (arr[count][1] - arr[count][0]);
System.out.println("Change for bill " + (count + 1));
while (amountowed > 0) {
if (amountowed >= 1) {
dollar++; amountowed -= 1;
}
else if (amountowed >= .25) {
quarter++;
amountowed -= .25;
}
else if (amountowed >= .10) {
dime++;
amountowed -= .10;
}
else if (amountowed >= .05) {
nickel++;
amountowed -= .05;
}
else if (amountowed >= .01) {
penny++;
amountowed -= .01;
}
else{
amountowed = 0;
}
}
System.out.println();
System.out.println(dollar + " dollar");
System.out.println(quarter + " quarter");
System.out.println(dime + " dime");
System.out.println(nickel + " nickel");
System.out.println(penny + " Pennies");
}
}
}

// Hope it helps! :-)

// Leave a comment if you have any query. I'll try to explain further.