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

Specifications Create an abstract Employee class that provides private attributes for the first name, last name,...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class should add private attributes for years of experience and the annual salary. This class should also provide...
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...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the user to choose game tester type...
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...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT