1.3-Object-Georienteerd-Programmeren

Multilingualism

In this assignment, we are going to create an application that supports multiple languages. Given is the class Translator (code below) which can be used to implement a specific language. This class contains the following attributes: the name of the language, the currency symbol (e.g. $ or €), the conversion rate to the euro, and the time format (e.g. 24-hour or 12-hour with AM and PM). In addition, there are:

We will now implement three specific languages: Dutch, Russian and English (American). Create new classes that inherit from the Translator class and make sure you include the correct values in the call to the super() constructor. Then overwrite the methods with default messages in your class and put a translation in it. (Tip: use Google Translate if you are not familiar with the language).

Finally, add another language of your own choice!

Translation.java

package nl.saxion.oop.week4.model;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Translation {
    private String language;
    private String currency;
    private double conversionRate;
    private String timeFormat;

    public Translation(String language, String timeFormat, String currency, double conversionRate) {
        this.language = language;
        this.timeFormat = timeFormat;
        this.currency = currency;
        this.conversionRate = conversionRate;
    }

    public String getGreeting() {
        throw new IllegalStateException("Translation.getGreeting() called!");
    }

    public String getExplanation() {
        throw new IllegalStateException("Translation.getExplanation() called!");
    }

    public String getLanguage() {
        return language;
    }

    public String getTimeInFormat() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(timeFormat));
    }

    public String getCurrency() {
        return currency;
    }

    public double convertFromEuro(int nrOfEuro) {
        return nrOfEuro * conversionRate;
    }
}

Example

The following text is displayed in: Russian

Уважаемые ученики!

Этот пример переведен без усилий....используя наследование!

The current time would be printed as 06.03.2023 14:58:54 in this country.

1 Euro would be worth 89.5861 Ruble
25 Euro would be worth 2239.6525 Ruble

(Disclaimer: As no teachers speak Russian, our translations are created using tooling. If these texts are incorrect and you want to suggest a better alternative, please let us know!)

This output was generated by:

RussianTranslation translation = new RussianTranslation(); // Change this!

System.out.println("The following text is displayed in: " + translation.getLanguage());
System.out.println();

System.out.println(translation.getGreeting());
System.out.println();
System.out.println(translation.getExplanation());
System.out.println();

System.out.println("The current time would be printed as " + translation.getTimeInFormat() + " in this country.");
System.out.println();

System.out.println("1 Euro would be worth " + translation.convertFromEuro(1) + " "+ translation.getCurrency());
System.out.println("25 Euro would be worth " + translation.convertFromEuro(25) + " "+ translation.getCurrency());