Concept explainers
(Implement the StringBuilder class) The StringBuilder class is provided in the Java library. Provide your own implementation for the following methods (name the new class MyStringBuilder2):
public MyStringBuilder2();
public MyStringBuilder2(char[ ] chars);
public MyStringBuilder2(String s);
public MyStringBui1der2 insert(int offset. MyStringBuilder2 s);
public MyStringBuilder2 reverse();
public MyStringBuilder2 substring(1nt begin);
public MyStringBuilder2 toUpperCase();
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
Digital Fundamentals (11th Edition)
Starting Out with Python (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Concepts Of Programming Languages
- Write a java method that receives a string containing letters of the English alphabet and then prints the Letters whose frequencies are not unique. Notes: 1) Ignore letter case; Uppercase and lowercase letters are considered the same. 2) Do not use methods from the Arrays class.arrow_forwardWrite a java method that receives a string containing letters of the English alphabet and then prints the three Letters with lowest frequencies. Notes: 1) Ignore letter case; Uppercase and lowercase letters are considered the same. 2) Do not use methods from the Arrays class.arrow_forwardClass Utilities { Method Details addDelimiter: public static java.lang.String addDelimiter(java.lang.String str, char delimeter) Returns a string where characters are separated by the specified delimeter character. A string with a single character will not have a delimeter added. The space character is consider a character (similar to character 'A'). You can assume str will never be the empty string. You may not use an auxiliary method in order to implement this method. Your implementation must be recursive and you may not use any loop construct. Note: In java given two characters a and b, a + b will not create a string. To create a string, append a to the empty string and the result to b. From the String class, the only methods you can use are length(), isEmpty(), charAt() and substring. Do not use ++ or -- in any recursive call argument. It may lead to an infinite recursion. For example, use index + 1, instead of index++. Parameters: str - delimeter - Returns: String with characters…arrow_forward
- Do not use static variables to implement recursive methods. USING JAVA: // P6 public static int countSubstrings(String s1, String s2) { } Write a recursive method countSubstrings that counts the number of non-overlapping occurrences of a string s2 in a string s1. Use the method indexOf() from String class. As an example, with s1=”abab” and s2=”ab”, countSubstrings returns 2. With s1=”aaabbaa” and s2=”aa”, countSubstrings returns 2. With s1=”aabbaa” and s2=”AA”, countSubStrings returns 0. Show the output on the following strings: s1 = “Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture.…arrow_forwardWhat is the output of the following code? Explain each line of the console output in yourown words. (HINT: if there are errors, please explain why the errors occur) import java.util.ArrayList;public class Pet {public void goToVet(){System.out.println("My Pet needs to go to Vet ...");}public static void main(String args[]){Hamster pug = new Hamster();Pet sally = new Pet();Pet loki = new Hamster();Object sunny = new Object();Object joy = new Pet();Object mini = new Hamster();ArrayList<Object> myList = new ArrayList<>(); myList.add(pug); myList.add(sally);myList.add(loki);myList.add(sunny);myList.add(joy);myList.add(mini);myList.forEach(i -> {if (i instanceof Hamster) {System.out.println("My Pet is cute: so " + (((Hamster) i).cute())+ "! ");((Hamster) i).goToVet();}else if (i instanceof Pet)((Pet) i).goToVet();elseSystem.out.println("This is not a Pet");});}}class Hamster extends Pet {public void goToVet(){System.out.println("My Hamster needs to go to Vet…arrow_forwardWhat is the output of the following code? Explain each line of the console output in yourown words. (HINT: if there are errors, please explain why the errors occur)import java.util.ArrayList;public class Pet {public void goToVet(){System.out.println("My Pet needs to go to Vet ...");}public static void main(String args[]){Hamster pug = new Hamster();Pet sally = new Pet();Pet loki = new Hamster();Object sunny = new Object();Object joy = new Pet();Object mini = new Hamster();ArrayList<Object> myList = new ArrayList<>(); myList.add(pug); myList.add(sally);myList.add(loki);myList.add(sunny);myList.add(joy);myList.add(mini);myList.forEach(i -> {if (i instanceof Hamster) {System.out.println("My Pet is cute: so " + (((Hamster) i).cute())+ "! ");((Hamster) i).goToVet();}else if (i instanceof Pet)((Pet) i).goToVet();elseSystem.out.println("This is not a Pet");});}}class Hamster extends Pet {public void goToVet(){System.out.println("My Hamster needs to go to Vet…arrow_forward
- (YOU ARE NOT ALLOWED TO USE ARRAYLIST IN THIS PROJECT)Write a Java program to simulate a blackjack game of cards. The computer will play the role of the dealer. The program will randomly generate the cards dealt to the player and dealer during the game. Cards in this game will be represented by numbers 1 to 13 with Ace being represented by a 1. Remember, that face cards (i.e. Jack, Queen, and King) are worth 10 points to a hand while an Ace can be worth 1 or 11 points depending on the user’s choice. The numbered cards are worth their number value to the hand.arrow_forwardPlease include a gui for the encryption and decryption java code. Example of the gui in the photos Java encryption and decryption code below import java.util.*; public class Main { //Inputs a one character string and returns True if the character is a letter (i.e. a to z or A to Z). Returns false if it is not. A function to check that the password or encryption key is valid. public static boolean isALetter(char letter){ if( (letter >= 'a' && letter = 'A' && letter =-32767 && encryptKeyarrow_forward5. Now examine the for-loops in the above Java program. (assume that we have the have replaced the array with an ArrayList) a) Which ArrayList method should you use to control the for-loop iterations? b) Explain why the first for-loop cannot be controlled by that ArrayList method (but the other two for-loops can). Here is a quick review of how array elements are modified and accessed: 1. public class BasicArray{ 2. public static void main(String[] args) int[] basic = new int[4]; for (int i=0; iarrow_forwardWrite a method that returns the smallest element in the array that it takes as a parameter. (In the "main" method,will be encoded in java)arrow_forward(Implement set operations in MyList)(JAVA) Please use class name: Exercise_01 The implementations of the methods addAll, removeAll, retainAll, toArray(), and toArray(T[]) are omitted in the MyList interface. Implement these methods. Test your new MyList class using the code at https://liveexample.pearsoncmg.com/test/Exercise24_01.txt. Sample Output: Enter five strings for array name1 separated by space: TomGeorgePeterJeanJaneEnter five strings for array name2 separated by space: TomGeorgeMichaelMichelleDanielEnter two strings for array name3 separated by space: TomPeterlist1:[Tom, George, Peter, Jean, Jane]list2:[Tom, George, Michael, Michelle, Daniel]After addAll:[Tom, George, Peter, Jean, Jane, Tom, George, Michael, Michelle, Daniel] list1:[Tom, George, Peter, Jean, Jane]list2:[Tom, George, Michael, Michelle, Daniel]After removeAll:[Peter, Jean, Jane] list1:[Tom, George, Peter, Jean, Jane]list2:[Tom, George, Michael, Michelle, Daniel]After retainAll:[Tom, George] list1:[Tom, George,…arrow_forwardJava: Class: MiddleStr Write a method public static String middle(String str) that returns a string containing the middle character in str if the length of str is odd, or the two middle characters if the length is even. For example, middle("middle") returns "dd". Write a test program [main()] to test the method.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education