CS 160, Summer 2016
Programming Assignment P6
Creating a Pseudo String Class

Programming due Monday, Jul. 18 at 6:00pm; late deadline at 11:59pm.


This lab has the goal of teaching you how to:
  1. Write a class that implements a number of methods.
  2. Declare private instance data inside your class.
  3. Instantiate an object of your class and call its methods.
  4. Test your own class with the main method.

Description

In this assignment you will create your own class and write the methods in it. The class you write is called Pseudo and it mimics some of the attributes of the String class. After you write the methods in the Pseudo class, you can test them by comparing the return values from methods in your class to the return values from the String class.

Instructions

Create a project called P6 and a class named Pseudo in a file called Pseudo.java, then follow the instructions below exactly:
  1. Declare two private instance variables. One of type char array that holds up to 80 characters and the other of type int that will hold the length of the string.
  2. Create a constructor that takes a parameter of type String and calls the setString method that you will be implementing next.
  3. Create a setString method that takes a parameter of type String and doesn't return anything. This method should and use a loop to store the characters into the instance array and then stores the size into the instance variable length.
  4. Create a toString method that takes no parameters and returns a String. This method should use a loop to build and returns a String with the contents of your character array.

    WARNING: To implement the methods below, you cannot use the String methods indexOf, toUpperCase, substring, or equals. All of the methods below must use the contents of the character array stored in the Pseudo class:

  5. Declare a public method called charAt that takes an index parameter and returns the character from the array at the index specified. You can assume that the index is valid, i.e. between 0 and String.length()-1.
  6. Declare a public method called indexOf that takes a character parameter and returns the index in the character array of the first occurrence of that character or -1 if the character is not found.
  7. Declare a public method called toUpperCase that constructs and returns a String with the contents of the character array converted to upper case. Do not change the contents of the character array!
  8. Declare a public method called substring with two integer parameters start and end that builds and returns a substring (from the character array) in a manner identical to the String method of the same name. You can assume that both indices are valid.
  9. Declare a public method called substring with one integer parameter called start that returns the substring from the character array in a manner identical to the String method of the same name. You can assume the starting index is valid.
  10. Declare a public method called pseudoEquals that takes a String parameter and compares the contents of it with the string stored in the character array. Return true if they exactly match character for character, and false if not.
  11. Declare a public method called pseudoEquals that takes a Pseudo parameter and compares the contents of it with the string stored in the character array.
  12. Add a main method with the usual signature that instantiates the Pseudo class and tests its methods as follows (the output from Pseudo should match the output from String):

Testing

Here are some sample test cases and the corresponding output. Type this code into your main method to test your class out.

Output

output if your methods are correct:
Verifying Pseudo methods:
pseudo = 1234567890 Computer Science !(*@&#)*&
pseudo.charAt(5) = 6
pseudo.indexOf('C') = 11
pseudo.toUpperCase() = 1234567890 COMPUTER SCIENCE !(*@&#)*&
pseudo.substring(11, 17) = Comput
pseudo.substring(5) = 67890 Computer Science !(*@&#)*&
Verifying Pseudo equals method with a String object:
pseudo.pseudoEquals("Compare") = true
pseudo.pseudoEquals("Compare!") = false
Verifying Pseudo equals method with a Pseudo object:
pseudo.pseudoEquals("Compare") = true
pseudo.pseudoEquals("Compare!") = false

Comparing to the String Methods:
string = 1234567890 Computer Science !(*@&#)*&
string.charAt(5) = 6
string.indexOf('C') = 11
string.toUpperCase() = 1234567890 COMPUTER SCIENCE !(*@&#)*&
string.substring(11, 19) = Computer
string.equals("Compare") = true
string.equals("Compare!") = false
You may want to do some additional testing on your own!

Specifications

Your program must meet the following specifications:

Grading Criteria

Submit your Pseudo.java file to the Checkin tab on the course website, as you were shown in the recitation, and read the syllabus for the late policy.

© 2016 CS160 Colorado State University. All Rights Reserved.