Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Java language please. Begin by launching Eclipse and starting a new Java project for your work. In this assignment, your code will consist of two

Java language please.

Begin by launching Eclipse and starting a new Java project for your work. In this assignment, your code will consist of two classes:

  • PirateTranslator
  • SimpleLauncher

The PirateTranslator class will encapsulate the logic to translate English sentences into Pirate-speech. The SimpleLauncher class will contain the main method and the associated logic that will allow you to type in sentences and then have them translated for you. In this assignment, I've written the SimpleLauncher class for you (below), and you can simply type it into Eclipse.

This is SimpleLauncher:

import java.util.Scanner; public class SimpleLauncher { public static void main(String [] args) { PirateTranslator translator = new PirateTranslator(); Scanner userInput = new Scanner(System.in); String response; // userInput.hasNext() will return true until // you type 'Control-D' on a mac, or Control-Z on // a windows machine. if that happens, we need // to break out of the loop and stop. while(userInput.hasNext()) { System.out.println(translator.translate(userInput.nextLine())); } } } 

Implementing PirateTranslator

public class PirateTranslator { String[] phrases = {"hello", "hi", "is", "pardon me", "excuse me", "my", "friend", "sir", "madam", "stranger", "officer", "where", "you", "tell", "know", "how far", "old", "happy"}; String[] piratetalk = {"ahoy", "yo-ho-ho", "be", "avast", "arrr", "me", "me bucko", "matey", "proud beauty", "scurvy dog", "foul blaggart", "whar", "ye", "be tellin'", "be knowin'", "how many leagues", "barnacle-covered", "grog-filled"}; String[] positiveWords = {"adore", "enjoy", "love"}; String[] negativeWords = {"hate", "despise", "dislike"}; String[] lastTranslations = new String[25]; int s = 0; /** * _Part 1: Implement this method_ * * Translate the input string and return the resulting string */ public String translate(String input) { // TODO: implement this return null; } } 

Within your Eclipse/IntelliJ project, create a new Class called PirateTranslator. This class should have one public method with the following signature:

public String translate(String input)

The method should take an input string, and output a version of that string that has been translated into Pirate-speech. For example the phrase "hello officer" should be translated as "ahoy foul blaggart". Below is a list of normal english words/phrases and their Pirate-speech counter parts.

English phrases: "hello", "hi", "pardon me", "excuse me", "my", "friend", "sir", "madam", "stranger", "officer", "where", "you", "tell", "know", "how far", "old", "happy"

Pirate counterparts: "ahoy", "yo-ho-ho", "avast", "arrr", "me", "me bucko", "matey", "proud beauty", "scurvy dog", "foul blaggart", "whar", "ye", "be tellin'", "be knowin'", "how many leagues", "barnacle-covered", "grog-filled"

Your translate method should accept strings with arbitrary capitalization, however, it can return translated strings that are all in lower case.

Once you can successfully translate simple sentences into pirate speech, you should add logic to your translate method that attempts to detect the sentence's affect. For simplicity, we'll consider three possibilities for affect: positive, negative, and none.

A user response should be considered positive if it contains one of the following strings: adore, love, enjoy. A response should be considered negative if it contains one of these strings: dislike, hate, despise. If the user response contains neither a negative affect string nor a positive affect string, or it if contains both, then the affect should be considered none. When examining the user's response for affect, you should ignore case. Thus a user response of "I HATE that" should be treated identically to "i hate that". Note that there are no gradations of affect; affect is simply positive, negative, or none.

For negative affect sentences, you should append "...'tis like bein' food for the fish!" to the end of the translation. For positive affect sentences, you should append "...'tis like me pirate treasure!" to the end of the translation. Thus an input sentence "I adore you" would translate to "I adore ye 'tis like me pirate treasure!".

Thus, for full credit:

  1. Translate english phrases into their pirate-speech counterparts
  2. Translate arbitrary capitalization on input, but return all lower case output
  3. Detect the affect of input sentences and append metaphor appropriately

Also, create another method that performs the same function as translate but retains the original capitalization of the input sentence (instead of returning a string that is in all lower-case). This new function should have the signature:

Example Output

Below is a sample trace from my program when I run SimpleLauncher. Translations are in italics.

> hello

ahoy

> hello friend

ahoy me bucko

> I adore you

i adore ye...'tis like me pirate treasure!

> I hate you

i hate ye...'tis like bein' food for the fish!

> where is my old boat?

whar be me barnacle-covered boat?

> pardon me sir, do you know where my old boat is?

avast matey, do ye be knowin' whar me barnacle-covered boat be?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students explore these related Databases questions