In: Computer Science
Write a simple JAVA program to understand natural language.
The user will enter the input following the format:
Name came to City, Country in Year.
For example:
Chris came to Bangkok, Thailand in 2009.
The user will follow the exactly the same formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format:
Name stay in City for X year(s). City is in Country.
For example
Chris stay in Bangkok for 11 years. Bangkok is in Thailand.
* note X = 2020-Year.
Example of the output to illustrate the expected behavior of your program.
Hint: you may use Integer.parseInt() to convert a string to an integer.
Translator Program
---------------------------------------------------------
Please enter the input sentence (press q to exit):
Chris came to Bangkok, Thailand in 2009.
Chris stays in Bangkok for 11 years. Bangkok is in thailand.
Please enter the input sentence (press q to exit):
Lee came to Paris, France in 2000.
Lee stay in Paris for 20 years. Paris is in France.
Please enter the numbers along operation (press q to exit):
q
Thank you
Here is the answer for your question in Java Programming Language.
Kindly upvote if you find the answer helpful.
#######################################################################
CODE :
public class NatiralLanguage { |
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
########################################################################
OUTPUT :
Any doubts regarding this can be explained with pleasure :)