• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Mooc fi. Part 5 Part4 Adding Money

 
Ranch Hand
Posts: 1049
1
  • 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.
 
Bartender
Posts: 10964
87
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: 1049
1
  • 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
Bartender
Posts: 10964
87
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: 1049
1
  • 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: 80085
412
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic