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.
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.
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.
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...
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