subject
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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:30
1. before plugging in a new device to a computer you should unplug all other devices turn off the computer turn on the computer 2. many of the maintenance tools for a computer can be found in the control panel under administrative tools display personalization
Answers: 1
question
Computers and Technology, 24.06.2019 00:40
Use a software program or a graphing utility with matrix capabilities to solve the system of linear equations using an inverse matrix. x1 + 2x2 − x3 + 3x4 − x5 = 6 x1 − 3x2 + x3 + 2x4 − x5 = −6 2x1 + x2 + x3 − 3x4 + x5 = 3 x1 − x2 + 2x3 + x4 − x5 = −3 2x1 + x2 − x3 + 2x4 + x5 = 5
Answers: 3
question
Computers and Technology, 24.06.2019 17:50
Create a class hand in its own module. one object of class hand represents a hand of cards and so one object stores a number of card objects. for this assignment you will submit three separate modules, one with the definition of class card, one with the definition of class hand and one with the main application that thoroughly tests class hand.class hand must contain the following four methods: 1) , numcardsinhand) takes an integer as parameter and initializes a hand object with numcardsinhand card objects inside it. these card objects are generated randomly. for simplicity, assume an infinite number of decks of cards.2) bjvalue(self) returns the blackjack value for the whole hand of cards3) ) returns a string containing all the cards in the hand4) hitme(self) adds one randomly generated card to the handcreate a main program in its own module that thoroughly tests class hand. you will have three modules/files to upload to your etudes assignment submission: card.py, hand.py and the module that contains your main program.two alternatives for extra credit - you cannot get credit for both! (+1 point): after you have thoroughly tested the class hand and all of its methods, add code to your main program that stores one hand object as a pickle file and reads it back into a new hand object. you are only eligible for this extra credit if class hand has all four of the methods above working.or(+2 points): after you have thoroughly tested the class hand and all of its methods, add code to your main program that stores one hand object as a text file on the disk and reads it back into a new hand object. you are only eligible for this extra credit if class hand has all four of the methods above working.notes: -start by making any and all modifications suggested by my comments to your previous submission of class card from assignment #6 "a robust card object"-once your class card is tested and working well, you will not make any further modifications to it for the purposes of class hand.-you can keep the test code for class card intact. if it is indented inside an if __name__ == "__main__", then it will not be executed when your main program's module imports it.-to save time, write and test one method for class hand at a time.-under no circumstances are you to attempt the extra credit until you are completely finished with writing and testing all the methods in class hand.
Answers: 3
question
Computers and Technology, 24.06.2019 23:00
Hypertension occurs when blood pressure is too high.
Answers: 1
You know the right answer?
HW3_P2 - MyString The String class is provided in the Java library. Provide your own implementation...
Questions
question
Mathematics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Business, 13.09.2020 14:01
question
History, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Social Studies, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
English, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Physics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
question
Mathematics, 13.09.2020 14:01
Questions on the website: 13722367