can someone tell me how to fix this? /* * To change this template, choose Tools
ID: 3647995 • Letter: C
Question
can someone tell me how to fix this?/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package computerchange;
import java.util.Scanner;
/**
*
* @author Owner
*/
public class Computerchange {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner( System.in);
System.out.print("Enter dollar amoumt as a double, for example 11.90");
double amount = input.nextDouble();
int remainingAmount = (int)(amount*100);
int numberofdollars = (int)(remainingAmount/100);
remainingAmount = remainingAmount % 100;
int numberofQuarters =remainingAmount / 25;
remainingAmount = remainingAmount % 25;
int numberofdimes = remainingAmount / 10;
remainingAmount = remainingAmount % 10;
int numberofnickles = remainingAmount / 5;
remainingAmount = remainingAmount % 5;
int numberofpennies = remainingAmount;
String output = " your amount" + amount + " consists of n" +
" " + numberofdollars + " dollars " +
" " + numberofQuarters + " Quarters " +
" " + numberofnickles + " nickles " +
" " + numberofpennies + " pennies " ;
System.out.println(output);
}
}
Explanation / Answer
There are some errors in your code. i have fixed them. this the final code.. import java.util.Scanner; public class ComputeChange { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Receive the amount System.out.print( "Enter an amount in double, for example 11.56: "); double amount = input.nextDouble(); int remainingAmount = (int)(amount * 100); // Find the number of one dollars int numberOfOneDollars = remainingAmount / 100; remainingAmount = remainingAmount % 100; // Find the number of quarters in the remaining amount int numberOfQuarters = remainingAmount / 25; remainingAmount = remainingAmount % 25; // Find the number of dimes in the remaining amount int numberOfDimes = remainingAmount / 10; remainingAmount = remainingAmount % 10; // Find the number of nickels in the remaining amount int numberOfNickels = remainingAmount / 5; remainingAmount = remainingAmount % 5; // Find the number of pennies in the remaining amount int numberOfPennies = remainingAmount; // Display results System.out.println("Your amount " + amount + " consists of " + " " + numberOfOneDollars + " dollars " + " " + numberOfQuarters + " quarters " + " " + numberOfDimes + " dimes " + " " + numberOfNickels + " nickels " + " " + numberOfPennies + " pennies"); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.