• Post Reply Bookmark Topic Watch Topic
  • New Topic

Incompatible types on getter method in java with subclasses  RSS feed

 
Yarelly Gomez
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read through a number of different questions that have a similar issue but not what I'm struggling with specifically. I have created a total of 4 classes, a Bill class, a Money class and a Date class as well as a driver to test my output. These classes are supposed to be implemented for use in managing a set of outstanding and paid bills. When I attempt to run my main on my driver class I receive a "Incompatible types, money cannot be converted to int" and it points to my getDollars method. I am fairly new to java so my solution may be simple but I don't see what I'm doing wrong. Should I be returning an object?


This is the class that has an error when I run it in my driver.
The other classes are

Date Class

And my driver to test the code

Someone please help I'm so confused on what I'm doing wrong





 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two classes with the same name . How did you do this?
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have more mistakes into the code, for example this:

   

You described that method will return int, but, actually, you try to return Money. So, you need to decide what do you want.
Case 1. Return int.

   

Case 2. Return Money.

   
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think when you correct all the code, you will see exactly your problem places and we can help you
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think VL has probably answered your question. Thank you for using code tags, but you didn't quite get them right. More details here. Don't worry: I corrected the error, and I think I got it right, and doesn't it look better
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!