Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8120559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:11:26+00:00 2026-06-06T05:11:26+00:00

I have to write a Java program that tells what coins to give out

  • 0

I have to write a Java program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following:

86 cents can be given as 3 quarters, 1 dime and 1 penny.

Use coin denominations of 25, 10, 5, and 1. Your program will use the following method(among others):

public static int computeCoin(int coinValue,);
// Precondition: 0 < coinValue < 100; 
// Postcondition: returned value has been set equal to the maximum 
//number of coins of the denomination coinValue cents that can be 
//obtained from amount (a different variable) cents. amount has been 
//decreased by the value of the coins, that is, decreased by     
//returnedValue*coinValue.

So far this is what I have but I think I am missing more can somebody give me a hand?
And I am also not suppose to use doubles instead int.

public class Assignment6{
   public static void main(String [] args){
   amount = (int)(Double.parseDouble(args[0])*100);

   System.out.println("Five: " + computeCoin(500));
   System.out.println("one: " + computeCoin(100) );
   System.out.println("Q : " + computeCoin(25) );
   System.out.println("D : " + computeCoin(10) );
   System.out.println("N : " + computeCoin(5) );
   System.out.println("P : " + computeCoin(1) );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:11:28+00:00Added an answer on June 6, 2026 at 5:11 am
    public class Assignment6 {
        private static int amount = 0;
        public static void main(String[] args) {
            amount = (int)(Double.parseDouble(args[0])*100);
            System.out.println("Five: " + computeCoin(500));
            System.out.println("one: " + computeCoin(100) );
            System.out.println("Q : " + computeCoin(25) );
            System.out.println("D : " + computeCoin(10) );
            System.out.println("N : " + computeCoin(5) );
            System.out.println("P : " + computeCoin(1) );
        }
    
        public static int computeCoin(int cointValue) {
            int val = amount / cointValue;
            amount -= val * cointValue;
            return val;
        }
    }
    

    The trick here lies in the computeCoin method, and in the fact that the division is integer division, so val will hold the ‘maximum’ number of coins of the given value (coinValue) whose total value does not exceed amount.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a little Java program that stands in the middle of
I'm trying to write a java program that reads data from an image and
I have a Java program that mirrors a connection from a client server to
I have to write program that gets a number n from the user, and
I have been asked to write a java program on linux platform. According to
How to write a java program which will tell me whether I have internet
I have wrote the code below which was taken from Java How to program
I have to write an XML file using java.The contents should be written from
I am trying to write a java program that will automatically download and name
Problem: Write a program Deal.java that takes an command-line argument N and prints N

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.