Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

STRING PROGRAMS

Be sure to include any pre and post conditions if you use any methods. Be sure
to comment ALL methods and segments thoroughly and meet the programming
expectations.
1.

Create a program that will take an input string and count all of the vowels
in the string. For the input word, the word should be printed and the
number of vowels in the word should be printed. Save the program as
VowelCounter your vowelcounter will use the countMe class.
Create a Class countMe that:
constructor takes in the string
isVowel that has an integer parameter of the
location to be checked and returns whether the
letter was a vowel

2.

Write a program that checks whether an entered string is a palindrome.


A palindrome is the same phrase spelled frontwards as it is backwards. Ex.
ABLE WAS I ERE I SAW ELBA. Save as palindrome your palindrome will use
the translator class
Create a Class translator that:
constructor that takes in the string and create an
original string and a new string
ChangeBackwards converts original string into a
new string which is backwards and returns the new
string
IsEqual checks to see if the new string is equal to the original
string and returns a boolean

3.

Im in a
palindrome

Write a program that converts a sentence into PIG LATIN. You may choose
to change your sentence to uppercase or lowercase to make your output
look consistent (the choice is up to you).

If a word begins with A, E, I, O, or U you simply add AY to the end


of the word
APPLE BECOMES APPLEAY
Otherwise, the consonants are taken off the beginning of the
word and added on to the end until a vowel is reached.
SAND BECOMES ANDSAY
PRUNE BECOMES UNEPRAY
THROUGH BECOMES OUGHTHRAY
Save the program as PigLatin it will use the subclass HerePiggy.
your driver class should look like this
System.out.print("Please enter your phrase ");
words = scan.nextLine();
//create your object
HerePiggy PigWord = new HerePiggy(words);
//translate your phrase
System.out.println(PigWord.translate());
Create a class called HerePiggy your constructor should take in a
phrase and set the number of words in the phrase (hint you will be
writing a method to do this). HerePiggy should have the following
methods:
WordCount returns the number of words to translate
(assume that--a sentence never starts with a ; there is
a word before every blank, and a sentence never ends
with a blank (hint there is one extra wordwhen you
get to the end of the string))
cutWord returns a word (takes off a word based the
location in translate)
translate returns the translated phrase back to the user
(hint this method should loop through the words, cut

the word off (hint keep track of what letter you are at
(must be global)), change to piglatin and add it to your
new phrase)
ChangePig changes the word to piglatin (hint you will
want to loop to cut off the first letter until you hit a
vowel)
4.

In math, there is a method of casting out nines to check to see if a


number is divisible by 9. First, you add the digits of a given integer. If the
result is bigger than 9, you add the digits again
(repeat until the number is ONE DIGIT (equal to 9
or is less than nine)). If the one digit number is 9
then the original number is divisible by 9
otherwise the original number was not divisible
by 9. SAVE AS CastingNines
EXAMPLE
INPUT 24 BECOMES 2 + 4 = 6 (do not have
to cast againonly 1 digit) original number
is NOT divisible by 9.
INPUT 684 BECOMES 6 + 8 + 4 = 18 1 + 8 = 9 original number is
divisible by 9
INPUT 93 BECOMES 9 + 3 = 12 1 + 2 = 3 original number is not
divisible by 9.
Hints
You must input a string--Numbers may not be cut apart
Once you cut the number off, it is still a string, you will have
to change it to a number (number =
Integer.parseint(stringnumber);remember to change a
string to an integer)
To change a number to a string (stringnumber =
String.valueof(number);remember to change a number to a
string)

Create a class called Cutter that has the following methods: (note
Cutter will not have a constructorwe will just use Cutter for its
methods)
SliceNAdd that takes in a stringcuts apart the string,
changes it to a number, and adds the digits up. The method
should return the new number.
IsGreater takes in a number and returns whether the
number is > 9
NineCast takes in a number and returns whether the
number = 9

You might also like