Question

Write in Java and explain all the code. Have a unit test implemented in the main...

Write in Java and explain all the code.
Have a unit test implemented in the main method.
Show example of the execution
Write a filter to clean a text, which is to say to delete all the characters that are not alphabetic, plans or a newline. And besides deleting them they should all also be replaced with a blank spot, so that the number of characters are still the same as the text before it was cleaned.

Homework Answers

Answer #1

If you have any doubts, please give me comment...

public class FilterText{

    public static void main(String[] args) {

        String result = filter("Hi! th#s is test!ng!");

        System.out.println(result);

    }

    public static String filter(String str){

        String result = "";

        for(int i=0; i<str.length(); i++){

            if(Character.isAlphabetic(str.charAt(i)))

                result += str.charAt(i);

            else

                result += " ";

        }

        return result;

    }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
Please program in JAVA: Program each option such as delete line and such. Your program will...
Please program in JAVA: Program each option such as delete line and such. Your program will be a line editor. A line editor is an editor where all operations are performed by entering commands at the command line. Commands include displaying lines, inserting text, editing lines, cutting and pasting text, loading and saving files. For example, a session where the user enters three lines of text and saves them as a new file may appear as: Menu: m Delete line:...
Instruction This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks....
Instruction This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks. These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
Question(C++). Please write a C++ code, it will generate a conversation between Hans and Beatrice by...
Question(C++). Please write a C++ code, it will generate a conversation between Hans and Beatrice by randomly selecting phrases and sentences from files, then altering them before output The code will start the conversation between Hans and Beatrice by having Hans say "hello" (it's him who makes the call). This is to be followed alternately by Beatrice and then Hans saying something. Each thing they say will be chosen at random from their respective files, HansSayings.dat and BeatriceSayings.dat. But before...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...