Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help for Implementing Hexadecimal Calculator using polymorphism  RSS feed

 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends!
I am writing a program to implement a console based calculator which will perform some basic arithmatic operation.
It will provide two mode i.e. Decimal mode and hexadecimal mode.
Since my project require polymorphism, i have to use same function name for both Decimal as well as hexadecimal.
I wrote a code for decimal calculator. but cant find solution how to implement these same function for hexadecimal.

here is my function list for decimal calculator:



I want to used these same function names for hexadecimal arithmatic calculations.
Please provide some help regarding this!

Thanks In Advanced
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hexadecimal is just a different way of representing quantities. And since Java allows for int and double literals to be hexadecimal (preceded by 0x), your methods should work just fine using input of either form.

However, the output will be in base 10. So if your calculator is in "hex mode," then you will need to convert the output back to hex for display. The classes Integer and Double have methods that will take care of this for you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!