Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How can I create a program which performs basic maths between an emoji and a number in Java?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I would like to create a basic maths calculator using emojis and numbers, like πŸ’―+2= 102. I need Java to read the πŸ’― as 100, or 1️⃣ as 1. I also need that the output to be either a number or an emoji (i.e if I perform 2x2, the output to be either 4️⃣ or 4). Hope it makes sense. I've been searching for different solutions, but I did not find anything useful.
Any idea?

Thank you in advance!
 
Marshal
Posts: 7794
536
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure about the emojis, but how about if you start with a simple calculator first, so it works just with an actual numbers?
 
Liutauras Vilda
Marshal
Posts: 7794
536
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if were in need to understand those requirements, I'd have a lot questions.

Diane Branco wrote:if I perform 2x2, the output to be either 4️⃣ or 4...
Hope it makes sense.


No. What makes one or other form of answer to be shown, how is decided?

 
Marshal
Posts: 70718
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can easily read both operators and emojis from the keyboard with programs like Scanner#next(). Make sure to separate them by spaces, so 😻+7 is regarded as incorrect input. There are also Scanner#hasNextXXX() methods which allow you to tell that the following token is a particular type.
An emoji is usually a Unicode code point > 0x0000_ffff, and that comes out as an int. You can look up their values on the Unicode website. I shall let you work out what sort of data structure is supplied ready‑made that can map an emoji (a number) to another number, so you can have 😱 ↦ 123 or similar.
 
Saloon Keeper
Posts: 12436
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Liutauras. You first need clear requirements.

What is the result of πŸ’―+ 4️⃣?
 
Bartender
Posts: 2704
130
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest first defining the domain for your problem. Certain emoji are rendered differently depending on clients.
E.g. a Calendar can be shown as '1' in certain clients and '31' on certain clients. I dont think there's a way for you to know what's the displayed character. Next, there are multiple emojis that can show the same number.
e.g. both 1️⃣ and πŸ• can mean 1.
Your code needs to either decide on using one of them or both of them.

Here's a short table I made : This is my interpretation only. Your table might differ.

 
salvin francis
Bartender
Posts: 2704
130
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding a few more items ...
  • There are mathematical operators in emojis as well: βž• (plus), βž– (minus), βž— (divide), βœ–οΈ (multiply), ❌ (multiply), ❎ (multiply) are you going to support them ?
  • Are you going to consider multiple emojis as a single number? e.g. 1️⃣2️⃣3️⃣4️⃣  as 1234
  • Are you going to consider multiple operators ?  e.g. 1️⃣0️⃣ ❌ 9️⃣ βž• πŸ”Ÿ returns πŸ’― ?  
  •  
    Diane Branco
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Firstly, thank you all for the answers.

    Indeed, I need to support the mathematical operators in emojis as well, also meed to consider multiple emojis as a number and to consider multiple operators.

    Like this:

    input: 9 ❌ 9 +1
    output: 82

    input: πŸ”Ÿ + 8 / 4
    output: 1️⃣2️⃣

    As far as the domain is concerned, I would need to represent the numbers as keycaps (e.g 0️⃣1️⃣2️⃣3️⃣...) and also using different symbols (e.g 🎱 for 8 and πŸ’― for 100).

    So far, I made a simple calculator program. I've also used the Map Interface to represent emojis as numbers, but that's all.
     
    salvin francis
    Bartender
    Posts: 2704
    130
    Google Web Toolkit Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I think your program should follow the following basic steps:

    Input >> Interpret >> Validate >> Solve >> Translate >> Output

    Input: Accept text from user (or test case)
    Interpret : Convert number into text form. e.g. πŸ”Ÿ to "10"
    Validate : Ensure the equations are valid, e.g.  10 xx 10, 10 ++ 10 -- 3, etc...
    Solve : This is where you can get creative, you can either make a full fledged number parser or you can simply use the underlying javascript engine or some other library to get the final numerical answer
    Translate : convert final result back to emoji like "100" to πŸ’―and so on... You can even randomly choose to either output a number or emoji for every number
    Output : Show the result to the user

    We would love to see what you've made so far !
     
    What's that smell? Hey, sniff this tiny ad:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
    reply
      Bookmark Topic Watch Topic
    • New Topic