SlideShare a Scribd company logo
1 of 12
Download to read offline
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

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

Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20Max Kleiner
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de JavascriptBernard Loire
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)Tak Lee
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Asim Rais Siddiqui
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2ppJ. C.
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptxDurgaNayak4
 
Coding Best Practices
Coding Best PracticesCoding Best Practices
Coding Best Practicesmh_azad
 

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

LectureNotes-04-DSA
LectureNotes-04-DSALectureNotes-04-DSA
LectureNotes-04-DSA
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Javascript
JavascriptJavascript
Javascript
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript
JavascriptJavascript
Javascript
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Simple Design
Simple DesignSimple Design
Simple Design
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Perl slid
Perl slidPerl slid
Perl slid
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptx
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Coding Best Practices
Coding Best PracticesCoding Best Practices
Coding Best Practices
 

More from archanaemporium

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

More from archanaemporium (20)

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

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

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.