• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Mooc fi. Part 5 Part4 Adding Money

 
Ranch Hand
Posts: 1013
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to get someone to send me the Part 5 exercises but without the TCMBeans I can't tell what is wrong cos I am using Eclipse.

I hope someone can tell me how to overcome the error in this case:

The requirements as follows :
Let's create a method for the terminal that can be used to add money to a payment card. Recall that the payment that is received when adding money to the card is stored in the register. The basis for the method:




My question is at the Main Program public static void main(String[]args) there is this line new PaymentCard(10) but eclipse is saying that



eatAffordably is int but the method contains a reference object PaymentCard so is there anything wrong with the program or how should I overcome the error ?

Thanks.
 
Saloon Keeper
Posts: 10546
83
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method says that it is expecting a PaymentCard as an argument, not an int.
 
tangara goh
Ranch Hand
Posts: 1013
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:The method says that it is expecting a PaymentCard as an argument, not an int.



But, at the public void main(String [] args) it has 10 inside the eatAffordably method...is that a mistake then ?
unicafeExactum.eatAffordably(10);
 
Carey Brown
Saloon Keeper
Posts: 10546
83
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, one or the other is a mistake. Seeing as how you have a Card class I'm going to guess that the '10' is the mistake.

There's something not quite right with your Terminal class, it is maintaining a cardBalance. That should be the job of the Card class not the Terminal class.
This code is not defining which class is responsible for what very clearly. Who is supposed to handle card balance? Why does Terminal even have 'money'? The test for balance compared to 2.50 is already in the Card class (see takeMoney()) but you're not using it.
 
tangara goh
Ranch Hand
Posts: 1013
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Well, one or the other is a mistake. Seeing as how you have a Card class I'm going to guess that the '10' is the mistake.

This code is not defining which class is responsible for what very clearly. Who is supposed to handle card balance? Why does Terminal even have 'money'? The test for balance compared to 2.50 is already in the Card class (see takeMoney()) but you're not using it.



Thanks Carey.

The CardBalance is my mistake.  It is not there in the template code but I was trying to solve the previous part I, II and III and probably my method is wrong, even though the answer can be derived.
But, now with part IV, I can see that it is a real problem cos now I can't get the answer now.

 
Marshal
Posts: 78656
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is using doubles for money also in the template code? That is another mistake.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic