Question

In: Computer Science

Name: __________________________________________ Specifications: Create a class called WordMaker that is passed characters one at a time...

Name: __________________________________________

Specifications:

  1. Create a class called WordMaker that is passed characters one at a time and assembles them into words.

  1. As long as the characters passed to it are letters, it builds a word by placing each character on the end of a string.
  1. When a character that is not part of a word (i.e., is not a letter) is encountered, the class signals that the word is complete, and makes a string containing the word available to its client.
  1. After encountering a non-letter, it will continue to ignore whitespace passed to it until it encounters a letter, in which case it will signal that a new word is being built.
  1. Apostrophes are a special case. Even if they occur within a word (e.g., surrounded on each side by a letter), they should be ignored.
  1. The class will have the following public member functions:

public void reset()

Resets the WordMaker so that it is ready to start building a word.

   public void addChar(newChar);

Adds a character to the WordMaker. If it is a letter and

WordMaker is making a word, it adds it to the end of the word. If

it is a letter and WordMaker is not making a word, it erases the

current word, and starts a new word with the letter. If it is not a

letter and WordMaker is making a word, it ends the word (unless

it is an apostrophe, treated specially as described above). If it is not

a letter and WordMaker is not making a word, it is ignored.

             public boolean wordReady()

Returns true if the WordMaker has finished constructing a word,

false otherwise. After a reset, or when the WordMaker is first

constructed, it returns false. When a word has just been completed

(i.e., the first non-letter character has been added), it returns true.

Otherwise it returns false.

   public String getWord()

Returns the word that the WordMaker has created when

WordReady returns true. It should not be called when WordReady

returns false.

  1. A test plan should accompany this project.
    1. List a description of the various test cases you will program.
    2. Give each test in your test plan a number.
    3. Annotate each line in the methods with the number of a test case that tests it to verify that your code coverage is complete.
    4. Also annotate your output to make clear what your test plan tests.
    5. The test plan will be assessed based on its thoroughness and clarity.

Solutions

Expert Solution

CODE :

class WordMaker{
   private String word = "";
   boolean wordBuilding = false;
  
   public void reset(){
       word = "";
   }
  
   public void addChar(char c){
       int asci = c;
       if((asci >= 65 && asci <= 90) || (asci >=97 && asci <= 122)){
           if(wordBuilding){
               word += c;
           }
           else{
               reset();
               wordBuilding = true;
               word += c;
           }
       }
       else if(c == '"'){}
       else{
           wordBuilding = false;
       }
   }
  
   public boolean wordReady(){
       if(word.length() != 0 && !wordBuilding){
           return true;
       }
       else{
           return false;
       }
   }

   public String getWord(){
       return word;
   }
}

class Main{
   public static void main(String [] args){
       WordMaker wm = new WordMaker();
      
       if(wm.wordReady()){
           System.out.println(wm.getWord());
       }

       String test = "sfda saf ;ljljoih";
      
       for(int i=0;i<test.length();i++){
           wm.addChar(test.charAt(i));
           if(wm.wordReady()){
               System.out.println(wm.getWord());
           }
       }
       System.out.println(wm.getWord());
   }
}

OUTPUT :

NOTE :

Unit testing is not implemented.

The string (test) in the class "Main" is designed as such the whole program is being covered and tested.

If still test cases are required :

1] Empty string (test = "")

2] String with only one word (test = "HELLO")

3] String with more than one word without a special character (test = "HELLO WORLD")

4] String with apostrophe (test = "HELLO \"WORLD ")

5] String with special characters (test = "HELLO ;<World")


Related Solutions

Animal class Create a simple class called Animal instantiated with a name and a method toString...
Animal class Create a simple class called Animal instantiated with a name and a method toString which returns the name. Cat class Create a simple class Cat which extends Animal, but adds no new instance variable or methods. RedCat class Create a simple class RedCat which extends Cat, but adds no new instance variable or methods. WildCardTester class Create a class with the main method and methods addCat, deleteCat and printAll as follows. addCat method Has two parameters, an ArrayList...
Create a class called Student which stores • the name of the student • the grade...
Create a class called Student which stores • the name of the student • the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into the grade field. • Calculate the...
IN JAVA PLEASE Create a class called Child with an instance data values: name and age....
IN JAVA PLEASE Create a class called Child with an instance data values: name and age. a. Define a constructor to accept and initialize instance data b. include setter and getter methods for instance data c. include a toString method that returns a one line description of the child
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class Create another class called CourseSection Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of the methods required for a standard user defined...
follow pseudo 1) Create class called Node Declare private integer called data (or any other name)...
follow pseudo 1) Create class called Node Declare private integer called data (or any other name) Declare private Node called link (or any other name) 2) Declare constructor Should be public (ex: Node) where: link is equal to null data is equal to zero 3) Declare another constructor public Node with parameters integer d, Node n where: data is equal to d link is equal to n 4) Declare function to set link to next Node link equal to n...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
Part 1 – Create a Stock Class Write a class named Stock. Stock Class Specifications Include...
Part 1 – Create a Stock Class Write a class named Stock. Stock Class Specifications Include member variables for name (string), price (double), shares (double). Write a default constructor. Write a constructor that takes values for all member variables as parameters. Write a copy constructor. Implement Get/Set methods for all member variables. Implement the CalculateValue function. This function should multiply the prices by the shares and return that value. Use the following function header: double CalculateValue(). Add a member overload...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT