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

  • SEARCH
  • Home
  • 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 8996799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:48:11+00:00 2026-06-15T23:48:11+00:00

When i enter a value ( 202 cents ) it should give me this

  • 0

When i enter a value (202 cents) it should give me this amount either in 5 cents or 2 cents coins. Everything works fine in my code, but the output is given as System.out statement in the TwoCent and FiveCent class it self. WHat i want to do is to return the number of 5 cents and 2 cents coins so that i could capture and display it in my Test class.

Note: In the code below, the number of 2 and 5 cents coins are returned(displayed/printed to the console) from that class it self. but i want to modify the code so those methods (in the TwoCents and FiveCents classes) will return and int may be with the amount of coins. I should be able to get these values and display from the Test class only.

   public abstract class Coin {
    protected Coin co;
    public abstract void finCoin(Money m);
    public void setnext(Coin c) {
        co = c;
    }
}

public class TwoCent extends Coin{

    @Override
    public void finCoin(Money m) {
        if(m.getChange()%2==0){
          System.out.PrintLn("Return "+ m.getChange/2);
    else {
        int remainngCoins=m.getChange()*((m.getChange/2)*2));
        m.setChange(remainngCoins);
        co.setnext(m);
    }
}


public class FiveCent extends Coin{

    @Override
    public void finCoin(Money m) {
        if(m.getChange()%5==0){
          System.out.PrintLn("Return "+ m.getChange/5);
    else {
        int remainngCoins=m.getChange()*((m.getChange/5)*5));
        m.setChange(remainngCoins);
        co.setnext(m);
    }
}

public class Test {
public void showcoin(){
Coin f = new FiveCent();
        Cash t = new TwoCent();

        f.setSuccessor(t);

        Money cr = new Money(200);
        f.finCoin(cr);
}
}
  • 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-15T23:48:12+00:00Added an answer on June 15, 2026 at 11:48 pm

    Interesting, the definition of the abstract class Coin already describes that the method finCoin(Money m) must return an int. But in neither of the implementations (FiveCent and TwoCent) this value gets returned.

    What you do is replace the System.out.println stuff with a return like this:

    instead of

     @Override
    public void finCoin(Money m) {
        if(m.getChange()%5==0){
          System.out.PrintLn("Return "+ m.getChange/5);
    else {
        int remainngCoins=m.getChange()*((m.getChange/5)*5));
        m.setChange(remainngCoins);
        co.setnext(m);
    }
    

    ** you do **

     @Override
    public int finCoin(Money m) {   // VERY IMPORTANT replace void by int
        if(m.getChange()%5==0){
          // System.out.PrintLn("Return "+ m.getChange/5);
          return m.getChange/5;   // thats how you return a value and end this method call
        else {
          int remainngCoins=m.getChange()*((m.getChange/5)*5));
          m.setChange(remainngCoins);
          co.setnext(m);
        }
        return 0;   // this is just a guess but you MUST return something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MATLAB, I have this code: value = input('>> Enter a value: '); and
I have written a code to open a form if user enter value greater
I have the following: StringBuilder errors = new StringBuilder(); if(IsNullOrEmpty(value)) { errors.AppendLine(Enter value); }
I'm trying to enter a value in a specific records , I have a
I want to be able to enter a value and check if it is
I have a requirement that a user is allowed only to enter string value
With my Application, i want to make sure if user enter no value in
I am coding for a program whose detail is: 1. User enter the value
Below are my Page and Spec. I am able to enter the value for
I am developing an PHP/Mysql application whereby if the user enter a certain value,

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.