Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.*; public class PigLatin { public static Scanner kbd; public static void main(String[] args) { kbd = new Scanner(System.in); kbd.close(); } } (Here is

import java.util.*;

public class PigLatin {

public static Scanner kbd;

public static void main(String[] args) {

kbd = new Scanner(System.in);

kbd.close(); } }

(Here is the Starter Code)(Pay close attention to the rules and requirements)

Write a java application that acts as a one-word Pig Latin translator. Your program should:

ask the user to enter a word

convert the entered word into proper Pig Latin translation

print the translated word on the screen

The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on the values that the user types in while the program runs. The user's values are shown below in italics:

Please enter a word: pig Your word translated into Pig Latin is: igpay

Here's another example:

Please enter a word: latin Your word translated into Pig Latin is: atinlay

The rules for pig latin translation are as follows:

Rule #1: Words that start with a vowel (A, E, I, O, U) should simply have the characters "way" appended to the end of the word. For example, the word "apple" translates into "appleway" 'Y' is not counted as a vowel for this rule.

Rule #2: Words that start with a consonant should have all consonant letters up to the first vowel moved to the end of the word and then "ay" is appended. For example, the word "chair" translates into "airchay" 'Y' is considered to be vowel in this rule, so the word "xylophone" translates into "ylophonexay" It is possible that the word may not contain any vowels at all. In this case, following rule #2, you would simply append "ay" to the end of the word. For example, the word "crwth" translates into "crwthay"

Rule #3: When "Y" is the first letter of the word, the word should follow Rule #2. As an example, the word "yellow" translates into "ellowyay"

Program Requirements

The user should enter all lowercase letters. If the user enters any uppercase letters, you should convert to all lowercase before proceeding. Additionally, also remove any spaces that the user may enter at the beginning or end of the word. There are methods in the String class to do both of these tasks.

The main program should only do three basic things:

Get the input from the user

Use a method named translate to get the Pig Latin translation of the input word

Print the result to the screen

The main program is NOT allowed to do any String processing that is the job of the translatemethod. The main program should only do the three things listed above.

You must write and use a method called translate. This method should NOT get any values from the user/keyboard that job should be done by the main program. This method should be sent a String value from the main program. This string is the word which should be translated into Pig Latin. The method, then, should create a new string (you will need a local variable to hold this string temporarily). This new string will be the translation of the original word. Finally, this method will need to send the new string back to the main program so that the main program can print the final result.

The translate method is NOT allowed to print anything to the screen.

Declare the keyboard object as a class (global) variable as discussed in our class example. You are NOT allowed to use any other class (global) variables in this program. All other variables must be declared as local

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

20. Would opiates increase or decrease itch sensations?

Answered: 1 week ago