Question: Write the methods without calling on the methods. Ex) charAr -- Write a code that captures the array, if the user calls on R it

Write the methods without calling on the methods. Ex) charAr -- Write a code that captures the array, if the user calls on R it will return the location ( S P R I N G, user calls r it returns 2)

Need to do all 9. Write code that does the code without typing the actual method. I just need the driver class made please! The String class is made!

- Using blueJ

- Must have a driver

--------------------------------------------------------

1. charAt(int index)

If its too long then print the message : thats not the numerator of the string

2.indexOf ( int ch)

3.lastIndexOf

4.Replace ( char oldChar, char newChar)

5.toUpperCase

6.toLowerCase

7.equalsto

8.compareTo

9.substring

--------------------------------------------------------------------

// StringClass.java

public class StringClass { private char array[] = null;

public StringClass(char[] array) { this.array = array; }

public char charAt(int index) { char ch = 0; if (index >= 0 && index < array.length) { ch = array[index]; } return ch; }

public int length() { int i = 0; for (char c : array) {

i++;

} return i; }

public int indexOf(char ch) { for (int i = 0; i < length(); i++) { if (array[i] == ch) return i; } return -1; }

public int lastIndexOf(char ch) { for (int i = length() - 1; i >= 0; i--) { if (array[i] == ch) return i; } return -1; }

public void Replace(char oldChar, char newChar) { for (int i = 0; i < length(); i++) { if (array[i] == oldChar) { array[i] = newChar; } } }

public StringClass toUpperCase() { int len = length(); char arr[] = new char[len]; for (int j = 0; j < len; j++) { arr[j] = (char) (array[j] - 32); } return new StringClass(arr);

}

public StringClass toLowerCase() { int len = length(); char arr[] = new char[len]; for (int j = 0; j < len; j++) { arr[j] = (char) (array[j] + 32); } return new StringClass(arr); }

public boolean equalsto(StringClass m) { if (array.length != m.length()) { return false; } for (int i = 0; i < length(); i++) { if (array[i] == m.array[i]) return false; } return true; }

public StringClass substring(int begin, int end) { int len = end - begin; char arr[] = new char[len]; for (int i = 0; i < len; i++) { arr[i] = array[begin]; begin++; } return new StringClass(arr); }

}

Just need driver class!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!