Computers and Technology
Computers and Technology, 15.10.2020 19:01, 8hoofs

HW3_P2 - MyString The String class is provided in the Java library. Provide your own implementation for the following methods (name the new class MyString):
**PLEASE DO NOT USE THE STRING OBJECT AND ITS METHODS. IMPLEMENT THEM ALL AGAIN YOURSELF!
**You can use char[] array and Character object.
public MyString(char[] chars);
public char charAt(int index);
public int length();
public MyString substring(int begin, int end);
public MyString toLowerCase();
public boolean equals(MyString s);
public static MyString valueOf(int i); // Convert int type to MyString type
public char[] toChars();
Sample Input1: Test Length() Method
1
abcdef
Sample Output1: Test Length() Method
4
Sample Input2: Test charAt() Method
2
abcdfeg
3
Sample Output2: Test charAt() Method
d
Sample Input3: Test substring() Method
3
abcdefrgggfhgfgfhfgy
0
4
Sample Output3: Test substring() Method
abcd
Sample Input4: Test equals() Method
4
abcdefghi
sqsq
Sample Output4: Test equals() Method
false
Sample Input5: Test toLowerCase() Method
5
ABcDEfGHi
Sample Output5: Test toLowerCase() Method
abcdefghi
Sample Input6: Test valueOf() Method
6
9876543
Sample Output6: Test valueOf() Method
9876543
*Drivers Class*
import java. util.*;
import java. lang.*;
import java. io.*;
public class Driver {
public static void main(String[] args){
String str = null;
MyString s = null;
Scanner input = new Scanner(System. in);
int which = input. nextInt();
if(which!=6)
str = input. next();
switch (which) {
case 1 : // test length method
s = new MyString(str. toCharArray());
System. out. println(s. length());
break;
case 2 : // test charAt method
s = new MyString(str. toCharArray());
System. out. println(s. charAt(input. nextInt()));
break;
case 3 : // test substring method
s = new MyString(str. toCharArray());
System. out. println(new String(s. substring(input. nextInt(), input. nextInt()).toChars()));
break;
case 4 : // test equals method
String str2 = input. next();
s = new MyString(str. toCharArray());
MyString s2 = new MyString(str2.toCharArray());
System. out. println(s. equals(s2));
break;
case 5 : // test toLowerCase method
s = new MyString(str. toCharArray());
System. out. println(new String(s. toLowerCase().toChars()));
break;
case 6 : // test valueOf method
System. out. println(new String(MyString. valueOf(input. nextInt()).toChars()));
break;
}
}
}
*Solution class*
import java. util.*;
import java. lang.*;
import java. io.*;
//toChars() method is already implemented, so plese do not change it
class MyString {
private char[] chars;
public MyString(char[] chars) {
}
public char[] toChars() { //Do not change this method
return chars;
}
public int length()
}
public char charAt(int index) {
}
public MyString substring(int begin, int end) {
}
public boolean equals(MyString s){
}
public MyString toLowerCase() {
}
//convert an int type to MyString type
public static MyString valueOf(int i) {
}
}
Dont change driver class or myString. just add code

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:30, Cassandoo
The total revenues for a company are $150,223 and the total expenses were 125,766. if you are calculating the net income, which of these spreadsheets would you use? insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2-b3. the formula should be showing in the formula bar. insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2+b3. the formula should be showing in the formula bar. insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2/b3. the formula should be showing in the formula bar. insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2*b3. the formula should be showing in the formula bar.
Answers: 3
image
Computers and Technology, 22.06.2019 06:50, phillipfruge3
Match the personality traits with their description
Answers: 1
image
Computers and Technology, 22.06.2019 10:30, icantspeakengles
Aconstruction company is creating a powerpoint presentation describing how they calculate costs during each construction step. they plan to email this presentation to clients. the individual clients will be watching the presentation slide show on their own personal computers. what is the most important formatting step the company should take to make the text readable and pleasing to the eye?
Answers: 2
image
Computers and Technology, 24.06.2019 01:00, summerjoiner
Verify each identity[tex] \frac{csc}{cot \: x \: + \: tan \: x} = cos \: x[/tex]
Answers: 1
Do you know the correct answer?
HW3_P2 - MyString The String class is provided in the Java library. Provide your own implementation...

Questions in other subjects:

Konu
Mathematics, 13.05.2021 23:40
Konu
Mathematics, 13.05.2021 23:40
Konu
Mathematics, 13.05.2021 23:40