Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the three classes 'Split', 'Word', and 'Sentence'. Test your work using 'PigLatinTester'. PLEASE DON T USE CHARAT ( ) ! ! ! ! public

Write the three classes 'Split', 'Word', and 'Sentence'. Test your work using 'PigLatinTester'. PLEASE DON
T USE CHARAT
()
!
!
!
!
public class Split
{
//
Declare String instance variables for first part and last part of the word.
/*
Write the constructor method. It will take one String parameter, the word
*
to be split.
*
In the constructor, do the following.
*
Determine an index to be the breakpoint, as described below. Assign
*
the substring before the breakpoint as the first part, the rest of the
*
word as the last part.
*
If word begins with
'
qu
'
or
'
Qu
"
,
returns that substring as the first part.
*
If word contains a
'
y
'
that is not the first character or the last character,
*
and that
'
y
'
is closer to the beginning of the word than any other vowels,
*
consider
'
y
'
a vowel, and break on that
'
y
'
.
*
Otherwise, the breakpoint should be at the first vowel
(
a
,
e
,
i
,
o
,
or u
)
.
*/
/*
Write public accessor
(
getter
)
method called 'getFirst' returning the first part of the word.
*
Use the signature
*
public String getFirst
()
*/
/*
Write public accessor
(
getter
)
method called 'getLast' returning the last part of the word.
*
Use the signature
*
public String getLast
()
*/
}
public class Word
{
//
Declare a static int variable keeping track of the number of words instantiated.
//
Declare a String instance variable to store pig latin translation of the word.
//
Declare a Split instance variable to hold the Split object made from the word.
//
Declare a boolean variable to record whether the the word was capitalized
//(
so the pig latin translation can be capitalized also
)
.
/*
Write the constructor. It take one String parameter for the word.
*
The String methods toLowerCase and
/
or toUpperCase may be useful in the constructor.
*
In the constructor, do the following
4
things.
*1.
Check to see whether the word is capitalized, and record whether or not it
*
is capitalized in your instance variable.
*2.
Next change the word to lowercase, and make a Split object from the lowercase
*
word. Store the split object in your instance variable.
*3.
Then call the method makePigLatinWord
(
described below
)
on the Split object and
*
store the returned pig latin translation of the word in your instance variable.
*4.
Add one to the static int variable, to record another Word instance.
*/
/*
Write a accessor
(
getter
)
method called 'getPigLatinWord' returning the pig latin translation
*
of the word.
*
Use the signature
*
public String getPigLatinWord
()
*/
/*
Write a accessor
(
getter
)
method called 'getNumberOfWords' returning the number of words
*
instantiated.
*
Use the signature
*
public static int getNumberOfWords
()
*/
/*
Write a method called 'makePigLatinWord' that takes the Split object as a parameter,
*
and returns the pig latin translation of the word.
*
The String methods toLowerCase and
/
or toUpperCase may be useful in the method.
*
Ensure that if the original word was capitalized, the pig latin translation is
*
also capitalized; otherwise, make it uncapitalized.
*
Use the signature
*
public String makePigLatinWord
(
Split splitWord
)
*/
}
public class Sentence
{
//
Declare String instance variables for the original sentence, and the pig latin translation
//
of the sentence.
/*
Write the constructor. It will take one String parameter containing the sentence
*
to be translated to pig latin.
*
Assign the value of the sentence parameter to the instance variable.
*
Traverse the characters in the sentence using looping and String methods you know.
*
For each word
(
a series of alphabetical characters A
-
Z or a
-
z
)
in the sentence,
*
find a pig latin translation, and concatenate that String onto the pig latin
*
translation of the sentence.
*
As you encounter each new non
-
alphabetical character
(
space
,
comma, period,
*
question mark, exclamation point, etc.
)
,
copy the character into the pig latin
*
translation in the orginal order.
*/
/*
Write a 'toString' method that returns a string containing the original sentence, the
*
pig latin translation of the sentence, and the number of words they both contain.
*
Use the signature
*
public String toString
()
*/
}
class PigLatinTester
{
public static void main
(
String
[]
args
){
String
[]
words
=
{"
Dear
"
,
"Queen", "Mary",
"
no
"
,
"there", "are",
"not", "three", "yucky", "argyle", "socks",
"
in
"
,
"
a
"
,
"drawer",
"
by
"
,
"our", "gym", "Love", "Abel"
}
;
String
[]
splitTestResults
=
{"
D
/
ear
"
,
"
Qu
/
een
"
,
"
M
/
ary
"
,
"
n
/
o
"
,
"
th
/
ere
"
,
"/
are
"
,
"
n
/
ot
"
,
"
thr
/
ee
"
,
"
y
/
ucky

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions