Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 1, Problem 9R
Program Plan Intro
Removing all the punctuations from a string
Program plan:
- Create a class StringBuilder to remove all the punctuation stored in a string.
- In main() function,
- Initially, assign the original string in variable.
- Then, invoke the removeIt()function to remove all the punctuation in a string and store the final value in original string.
- Display the string after removing the punctuation in console screen.
- In the method removeAt(),
- It passes input parameter “s” to check whether the character contains punctuation in the string. If yes, then it removes all the punctuation stored in the string “s”.
- For loop read all the characters from a sentence until the condition leads to false.
- Then, it calls the function ok() and check whether the character at “j” position matches with the character or not.
- If the result returns the Boolean value false, then delete the character at the specified position in “j” otherwise store the character using Tostring() method in “s” variable.
- In the method ok(),
- It passes input parameter “i” to check whether the character in the sentence matches with the corresponding ASCII values.
- If yes, then it returns the Boolean value true otherwise it return false.
- It passes input parameter “i” to check whether the character in the sentence matches with the corresponding ASCII values.
- In main() function,
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write an application that reads a five-letter word from the user and produces every possible three-letter string that can be derived from the letters of that word. For example, the three-letter words produced from the word “bathe” include “ate,” “bat,” “bet,” “tab,” “hat,” “the” and “tea.”
WRITE IN JAVA USING JOptionPane.showInputDialog
Write a program that reads a sentence as input and converts each word to “Pig Latin”. In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word, and then appending “ay” to the word. Here is an Example:
English: I SLEPT MOST OF THE NIGHT
Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
EXAMPLE:
Implement your own indexOf(String s) and lastIndexOf(String s) methods without using the built-in ones available in Java String class. Complete the following program://course: CSC190//project: Lab 12//date: (today’s date)//author: (your name)//purpose:import java.util.Scanner;class MyString {String s; //default constructor which sets s to a null string //your code here //additional constructor which sets s to the string passed from the caller //your code here //get and set methods for s //your code here //return the index within s of the first occurrence of str. //return -1 when str is not found on s. //if s = "aabababb", s = "aba", return 1 //if s = "aabababb", s = "abaa", return -1 int indexOf(String str) { //your code here} //return the index within s of the last occurrence of str. //return -1 when s is not found on str. //if s = "aabababb", s = "aba", return 3 //if s = "aabababb", s = "abaa", return -1 int lastIndexOf(String s) { //your…
Chapter 1 Solutions
Data Structures and Algorithms in Java
Ch. 1 - Prob. 1RCh. 1 - Suppose that we create an array A of GameEntry...Ch. 1 - Write a short Java method, isMultiple, that takes...Ch. 1 - Write a short Java method, isEven, that takes an...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that counts the number...Ch. 1 - Prob. 9RCh. 1 - Prob. 10R
Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Prob. 12RCh. 1 - Modify the declaration of the first for loop in...Ch. 1 - Prob. 14CCh. 1 - Write a pseudocode description of a method for...Ch. 1 - Write a short program that takes as input three...Ch. 1 - Write a short Java method that takes an array of...Ch. 1 - Prob. 18CCh. 1 - Write a Java program that can take a positive...Ch. 1 - Write a Java method that takes an array of float...Ch. 1 - Write a Java method that takes an array containing...Ch. 1 - Prob. 22CCh. 1 - Write a short Java program that takes two arrays a...Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Modify the CreditCard class to add a toString()...Ch. 1 - Write a short Java program that takes all the...Ch. 1 - Write a Java program that can simulate a simple...Ch. 1 - A common punishment for school children is to...Ch. 1 - The birthday paradox says that the probability...Ch. 1 - (For those who know Java graphical user interface...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- FOR JAVA Write a method that takes a String array and an integer as parameters and prints the Strings in the array whose length is greater than the second parameter.arrow_forwardWrite the code in java and please dont plagarise or copy from other sources write it on your own and read the question carefully and do what in the question says thank you.arrow_forwardWrite code that uses a regular expression to see if a string could be a variable, class, or method name in the java programming language (can be coded in any language).arrow_forward
- In java can you help with parts that are missing Email- date: Date- subject: String- urgent: boolean+ Email(date:Date,urgent:boolean,subject:String)+ getDate(): Date+ setDate(date: Date): void+ getSubject(): String+ setSubject(subject:String): void+ isUrgent(): boolean+ setUrgent(urgent: boolean): void+ toString(): String public class Email { private Date date; private String subject; privatebooleanurgent; public Email() { } public Email(Date date, booleanurgent, String subject) { this.date = date; this.urgent = urgent; this.subject = subject; } public Date getDate() { returndate; } publicvoid setDate(Date date) { this.date = date; } public String getSubject() { returnsubject; } publicvoid setSubject(String subject) { this.subject = subject; } publicboolean isUrgent() { returnurgent; } publicvoid setUrgent(booleanurgent) { this.urgent = urgent; } @Override public String toString() { return"Email [date=" + date + ", subject=" + subject + ", urgent=" + urgent +…arrow_forwardJavaarrow_forwardJavaarrow_forward
- Write a java class method named addQuotes that takes one parameter of type String. The method should return a string that's indentical to it's argument, but with a double quote character added at the beginning and end of the string.arrow_forwardImplement a toString method for the following class that returns a string containing the class name and the names and values of all instance variables.arrow_forwardIn java Consider strings that can be split so that their first half is the same as their second half (ignoring blanks, punctuation, and case). For example, the string "booboo" can be split into "boo" and "boo". Another example is "hello, hello". After ignoring blanks and the comma, the two halves of the string are the same. However, the string "rattan" has unequal halves, as does the string "abcab". Add a method public static boolean check(String s) to the class Array Queue (function must be in the file ArrayQueue.java) that returns true when s has the property above and false otherwise. must use methods from Queuelnterface.java and ArrayQueue.java. Do not use stacks or recursion. First - In this problem, we will add new methods to the class Array Queue Suppose that we want to add a method to a class of queues that will splice two queues together. This method adds to the end of a queue all items that are in a second queue (making the second queue empty). The header of the method could…arrow_forward
- Write a java program with a method that reverses a string The method must accept one parameter of type String (string to reverse), and returns every second element from the end to the beginning. For example: String: thisisstringResult is: g i t s s harrow_forwardWrite a code that generates a random lowercase letter. In java programming. Note: Not a string of letters just one letter is generated every time the program is run. meaning the output should not be something like this: a c t c -that's a random string, it should only be one random letter generated randomly.arrow_forwardUSING JAVA Implement two methods that: Capitalize the first letter of each word in the given text. Reverse the characters in the words that are in the odd positions of the original text. Add a test program that exercises these methods for a string with at least tenwords in it. For example: The original text is "learning javafx is fun! javafx is a powerful library." The result and reversed text will be "Learning xfavaJ Is !nuF Javafx sI A lufrewoP Library."arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education