QuestionQuestion

Write a program that consists of three classes.The first class will be the actual program.
The second class will simply convert a string to lower case.
The third class will have three methods:
public static String trimmed(String str)
public static String trimmed(String str, int len)
public static String squeeze(String str)
The 1st trimmed method will return str without leading or trailing white space and will return an empty string if str is null.
The 2nd trimmed method will return the first len characters after trimming the string. The 2nd method must make use of the 1st method.
The squeeze method will replace all sequences of 2 spaces with 1 space.
The program will read a file containing the data below (cut and paste it into notepad and save it), and will display each line:
1.as entered but trimmed and squeezed.
2.as entered but trimmed, squeezed, and shortened to 10 characters
3.as entered but trimmed, squeezed, converted to lower case, and shortened to 20 characters.
Data (copy after this line down to (not including)the line that says end data, you will have 5 lines):
This is a test, this is only a test!
This test is a test of your Java programming skills!
xyz
ABCDEFGHIJKLMONPQRSTUVWXYZ1234567890-=_+!
end data

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.io.*;
import java.util.Scanner;

class assignment3 {
public static void main(String [] args) throws FileNotFoundException
{
String str1 = new Scanner(new File("test.txt")).useDelimiter("\\Z").next(); // the delimiter \Z is used because tokens end at end of file
                                                                  //one call to next brings the whole content of the file in this case
String str2 = StringOperations.trimmed(str1);
//task 1 - the input is printed trimmed and squeezed
System.out.println("Task1 - the content is trimmed & squeezed");
System.out.println("*********************************************");
System.out.println( StringOperations.squeeze(str2) );

String str3 = StringOperations.squeeze(str1);
//task2 - input is trimmed, squeezed and shortened to 10 characters only
System.out.println("Task2 - the content is trimmed, squeezed, and shortened to 10 characters");
System.out.println("*****************************************************...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$25.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats