SlideShare a Scribd company logo
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13th
Words Assignment
Robert Glen Martin
School for the Talented and Gifted, Dallas, TX
Based on the Lab16c assignment from Stacey Armstrong
© A+ Computer Science - www.apluscompsci.com
Introduction
The purpose of this assignment is to give students practice with Strings, arrays, and ArrayLists. It
also provides the opportunity to work with several interacting classes.
Overview
This project utilizes three new classes:
- Word- an immutable class representing a word
- Words - a class representing a list of Word objects
- WordTester- a class used to test the Word and Words classes.
Starter Code
The folder Words Student contains a JCreator project with starter code for the three classes.
WordTester (the application) is complete and only requires uncommenting to test the Word and
Words classes as they are completed. The needed imports, class headings, method headings, and
block comments are provided for the remaining classes. Javadocs are also provided for the Word
and Words classes.
Word – This part of the lab has been done for you.Look at the main WordTester to see how it
uses a Word object. Run the main to see the results of the tester code.
The Word class represents a single word. It is immutable. You have been provided a skeleton for
this class. Complete the Word class using the block comments, Javadocs, and the following
instructions.
1. Add a String instance variable named word which will contain the word.
2. Complete the one parameter constructor to initialize the word instance variable.
3. Complete the getLength method to return the number of characters in the word.
4. Complete the getNumVowels method to return the number of vowels in the word. It should
use the VOWELS class constant and String’s length, substring, and indexOf methods. Do not use
more than one loop. Do not use any String methods that are not in the AP Subset.
5. Complete the getReverse method to return a Word with the letters of this reversed.
6. Complete the toString method to return the String word.
7. Uncomment the Word test code in WordTester and make sure that Word works correctly.
Words
The Words class represents a list of words. You have been provided a skeleton for this class.
Complete the Words class using the block comments, Javadocs, and the following instructions.
Step has been done for you.
1. Add a List instance variable named words which will contain the list of words. Be sure to
specify the type of objects that will be stored in the List. Be sure that the instance variable is
private.
2. Complete the one parameter constructor to initialize the words instance variable. You will
need to create the ArrayList and add each word to it. Be sure to create a new Word object with
each String in the parameter array wordList and then add it to the ArrayList words. This would
be a great place to use a for-each loop. Your code should not generate any warnings.
3. Complete the countWordsWithNumChars method to return the number of words with lengths
of num characters.
4. Complete the removeWordsWithNumChars method to remove all words with lengths of num
characters.
5. Complete the countWordsWithNumVowels method to return the number of words that have
num vowels.
6. Complete the getReversedWords method to return an array of reversed words.
7. Complete the toString method to return the words as a String. You should utilize ArrayLists’s
toString method.
8. Uncomment the Words test code in WordTester and make sure that Words works correctly.
STARTER CODES AND SETUP
Word
/**
* Word.java 06/08/08
*
* @author - Jane Doe
* @author - Period n
* @author - Id nnnnnnn
*
* @author - I received help from ...
*
*
* Based on the Lab16c assignment
* Used with permission from Stacey Armstrong
* ? A+ Computer Science - www.apluscompsci.com
*/
/**
* A Word object represents a word.
*/
public class Word
{
/** The 5 vowels */
private static final String VOWELS = "AEIOUaeiou";
/** The word */
private String word;
/**
* Constructs a Word object.
* @param w the string used to initialize the word.
*/
public Word(String w)
{
word = w;
}
/**
* Gets the length of the word.
* @return the length (number of characters) of the word.
*/
public int getLength()
{
return word.length();
}
/**
* Gets the number of vowels in the word.
* @return the number of vowels (Characters in VOWELS in
* the word.
*/
public int getNumVowels()
{
int count = 0;
for (int i = 0; i < word.length(); i++)
{
String letter = word.substring(i, i + 1);
if (VOWELS.indexOf(letter) >= 0) //if letter is found in VOWELS, its a vowel
{
count++;
}
}
return count;
}
/**
* Gets the reverse word.
* @return a Word with this's
* letters reversed.
*/
public Word getReverse()
{
String reverse = ""; //Start the string as an empty string
for (int i = word.length() - 1; i >= 0; i--)
{
reverse += word.substring(i, i + 1); //build the string backward
}
return new Word(reverse); //must convert the string to a Word object to match
//the return type
}
/**
* Gives the string representing the word.
* @return the string representing the word.
*/
public String toString()
{
return word; // Replace
}
}
WORDS
/**
* Words.java 06/08/08
*
* @author - Jane Doe
* @author - Period n
* @author - Id nnnnnnn
*
* @author - I received help from ...
*
*
* Based on the Lab16c assignment
* Used with permission from Stacey Armstrong
* A+ Computer Science - www.apluscompsci.com
*/
import java.util.List; //You must import this to use the List datatype for the reference
import java.util.ArrayList;//Needed to instantiate an ArrayList
/**
* Words represents a list of Word objects.
*/
public class Words
{
/** The Words */
private List words;
/**
* Constructs a Words object.
* @param wordList the words for the Words object.
*/
public Words(String[] wordList)
{
words = new ArrayList();
//complete the constructor by using a loop to access each String in wordList,
//creating a Word object with each String and adding the Word object to the
//ArrayList.
}
/**
* Counts the number of words with num characters
* @param num the number of characters
* @return the number of words with num characters
*/
public int countWordsWithNumChars(int num)
{
return -999; // Replace
}
/**
* Removes the words with num characters
* from this
* @param num the number of characters of words to be removed
*/
public void removeWordsWithNumChars(int num)
{
}
/**
* Counts the number of words with num vowels
* @param num the number of vowels
* @return the number of words with num vowels
*/
public int countWordsWithNumVowels(int num)
{
return -999; // Replace
}
/**
* Makes an array containing reversed Word objects.
* Each of the items in the returned array is the reverse of an
* item in words. The items in the returned array
* are in the same order as in words.
* @return an array of the reverse objects of words.
*/
public Word[] getReversedWords()
{
return null; // Replace
}
/**
* Gives the string representing the words.
* @return the string representing the words.
*/
public String toString()
{
return null; // Replace
}
}
WORDTESTER
/**
* WordTester.java 06/08/08
*
* @author - Robert Glen Martin
* @author - School for the Talented and Gifted
* @author - Dallas ISD
*
* Based on the Lab16c assignment
* Used with permission from Stacey Armstrong
* A+ Computer Science - www.apluscompsci.com
*/
import java.util.Arrays;
/**
* Application to test the Word and
* Words classes.
*/
public class WordTester
{
public static void main(String[] args)
{
// Test Word
Word one = new Word("chicken");
System.out.println("Word one: " + one);
System.out.println("Number of chars: " + one.getLength());
System.out.println("Number of vowels: " + one.getNumVowels());
System.out.println("Reverse: " + one.getReverse());
System.out.println("  ");
Word two = new Word("alligator");
System.out.println("Word two: " + two);
System.out.println("Number of chars: " + two.getLength());
System.out.println("Number of vowels: " + two.getNumVowels());
System.out.println("Reverse: " + two.getReverse());
System.out.println("  ");
Word three = new Word("elephant");
System.out.println("Word three: " + three);
System.out.println("Number of chars: " + three.getLength());
System.out.println("Number of vowels: " + three.getNumVowels());
System.out.println("Reverse: " + three.getReverse());
System.out.println("  ");
// Test Words - Uncomment these lines of code to test the Words class
/*
Words test1 = new Words(new String[] {"one", "two", "three",
"four", "five", "six", "seven",
"alligator"});
System.out.println(" Words test1: " + test1);
System.out.println(" Number of words with 2 vowels: " +
test1.countWordsWithNumVowels(2));
System.out.println(" Number of words with 3 vowels: " +
test1.countWordsWithNumVowels(3));
System.out.println(" Number of words with 4 vowels: " +
test1.countWordsWithNumVowels(4));
System.out.println(" Number of words with 2 chars: " +
test1.countWordsWithNumChars(2));
System.out.println(" Number of words with 4 chars: " +
test1.countWordsWithNumChars(4));
System.out.println(" Number of words with 5 chars: " +
test1.countWordsWithNumChars(5));
test1.removeWordsWithNumChars(3);
System.out.println(" Words test1 after removing words " +
"with 3 chars: " + test1);
System.out.println(" Reversed words: " +
Arrays.toString(test1.getReversedWords()));
System.out.println("  ");
Words test2 = new Words(new String[] {"fun", "fly", "four", "six",
"times", "ten", "plus","eight"});
System.out.println("Words test2: " + test2);
System.out.println(" Number of words with 2 vowels: " +
test2.countWordsWithNumVowels(2));
System.out.println(" Number of words with 3 vowels: " +
test2.countWordsWithNumVowels(3));
System.out.println(" Number of words with 4 vowels: " +
test2.countWordsWithNumVowels(4));
System.out.println(" Number of words with 2 chars: " +
test2.countWordsWithNumChars(2));
System.out.println(" Number of words with 4 chars: " +
test2.countWordsWithNumChars(4));
System.out.println(" Number of words with 5 chars: " +
test2.countWordsWithNumChars(5));
test2.removeWordsWithNumChars(3);
System.out.println(" Words test2 after removing words " +
"with 3 chars: " + test2);
System.out.println(" Reversed words: " +
Arrays.toString(test2.getReversedWords()));
System.out.println("  ");
Words test3 = new Words(new String[] {"alligator", "chicken", "dog",
"cat", "pig", "buffalo"});
System.out.println("Words test3: " + test3);
System.out.println(" Number of words with 2 vowels: " +
test3.countWordsWithNumVowels(2));
System.out.println(" Number of words with 3 vowels: " +
test3.countWordsWithNumVowels(3));
System.out.println(" Number of words with 4 vowels: " +
test3.countWordsWithNumVowels(4));
System.out.println(" Number of words with 2 chars: " +
test3.countWordsWithNumChars(2));
System.out.println(" Number of words with 4 chars: " +
test3.countWordsWithNumChars(4));
System.out.println(" Number of words with 9 chars: " +
test3.countWordsWithNumChars(9));
test3.removeWordsWithNumChars(3);
System.out.println(" Words test3 after removing words " +
"with 3 chars: " + test3);
System.out.println(" Reversed words: " +
Arrays.toString(test3.getReversedWords()));
*/
}
} BlueJ: Words Studen Project Edit Tools View Help New Class... Word Words Compile
WordTester 8:23 AM 11/7/2016
Solution
words class
O/P
Word one: chicken
Number of chars: 7
Number of vowels: 2
Reverse: nekcihc
Word two: alligator
Number of chars: 9
Number of vowels: 4
Reverse: rotagilla
Word three: elephant
Number of chars: 8
Number of vowels: 3
Reverse: tnahpele
Words test1: [one, two, three, four, five, six, seven, alligator]
Number of words with 2 vowels: 5
Number of words with 3 vowels: 0
Number of words with 4 vowels: 1
Number of words with 2 chars: 0
Number of words with 4 chars: 2
Number of words with 5 chars: 2
Words test1 after removing words with 3 chars:
[three, four, five, seven, alligator]
Reversed words:
[eerht, ruof, evif, neves, rotagilla]
Words test2: [fun, fly, four, six, times, ten, plus, eight]
Number of words with 2 vowels: 3
Number of words with 3 vowels: 0
Number of words with 4 vowels: 0
Number of words with 2 chars: 0
Number of words with 4 chars: 2
Number of words with 5 chars: 2
Words test2 after removing words with 3 chars:
[four, times, plus, eight]
Reversed words:
[ruof, semit, sulp, thgie]
Words test3: [alligator, chicken, dog, cat, pig, buffalo]
Number of words with 2 vowels: 1
Number of words with 3 vowels: 1
Number of words with 4 vowels: 1
Number of words with 2 chars: 0
Number of words with 4 chars: 0
Number of words with 9 chars: 1
Words test3 after removing words with 3 chars:
[alligator, chicken, buffalo]
Reversed words:
[rotagilla, nekcihc, olaffub]
If you have any doubt you can ask me without any hesitation.

More Related Content

PDF
PDF
This program here prints the number of words that occurs in the inpu.pdf
PPTX
Programing with java for begniers .pptx
PDF
Cs hangman
DOCX
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
PDF
Description of the project Purpose To implement a simple au.pdf
PPT
Chapter 9 - Characters and Strings
PPT
Java căn bản - Chapter9
This program here prints the number of words that occurs in the inpu.pdf
Programing with java for begniers .pptx
Cs hangman
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
Description of the project Purpose To implement a simple au.pdf
Chapter 9 - Characters and Strings
Java căn bản - Chapter9

Similar to DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf (20)

PDF
java-programming.pdf
PPTX
Java Foundations: Strings and Text Processing
PDF
Test string and array
PDF
Alternate JVM Languages
PPTX
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
PPTX
String and StringBufferString and StringBuffer e examples.pptx
PPT
String slide
PPTX
TDD for the Win
PPT
Strings and Characters
PDF
Frequency .java Word frequency counter package frequ.pdf
PPTX
13. Java text processing
PPT
strings.ppt
PPT
PPTX
Java String Handling
PDF
Write a program that asks the user for the name of a file. The progr.pdf
PDF
vision_academy_classes_Bcs_bca_bba_java part_2 (1).pdf
PDF
Vision academy classes_bcs_bca_bba_java part_2
PDF
The java program Jumble that prompts user to enter nu.pdf
PDF
java.lang.String Class
PDF
Module-1 Strings Handling.ppt.pdf
java-programming.pdf
Java Foundations: Strings and Text Processing
Test string and array
Alternate JVM Languages
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
String and StringBufferString and StringBuffer e examples.pptx
String slide
TDD for the Win
Strings and Characters
Frequency .java Word frequency counter package frequ.pdf
13. Java text processing
strings.ppt
Java String Handling
Write a program that asks the user for the name of a file. The progr.pdf
vision_academy_classes_Bcs_bca_bba_java part_2 (1).pdf
Vision academy classes_bcs_bca_bba_java part_2
The java program Jumble that prompts user to enter nu.pdf
java.lang.String Class
Module-1 Strings Handling.ppt.pdf
Ad

More from archanaemporium (20)

PDF
Identify a article about a communicable or noncommunicable disease i.pdf
PDF
i safari File Edit View History Bookmarks Window Help 67 D. Thu 101.pdf
PDF
I dont know what is wrong with this roulette program I cant seem.pdf
PDF
I know that water molecules attract each other, but why do water mol.pdf
PDF
How can Internet technologies be involved in improving a process in .pdf
PDF
How many paths are there in a tree with n nodesHow many paths a.pdf
PDF
Hypothesize a way for a virus to evade a host defense & then devise .pdf
PDF
How many ways can letters of the word SINGAPORE be arranged such that.pdf
PDF
Haploid. After is complete, the resulting gametes are haploid. This m.pdf
PDF
FTP and TFTP are primarily file transfer protocols. What is the main.pdf
PDF
Given Starter Fileimport java.util.Arrays; Encapsulates.pdf
PDF
Express the verbal representation for the function f symbolically. M.pdf
PDF
Economic resources have a price above zero because...A. there are .pdf
PDF
Discuss in detail how two different Progressive reformers tackled th.pdf
PDF
Describe the major parts of the nervous system and their functions..pdf
PDF
DEFINE gene enhancer and gene promoter (3-4 sentences each).Sol.pdf
PDF
Cisco Systems, Inc. offers a switching technology known as Multi-Lay.pdf
PDF
C# ProgramingHow a derived class that inherits attributes and beha.pdf
PDF
Assume that x and y are already defined as being of type int . Write.pdf
PDF
Briefly define cyberterrorism. Define hacktivism. Illustrate example.pdf
Identify a article about a communicable or noncommunicable disease i.pdf
i safari File Edit View History Bookmarks Window Help 67 D. Thu 101.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
I know that water molecules attract each other, but why do water mol.pdf
How can Internet technologies be involved in improving a process in .pdf
How many paths are there in a tree with n nodesHow many paths a.pdf
Hypothesize a way for a virus to evade a host defense & then devise .pdf
How many ways can letters of the word SINGAPORE be arranged such that.pdf
Haploid. After is complete, the resulting gametes are haploid. This m.pdf
FTP and TFTP are primarily file transfer protocols. What is the main.pdf
Given Starter Fileimport java.util.Arrays; Encapsulates.pdf
Express the verbal representation for the function f symbolically. M.pdf
Economic resources have a price above zero because...A. there are .pdf
Discuss in detail how two different Progressive reformers tackled th.pdf
Describe the major parts of the nervous system and their functions..pdf
DEFINE gene enhancer and gene promoter (3-4 sentences each).Sol.pdf
Cisco Systems, Inc. offers a switching technology known as Multi-Lay.pdf
C# ProgramingHow a derived class that inherits attributes and beha.pdf
Assume that x and y are already defined as being of type int . Write.pdf
Briefly define cyberterrorism. Define hacktivism. Illustrate example.pdf
Ad

