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: Brief Version (11th Global Edition)
Additional Engineering Textbook Solutions
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Starting Out with Python (4th Edition)
Modern Database Management
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Code with comments and output screenshot. Thank you!! Write a java method that receives a string containing letters of the English alphabet and then prints the Letters having unique frequencies. Notes: 1) Ignore letter case; Uppercase and lowercase letters are considered the same. 2) Do not use methods from the Arrays class.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
- 5. 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_forwardComplete the method in Java. Name of the public class is Assignment1.javaarrow_forwardJava: Class: WordCount Write a method using the header below (remember your Javadoc comment) public static int countWords(String str) that returns a count of all words in the string str. Words are separated by spaces. For example, countWords("Mary had a little lamb") should return 5. Your method should work correctly if there are multiple spaces between words. Use helper methods to find the position of the next space following a given position, and the position of the next non-space character following a given position. Write a test program [main()] to test the method.arrow_forwardPlease complete the task by yourself only in JAVA with explanation. Don't copy. Thank you. Using quicksort to sort an array of car objects by various criteria. Define a class Car as follows: class Car { public String make; public String model; public int mpg; // Miles per gallon } c) Implement a comparator called CompareCarsByMakeThenDescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByMakeThenDescendingMPG should return a value that will cause quicksort to sort an array of cars in ascending order by make and, when two cars have the same make, in descending order by mpg.arrow_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_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_forwardJavaarrow_forwardJava Programming [ Using Array] - 2arrow_forwardI am having trouble with this: Implement the convertString method based on its specification. Here are some things that can help: the Character class has some utility methods to determine if a character is uppercase, lowercase, or a digit (numeral) the String class has a method to get the character at a specific position (called the index). Find that method and use it. make use of the convert methods you already have!convertString Specification: /** * Converts the letters and numerals in the given string * to their circled counterparts. All other characters * are unchanged. * * @precondition text != null * @postcondition none * * @param text the text to convert * @return a modified version of text, with all letters and numerals * circled. */My code: public class CircleStrings { /** * Converts the letters and numerals in the given string * to their circled counterparts. All other characters * are unchanged. * *…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