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
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...
would someone kindly convert the following C code to java? thanks so much # include <stdio.h>...
would someone kindly convert the following C code to java? thanks so much # include <stdio.h> int main(void) { int changeOwed; int check; char invisibleChar; int count = 0; int numQ=0, numD=0, numN=0, numP=0; do{ printf("How much change is owed (in cents)?\n"); check = scanf("%d", &changeOwed); // returns 1 if the input is a number and returns 0 otherwise //Get's rid of any extra invisible characters if the input is a char/String do{ scanf("%c",&invisibleChar); }while(invisibleChar != '\n'); }while(check == 0...
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per...
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers on a ticket....
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...