Recently uploaded (20)

PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Classroom Observation Tools for Teachers
PDF
Trump Administration's workforce development strategy
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
1_English_Language_Set_2.pdf probationary
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
RMMM.pdf make it easy to upload and study
Digestion and Absorption of Carbohydrates, Proteina and Fats
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Classroom Observation Tools for Teachers
Trump Administration's workforce development strategy
Paper A Mock Exam 9_ Attempt review.pdf.
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
History, Philosophy and sociology of education (1).pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Final Presentation General Medicine 03-08-2024.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
A systematic review of self-coping strategies used by university students to ...
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
1_English_Language_Set_2.pdf probationary
A powerpoint presentation on the Revised K-10 Science Shaping Paper
RMMM.pdf make it easy to upload and study

DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf

  • 1. DOES NOT NEED TO BE ANSWERED UNTIL NOV 13th Words Assignment Robert Glen Martin School for the Talented and Gifted, Dallas, TX Based on the Lab16c assignment from Stacey Armstrong © A+ Computer Science - www.apluscompsci.com Introduction The purpose of this assignment is to give students practice with Strings, arrays, and ArrayLists. It also provides the opportunity to work with several interacting classes. Overview This project utilizes three new classes: - Word- an immutable class representing a word - Words - a class representing a list of Word objects - WordTester- a class used to test the Word and Words classes. Starter Code The folder Words Student contains a JCreator project with starter code for the three classes. WordTester (the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word – This part of the lab has been done for you.Look at the main WordTester to see how it uses a Word object. Run the main to see the results of the tester code. The Word class represents a single word. It is immutable. You have been provided a skeleton for this class. Complete the Word class using the block comments, Javadocs, and the following instructions. 1. Add a String instance variable named word which will contain the word. 2. Complete the one parameter constructor to initialize the word instance variable. 3. Complete the getLength method to return the number of characters in the word. 4. Complete the getNumVowels method to return the number of vowels in the word. It should use the VOWELS class constant and String’s length, substring, and indexOf methods. Do not use more than one loop. Do not use any String methods that are not in the AP Subset. 5. Complete the getReverse method to return a Word with the letters of this reversed. 6. Complete the toString method to return the String word. 7. Uncomment the Word test code in WordTester and make sure that Word works correctly. Words
  • 2. The Words class represents a list of words. You have been provided a skeleton for this class. Complete the Words class using the block comments, Javadocs, and the following instructions. Step has been done for you. 1. Add a List instance variable named words which will contain the list of words. Be sure to specify the type of objects that will be stored in the List. Be sure that the instance variable is private. 2. Complete the one parameter constructor to initialize the words instance variable. You will need to create the ArrayList and add each word to it. Be sure to create a new Word object with each String in the parameter array wordList and then add it to the ArrayList words. This would be a great place to use a for-each loop. Your code should not generate any warnings. 3. Complete the countWordsWithNumChars method to return the number of words with lengths of num characters. 4. Complete the removeWordsWithNumChars method to remove all words with lengths of num characters. 5. Complete the countWordsWithNumVowels method to return the number of words that have num vowels. 6. Complete the getReversedWords method to return an array of reversed words. 7. Complete the toString method to return the words as a String. You should utilize ArrayLists’s toString method. 8. Uncomment the Words test code in WordTester and make sure that Words works correctly. STARTER CODES AND SETUP Word /** * Word.java 06/08/08 * * @author - Jane Doe * @author - Period n * @author - Id nnnnnnn * * @author - I received help from ... * * * Based on the Lab16c assignment * Used with permission from Stacey Armstrong * ? A+ Computer Science - www.apluscompsci.com */
  • 3. /** * A Word object represents a word. */ public class Word { /** The 5 vowels */ private static final String VOWELS = "AEIOUaeiou"; /** The word */ private String word; /** * Constructs a Word object. * @param w the string used to initialize the word. */ public Word(String w) { word = w; } /** * Gets the length of the word. * @return the length (number of characters) of the word. */ public int getLength() { return word.length(); } /** * Gets the number of vowels in the word. * @return the number of vowels (Characters in VOWELS in * the word. */ public int getNumVowels() { int count = 0; for (int i = 0; i < word.length(); i++) { String letter = word.substring(i, i + 1);
  • 4. if (VOWELS.indexOf(letter) >= 0) //if letter is found in VOWELS, its a vowel { count++; } } return count; } /** * Gets the reverse word. * @return a Word with this's * letters reversed. */ public Word getReverse() { String reverse = ""; //Start the string as an empty string for (int i = word.length() - 1; i >= 0; i--) { reverse += word.substring(i, i + 1); //build the string backward } return new Word(reverse); //must convert the string to a Word object to match //the return type } /** * Gives the string representing the word. * @return the string representing the word. */ public String toString() { return word; // Replace } } WORDS /** * Words.java 06/08/08 * * @author - Jane Doe
  • 5. * @author - Period n * @author - Id nnnnnnn * * @author - I received help from ... * * * Based on the Lab16c assignment * Used with permission from Stacey Armstrong * A+ Computer Science - www.apluscompsci.com */ import java.util.List; //You must import this to use the List datatype for the reference import java.util.ArrayList;//Needed to instantiate an ArrayList /** * Words represents a list of Word objects. */ public class Words { /** The Words */ private List words; /** * Constructs a Words object. * @param wordList the words for the Words object. */ public Words(String[] wordList) { words = new ArrayList(); //complete the constructor by using a loop to access each String in wordList, //creating a Word object with each String and adding the Word object to the //ArrayList. } /** * Counts the number of words with num characters * @param num the number of characters * @return the number of words with num characters */ public int countWordsWithNumChars(int num)
  • 6. { return -999; // Replace } /** * Removes the words with num characters * from this * @param num the number of characters of words to be removed */ public void removeWordsWithNumChars(int num) { } /** * Counts the number of words with num vowels * @param num the number of vowels * @return the number of words with num vowels */ public int countWordsWithNumVowels(int num) { return -999; // Replace } /** * Makes an array containing reversed Word objects. * Each of the items in the returned array is the reverse of an * item in words. The items in the returned array * are in the same order as in words. * @return an array of the reverse objects of words. */ public Word[] getReversedWords() { return null; // Replace } /** * Gives the string representing the words. * @return the string representing the words. */ public String toString()
  • 7. { return null; // Replace } } WORDTESTER /** * WordTester.java 06/08/08 * * @author - Robert Glen Martin * @author - School for the Talented and Gifted * @author - Dallas ISD * * Based on the Lab16c assignment * Used with permission from Stacey Armstrong * A+ Computer Science - www.apluscompsci.com */ import java.util.Arrays; /** * Application to test the Word and * Words classes. */ public class WordTester { public static void main(String[] args) { // Test Word Word one = new Word("chicken"); System.out.println("Word one: " + one); System.out.println("Number of chars: " + one.getLength()); System.out.println("Number of vowels: " + one.getNumVowels()); System.out.println("Reverse: " + one.getReverse()); System.out.println(" "); Word two = new Word("alligator"); System.out.println("Word two: " + two); System.out.println("Number of chars: " + two.getLength());
  • 8. System.out.println("Number of vowels: " + two.getNumVowels()); System.out.println("Reverse: " + two.getReverse()); System.out.println(" "); Word three = new Word("elephant"); System.out.println("Word three: " + three); System.out.println("Number of chars: " + three.getLength()); System.out.println("Number of vowels: " + three.getNumVowels()); System.out.println("Reverse: " + three.getReverse()); System.out.println(" "); // Test Words - Uncomment these lines of code to test the Words class /* Words test1 = new Words(new String[] {"one", "two", "three", "four", "five", "six", "seven", "alligator"}); System.out.println(" Words test1: " + test1); System.out.println(" Number of words with 2 vowels: " + test1.countWordsWithNumVowels(2)); System.out.println(" Number of words with 3 vowels: " + test1.countWordsWithNumVowels(3)); System.out.println(" Number of words with 4 vowels: " + test1.countWordsWithNumVowels(4)); System.out.println(" Number of words with 2 chars: " + test1.countWordsWithNumChars(2)); System.out.println(" Number of words with 4 chars: " + test1.countWordsWithNumChars(4)); System.out.println(" Number of words with 5 chars: " + test1.countWordsWithNumChars(5)); test1.removeWordsWithNumChars(3);
  • 9. System.out.println(" Words test1 after removing words " + "with 3 chars: " + test1); System.out.println(" Reversed words: " + Arrays.toString(test1.getReversedWords())); System.out.println(" "); Words test2 = new Words(new String[] {"fun", "fly", "four", "six", "times", "ten", "plus","eight"}); System.out.println("Words test2: " + test2); System.out.println(" Number of words with 2 vowels: " + test2.countWordsWithNumVowels(2)); System.out.println(" Number of words with 3 vowels: " + test2.countWordsWithNumVowels(3)); System.out.println(" Number of words with 4 vowels: " + test2.countWordsWithNumVowels(4)); System.out.println(" Number of words with 2 chars: " + test2.countWordsWithNumChars(2)); System.out.println(" Number of words with 4 chars: " + test2.countWordsWithNumChars(4)); System.out.println(" Number of words with 5 chars: " + test2.countWordsWithNumChars(5)); test2.removeWordsWithNumChars(3); System.out.println(" Words test2 after removing words " + "with 3 chars: " + test2); System.out.println(" Reversed words: " + Arrays.toString(test2.getReversedWords())); System.out.println(" "); Words test3 = new Words(new String[] {"alligator", "chicken", "dog",
  • 10. "cat", "pig", "buffalo"}); System.out.println("Words test3: " + test3); System.out.println(" Number of words with 2 vowels: " + test3.countWordsWithNumVowels(2)); System.out.println(" Number of words with 3 vowels: " + test3.countWordsWithNumVowels(3)); System.out.println(" Number of words with 4 vowels: " + test3.countWordsWithNumVowels(4)); System.out.println(" Number of words with 2 chars: " + test3.countWordsWithNumChars(2)); System.out.println(" Number of words with 4 chars: " + test3.countWordsWithNumChars(4)); System.out.println(" Number of words with 9 chars: " + test3.countWordsWithNumChars(9)); test3.removeWordsWithNumChars(3); System.out.println(" Words test3 after removing words " + "with 3 chars: " + test3); System.out.println(" Reversed words: " + Arrays.toString(test3.getReversedWords())); */ } } BlueJ: Words Studen Project Edit Tools View Help New Class... Word Words Compile WordTester 8:23 AM 11/7/2016 Solution words class O/P
  • 11. Word one: chicken Number of chars: 7 Number of vowels: 2 Reverse: nekcihc Word two: alligator Number of chars: 9 Number of vowels: 4 Reverse: rotagilla Word three: elephant Number of chars: 8 Number of vowels: 3 Reverse: tnahpele Words test1: [one, two, three, four, five, six, seven, alligator] Number of words with 2 vowels: 5 Number of words with 3 vowels: 0 Number of words with 4 vowels: 1 Number of words with 2 chars: 0 Number of words with 4 chars: 2 Number of words with 5 chars: 2 Words test1 after removing words with 3 chars: [three, four, five, seven, alligator] Reversed words: [eerht, ruof, evif, neves, rotagilla] Words test2: [fun, fly, four, six, times, ten, plus, eight] Number of words with 2 vowels: 3 Number of words with 3 vowels: 0 Number of words with 4 vowels: 0 Number of words with 2 chars: 0 Number of words with 4 chars: 2 Number of words with 5 chars: 2 Words test2 after removing words with 3 chars: [four, times, plus, eight] Reversed words: [ruof, semit, sulp, thgie] Words test3: [alligator, chicken, dog, cat, pig, buffalo]
  • 12. Number of words with 2 vowels: 1 Number of words with 3 vowels: 1 Number of words with 4 vowels: 1 Number of words with 2 chars: 0 Number of words with 4 chars: 0 Number of words with 9 chars: 1 Words test3 after removing words with 3 chars: [alligator, chicken, buffalo] Reversed words: [rotagilla, nekcihc, olaffub] If you have any doubt you can ask me without any hesitation.