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
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
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,...
JAVA Exercise_Pick a Card Write a program that simulates the action of picking of a card...
JAVA Exercise_Pick a Card Write a program that simulates the action of picking of a card from a deck of 52 cards. Your program will display the rank and suit of the card, such as “King of Diamonds” or “Ten of Clubs”. You will need: • To generate a random number between 0 and 51 • To define two String variables: a. The first String should be defined for the card Suit (“Spades”, “Hearts”, “Diamonds”, “Clubs”) b. The second String...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...