https://github.com/rabestro/roman-arabic-calculator
This code is a proof of concept. The calculator can work with both Arabic (1,2,3,4,5 ...) and Roman (I, II, III, IV, V ...) numbers.
https://github.com/rabestro/roman-arabic-calculator
arabic-numbers calculator functional-programming lambdas pattern-matching prof-of-work roman-numerals validation
Last synced: 3 months ago
JSON representation
This code is a proof of concept. The calculator can work with both Arabic (1,2,3,4,5 ...) and Roman (I, II, III, IV, V ...) numbers.
- Host: GitHub
- URL: https://github.com/rabestro/roman-arabic-calculator
- Owner: rabestro
- License: mit
- Created: 2020-07-31T12:49:43.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T08:03:58.000Z (over 2 years ago)
- Last Synced: 2024-12-28T05:25:26.599Z (5 months ago)
- Topics: arabic-numbers, calculator, functional-programming, lambdas, pattern-matching, prof-of-work, roman-numerals, validation
- Language: Java
- Homepage:
- Size: 171 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# roman-arabic-calculator
This code is proof of concept. It checks possibility of validation of user input by Scanner class.
## The requirements
1. The calculator can perform operations of addition, subtraction, multiplication and division with two numbers: a + b, a - b, a * b, a / b. Data is entered in one line.
2. The calculator can work with both Arabic (1,2,3,4,5 ...) and Roman (I, II, III, IV, V ...) numbers.
3. The calculator must accept numbers from 1 to 10 inclusively. At the output, the numbers are not limited in size and can be any.
4. The calculator can only work with whole numbers.
5. The calculator can only work with Arabic or Roman numerals at the same time, when the user enters a line like 3 + II, the calculator should throw an exception and stop working.
6. When the user enters inappropriate numbers, the application throws an exception and exits.
7. When the user enters a string that does not match one of the above arithmetic operations, the application throws an exception and exits.## The implementation
The main idea is to validate user input using [next(String pattern)](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Scanner.html#next(java.lang.String)) method of Scanner class. It allows to throw [InputMismatchException](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/InputMismatchException.html) immediately after incorrect user input. To fulfill the condition for the simultaneous input of either Arabic or Roman numbers, we determine the mode by the first number and use the appropriate pattern for the second number.