1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Delicious77 [7]
3 years ago
14

I need help to make this code to make it remove all instances of the specified letter from the original sentence

Computers and Technology
1 answer:
Agata [3.3K]3 years ago
5 0
Here is my solution. I did the following:

- changed the setRemover into a constructor, since the comment seems to hint that that is expected.
- changed the lookFor type into a String, so that it can work with the string replace overload. That's convenient if you want to replace with an emtpy string. The char type won't let you do that, you can then only replace one char with another.
- Added a static Main routine to use the class.

import java.lang.System.*;

public class LetterRemover 
{
   private String sentence;
   private String lookFor;

   public LetterRemover() {}
   
   // Constructor
   
   public LetterRemover(String s, char rem)
   {
       sentence = s;
       lookFor = String.valueOf(rem);
   }
   
   public String removeLetters()
   {       
       String cleaned = sentence.replace(lookFor, "");       
       return cleaned;
   }
   
   public String toString()
   {
       return sentence + " - letter to remove " + lookFor;
   }

   public static void main(String[] args) 
   {
        LetterRemover lr = new LetterRemover("This is the tester line.", 'e');
        System.out.println(lr.toString());
        String result = lr.removeLetters();        
        System.out.println("Resulting string: "+result);
   }
}

You might be interested in
100 tickets are sold in a raffle with one prize. John has 8 tickets, Jamie has 10 tickets, find the probability that John wins
Reika [66]

\frac{8}{100} or \frac{2}{25}
7 0
3 years ago
Read 2 more answers
Suggest any complete anime......?​
strojnjashka [21]
Ummmm toradora? on netflix
6 0
2 years ago
Read 2 more answers
What is a good place for students to read an out-of-print book.
love history [14]

Answer:

library because u said so

4 0
3 years ago
Read 2 more answers
When spark plug cables aren't far enough apart, premature firing of adjacent spark plugs can happen. this is known as?
e-lub [12.9K]
Misfiring seems to be a blanket term for spark plug inefficiencies and errors due to wrong gap configuration. Because of the small gap, the time <span>of the spark has less travel distance, it does not remain hot enough to ignite the air-fuel mixture that is needed to run the engine. </span>
7 0
3 years ago
Consider the following code segment: theSum = 0.0 while True: number = input("Enter a number: ") if number == ": break theSum +=
Strike441 [17]

n where n is the number of chances user takes to enter a blank number and n>=1.

<u>Explanation:</u>

The loop starts with a universal condition where it is initialized using a true value. Hence the iteration count goes to 1. The user is asked to enter a number after 1st iteration. If number is a blank number, the loop is terminated, else the loop goes on until the users enters a blank number. Hence the iterations depend on the number of chances taken by the user to enter a blank number. Since the user is going to enter a number at least once, the minimum value of n will be 1.

4 0
3 years ago
Other questions:
  • Write a program that reads in two integers typed on the keyboard and outputs their sum, difference, and product.
    12·1 answer
  • python A pet shop wants to give a discount to its clients if they buy one or more pets. The discount is equal to 20 percent of t
    12·1 answer
  • If you want to insert a column into an existing table what would you do
    11·1 answer
  • How do you answer a question on this app?!? Do you comment on the question? I need a reminder! (I haven't been on this app in a
    12·1 answer
  • Is 583 a string or a number?
    13·2 answers
  • Generally speaking, problems are rarely caused by motherboards. However, there are some instances in which a motherboard can fai
    12·1 answer
  • Which of these converts the reciprocating motion of the piston into rotary motion?
    7·1 answer
  • A printer is considered to be in the category of
    5·2 answers
  • Hey! I was recommended a site “9anime” the other day. All’s been going well but I accidentally taped on a new dub settingZ somet
    8·2 answers
  • Who would win in a fight, Noble 6 from halo reach or Master Chief??
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!