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 7005083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:18:25+00:00 2026-05-27T21:18:25+00:00

I’m stuck with this Java homework question: Write a new method, Refund, that simulates

  • 0

I’m stuck with this Java homework question:

Write a new method, Refund, that simulates the refunding of any remaining credits in multiples of 10 by repeatedly printing out the balance and decrementing by 10 each time until there is less than 10 credits remaining. Then begin decrement the balance by 1 credit repeatedly whilst printing to screen until the balance is zero. For example, if the current balance is 33 and Refund is called, the output to screen will look like this:

Balance: 33
Balance: 23
Balance: 13
Balance: 3
Balance: 2
Balance: 1
Balance: 0

It works perfectly fine with any number except numbers ending in ‘0’ i.e. 10,30,100 etc.

Here’s my Refund method:

public void Refund(){
    System.out.println("You have selected the refund option:");

    for(int counter=(int)balance;counter>=10;counter-=10){
        System.out.println("Balance: £"+balance);
        balance-=10;
    }

    for(int counter=(int)balance;counter>0;counter-=1){
        System.out.println("Balance: £"+balance);
        balance-=1;
    }

    System.out.println("Balance: £"+balance);
}

Basically, the only way I can make it work with 10,30 etc. numbers is to do

for(int counter=(int)balance-10;counter>=10;counter-=10){

in the following for statement (Refund method):

for(int counter=(int)balance;counter>=10;counter-=10){
System.out.println("Balance: £"+balance);
balance-=10;
}

However, now that I’ve done that, 10,30,100 work but any other numbers i.e. 33,54,62 etc. don’t work! Any suggestions?

  • 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-05-27T21:18:26+00:00Added an answer on May 27, 2026 at 9:18 pm

    Just to clarify the question. Your Refund method works fine.

    It suits your constrain “decrementing by 10 each time until there is less than 10 credits remaining”.
    It won’t suit if you change the constrain to is less or equal 10.

    Here is my test, that works:

    public class Main {
    
        public static void main(String[] args) {
            Main m = new Main();
            m.refund(33);
        }
    
        public void refund(float balance) {
            System.out.println("You have selected the refund option:");
    
            for (int counter = (int) balance; counter >= 10; counter -= 10) {
                System.out.println("Balance: £" + balance);
                balance -= 10;
            }
    
            for (int counter = (int) balance; counter > 0; counter -= 1) {
                System.out.println("Balance: £" + balance);
                balance -= 1;
            }
    
            System.out.println("Balance: £" + balance);
        }
    }
    

    I haven’t modified the body of your method.

    Here is the output on 30 input:

    You have selected the refund option:
    Balance: £30.0
    Balance: £20.0
    Balance: £10.0
    Balance: £0.0
    

    And on 33:

    You have selected the refund option:
    Balance: £33.0
    Balance: £23.0
    Balance: £13.0
    Balance: £3.0
    Balance: £2.0
    Balance: £1.0
    Balance: £0.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.