Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Group project code
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
marc.sheppard
Group project code
Commits
3510724a
Commit
3510724a
authored
Nov 21, 2019
by
marc.sheppard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
e1efcdfc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
Translator.java
Translator.java
+72
-0
No files found.
Translator.java
0 → 100644
View file @
3510724a
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Main program code
*
* @author Marc.
* Created 17 Nov 2019.
*/
public
class
Translator
{
static
int
languages
=
3
;
private
List
<
String
[]>
dictionary
=
new
ArrayList
<
String
[]>();
//constructor
public
Translator
()
{
//add words/phrases to dictionary
addWord
(
"hello"
,
"bonjour"
,
"hallo"
);
addWord
(
"goodbye"
,
"adieu"
,
"auf wiedersehen"
);
addWord
(
"thank you"
,
"merci"
,
"dankeschön"
);
addWord
(
"my"
,
"mon"
,
"mein"
);
addWord
(
"the"
,
"le"
,
"das"
);
addWord
(
"be"
,
"être"
,
"sein"
);
addWord
(
"to"
,
"à"
,
"zu"
);
addWord
(
"of"
,
"de"
,
"von"
);
addWord
(
"and"
,
"et"
,
"und"
);
addWord
(
"a"
,
"un"
,
"ein"
);
addWord
(
"in"
,
"dans"
,
"im"
);
addWord
(
"that"
,
"ce"
,
"das"
);
addWord
(
"have"
,
"avoir"
,
"haben"
);
addWord
(
"i"
,
"je"
,
"ich"
);
addWord
(
"it"
,
"il"
,
"es"
);
addWord
(
"for"
,
"pour"
,
"zum"
);
addWord
(
"not"
,
"ne pas"
,
"nicht"
);
addWord
(
"on"
,
"sur"
,
"auf"
);
addWord
(
"with"
,
"avec"
,
"mit"
);
addWord
(
"he"
,
"il"
,
"er"
);
addWord
(
"she"
,
"elle"
,
"sie"
);
addWord
(
"you"
,
"toi"
,
"du"
);
addWord
(
"time"
,
"temps"
,
"zeit"
);
addWord
(
"person"
,
"la personne"
,
"person"
);
addWord
(
"year"
,
"l' année"
,
"jahr"
);
addWord
(
"way"
,
"façon"
,
"weg"
);
addWord
(
"day"
,
"journée"
,
"tag"
);
addWord
(
"thing"
,
"chose"
,
"sache"
);
addWord
(
"world"
,
"monde"
,
"welt"
);
addWord
(
"life"
,
"la vie"
,
"leben"
);
addWord
(
"place"
,
"endroit"
,
"ort"
);
}
//returns translated word if it is in the dictionary else returns an empty string (note: case sensitive)
//input and and output languages (0 = English, 1 = French, 2 = German)
public
String
translate
(
String
word
,
int
input_language
,
int
output_language
)
{
int
dic_size
=
this
.
dictionary
.
size
();
//search for matching word by iterating though each word in the dictionary
for
(
int
index
=
0
;
index
<
dic_size
;
index
++)
{
//check if current word in inputed language matches inputed word and if so return translated word
if
(
this
.
dictionary
.
get
(
index
)[
input_language
].
equals
(
word
))
{
return
this
.
dictionary
.
get
(
index
)[
output_language
];
}
}
//if no matching word is found
return
""
;
}
//add word/phrase to dictionary (note: case sensitive)
private
void
addWord
(
String
english
,
String
french
,
String
german
)
{
int
index
=
this
.
dictionary
.
size
();
this
.
dictionary
.
add
(
new
String
[
languages
]);
this
.
dictionary
.
get
(
index
)[
0
]
=
english
;
this
.
dictionary
.
get
(
index
)[
1
]
=
french
;
this
.
dictionary
.
get
(
index
)[
2
]
=
german
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment