Question

4) Create the following in a Java program. Create a Scanner Prompt the user to Receive...

4) Create the following in a Java program.

Create a Scanner
Prompt the user to Receive the amount and declare the variable double amount for scanner
Declare variable integer remaining amount which is equal to (int) (amount*100)
Find the number of one dollars bt declaring the integer variable which is equal to remaining amount divided by 100
Declare: remaining amount %=100

Find the number of quarters:
Declare integer variable number of quarters equal to remaining amount divided by 25
Declare: remaining amount %=25

Find the number of dimes:
Declare integer variable number of dimes equal to the remaining amount divided by 10
Declare: remaining amount %=10

Find the number of nickels:
Find the number of nickels in the remaining amount divided by 5
Declare: remaining amount %=5

Find the number of pennies in the remaining amount
Where declare variable integer number of pennies equals to remaining amount

Display results:
System.out.println("Your amount " + amount + " consists of");
System.out.println(" " + numberOfDollars + (numberOfDollars == 1 ? " dollar" : " dollars"));
Instead of dollars using same line as above display the rest:
Display the number of quarters
Display the number of dimes
Display the number of nickels
Display the number of pennies

Homework Answers

Answer #1

Please upovte if you are able to understand this and if there is any query do mention it in the comment section.

CODE:

import java.util.Scanner;//importing the Scanner class from util package

public class Main
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);//creating object of Scanner class
       System.out.println("Enter amount");
       double amount = sc.nextDouble();//taking input from the user
       int remainingAmount = (int)(amount * 100);//calculating remainingAmount and coverting to int
       System.out.println("remainingAmount");
       int numberOfDollars = remainingAmount % 100;//calculating numberOfDollars
      
       int numberOfQuarters = remainingAmount % 25;//calculating numberOfQuarters
       int numberOfDimes = (int)(amount % 10);//calculating numberOfDimes and coverting to int
       int numberOfNickels = (int)(amount % 5);//calculating numberOfNickels and coverting to int
       int numberOfPennies = remainingAmount;//calculating pennies
      
       System.out.println("Your amount " + amount + " consists of");
       System.out.println(" " + numberOfDollars + (numberOfDollars == 1 ? " dollar" : " dollars"));
       System.out.println(" " + numberOfQuarters + (numberOfQuarters == 1 ? " quarters" : " quarters"));
       System.out.println(" " + numberOfDimes + (numberOfDimes == 1 ? " dimes" : " dimes"));
       System.out.println(" " + numberOfNickels + (numberOfNickels == 1 ? " nickels" : " nickels"));
       System.out.println(" " + numberOfPennies + (numberOfPennies == 1 ? " pennies" : " pennies"));
   }
}

OUTPUT:

If this was supposed to be done in any other way or something is required to be modified then please mention it in the comment section otherwise please upvote.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
5) Create a Java program using Scanner: Write a program where you will enter the grade...
5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage. Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math 2) Declare variable total and percentage 3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class 4) Calculate total of...
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
Create a Change application that prompts the user for an amount less than $1.00 and then...
Create a Change application that prompts the user for an amount less than $1.00 and then displays the minimum number of coins necessary to make the change. The change can be made up of quarters, dimes, nickels, and pennies. The application output should look similar to: Enter the change in cents: 212 The minimum number of coins is: Quarters: 8 Dimes: 1 Nickels 0 Pennies: 2 Must be coded in Java please
Create a function called totalCoins that takes an integer price of a product (in pennies) and...
Create a function called totalCoins that takes an integer price of a product (in pennies) and an integer amount of money paid (in pennies). It should return via output parameters the number of dollars, quarters, dimes, nickels, and pennies given as change. Must use pointers. C programming
2). Question with methods use scanner (Using Java): You are going to invest the amount, then...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then you going to compute that amount with annual interest rate. 1) Prompt the user to enter student id, student name, student major 2) Declare variables consistent with names that you are prompting and relate them to the scanner 3) Declare the amount invested in college, prompt the user to ask for amount and declare variable and scanner to input 4) Declare the annual interest...
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
5) Write a java program with scanner object to input first number and second number as...
5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement. Steps: 1) Declare scanner object 2) Ask system out print for first number and declare variable first number 3) Ask system out print for second number and declare variable second number 4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and...
JAVA Prompt the user for 10 numbers using a while loop. Create an int variable number....
JAVA Prompt the user for 10 numbers using a while loop. Create an int variable number. You have three additional int variables pos, neg, and zero. Your goal is to determine the number of positive, negative, and zeroes in the list of the ten numbers read in.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT