In: Computer Science
You'll notice that in the LearnAboutLanguages class there are a
few todos. You need to implement the three missing classes (
RussianSpeaker, JapaneseSpeaker and SwahiliSpeaker ). Then
uncomment all the stuff marked "todo" and run the code!
Submit
1. Your three new .java files
2. A screenshot of your correct code running on your computer.
--
public class EnglishSpeaker implements LanguageSpeaker{
@Override
public String GetMyLanguage() {
return "English";
}
@Override
public String GetHi() {
return "Hi";
}
@Override
public String GetBye() {
return "Bye";
}
}
--
public interface LanguageSpeaker {
String GetMyLanguage();
String GetHi();
String GetBye();
}
--
public class LearnAboutLanguages {
public static void teachLanguage(LanguageSpeaker
speaker) {
System.out.println("Hello, I speak
" + speaker.GetMyLanguage());
System.out.println("To say
\"hello\", we say: " + speaker.GetHi());
System.out.println("To say \"bye\",
we say: " + speaker.GetBye());
System.out.println();
}
public static void main(String[] args) {
LanguageSpeaker australian = new
EnglishSpeaker();
LanguageSpeaker uruguayan = new
SpanishSpeaker();
LanguageSpeaker mozambican = new
PortugueseSpeaker();
//TODO
// LanguageSpeaker russian = new
RussianSpeaker();
// LanguageSpeaker japanese = new
JapaneseSpeaker();
// LanguageSpeaker kenyan = new
SwahiliSpeaker();
teachLanguage(australian);
teachLanguage(uruguayan);
teachLanguage(mozambican);
//TODO
//teachLanguage(russian);
//teachLanguage(japanese);
//teachLanguage(kenyan);
}
}
--
public class PortugueseSpeaker implements LanguageSpeaker{
@Override
public String GetMyLanguage() {
return "Português";
}
@Override
public String GetHi() {
return "olá";
}
@Override
public String GetBye() {
return "tchau";
}
}
--
public class SpanishSpeaker implements LanguageSpeaker{
@Override
public String GetMyLanguage() {
return "Español";
}
@Override
public String GetHi() {
return "Hola";
}
@Override
public String GetBye() {
return "Adios";
}
}
I have implemented below three .java files::
1> RussianSpeaker.java :-
public class RussianSpeaker implements LanguageSpeaker{
@Override
public String GetMyLanguage() {
return "русский";
}
@Override
public String GetHi() {
return "Здравствуй";
}
@Override
public String GetBye() {
return "до свидания";
}
}
2> JapaneseSpeaker.java:-
public class JapaneseSpeaker implements LanguageSpeaker{
@Override
public String GetMyLanguage() {
return "Японский";
}
@Override
public String GetHi() {
return "こんにちは";
}
@Override
public String GetBye() {
return "さようなら";
}
}
3> SwahiliSpeaker.java
public class SwahiliSpeaker implements LanguageSpeaker{
@Override
public String GetMyLanguage() {
return "Kiswahili";
}
@Override
public String GetHi() {
return "Hi";
}
@Override
public String GetBye() {
return "Kwaheri";
}
}
Program :-
public class LearnAboutLanguages {
public static void teachLanguage(LanguageSpeaker speaker) {
System.out.println("Hello, I speak " + speaker.GetMyLanguage());
System.out.println("To say \"hello\", we say: " + speaker.GetHi());
System.out.println("To say \"bye\", we say: " + speaker.GetBye());
System.out.println();
}
public static void main(String[] args) {
LanguageSpeaker australian = new EnglishSpeaker();
LanguageSpeaker uruguayan = new SpanishSpeaker();
LanguageSpeaker mozambican = new PortugueseSpeaker();
//TODO
LanguageSpeaker russian = new RussianSpeaker();
LanguageSpeaker japanese = new JapaneseSpeaker();
LanguageSpeaker kenyan = new SwahiliSpeaker();
teachLanguage(australian);
teachLanguage(uruguayan);
teachLanguage(mozambican);
//TODO
teachLanguage(russian);
teachLanguage(japanese);
teachLanguage(kenyan);
}
}
Output:-
I hope you will understand the above program.
Do you feel needful and useful then please upvote me.
Thank you.