Ask Question
4 April, 05:23

1. Write a function that will ask the user to enter a value in dollars. The function should calculate and display the equivalent number of pennies, nickels, dimes, and quarters. Acceptable values are those which when multiplied by 100 will be exactly divisible by 50 (100*value must be exactly divisible by 50). Write a caller main function to call your function.

+4
Answers (1)
  1. 4 April, 07:14
    0
    import java. util. Scanner;

    public class Main

    {

    public static void main (String[] args) {

    valueInDollars ();

    }

    public static void valueInDollars () {

    double currentMoney, quarters, dimes, nickels, pennies;

    Scanner input = new Scanner (System. in);

    System. out. print ("Enter a value in dollars: ");

    currentMoney = input. nextDouble ();

    currentMoney * = 100;

    quarters = (int) currentMoney / 25;

    currentMoney = currentMoney % 25;

    dimes = (int) currentMoney / 10;

    currentMoney = currentMoney % 10;

    nickels = (int) currentMoney / 5;

    currentMoney = currentMoney % 5;

    pennies = currentMoney;

    System. out. print ("Quarters: " + quarters + "/n" + "Dimes: " + dimes + "/n" + "Nickels: " + nickels + "/n" + "Pennies: " + pennies);

    }

    }

    Explanation:

    Inside the function:

    - Declare the variables

    - Ask the user for a value in dollars

    - Multiply that value by 100

    - Find the amount of quarters, dimes, nickels, and pennies

    - Print the values

    Inside the main:

    - Call the function
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “1. Write a function that will ask the user to enter a value in dollars. The function should calculate and display the equivalent number of ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers