Question
Java2
Screenshot of the output required
Put some comment

..Il AT&T令 12:28 AM Back Complete and Submit Lab 2C Detail Submission Grade Complete and Submit Lab 2C Due: Mar 1, 2019 at 11
ll AT&T 12:28 AM KBack Complete and Submit Lab 2c on each e Detail Submission Grade a separate line) . If no symbol appears i
ll AT&T 12:28 AM Back Complete and Submit Lab 2C For bo leadin Detail Submission Grade You must also write any valid addres
ll AT&T 12:29 AM Back Complete and Submit Lab 2C Detail Submission Grade You must al containing @howardcc.edu to a file named
This is the mailing text file for the assignment

.nl AT&T令 12:28 AM 84%- Back Lab2A.txt new.studenthowardcc.edu SweetToothêgmail.com namenotfoundyahoo.com mQuinn howardcc.edu
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Lab2C.java

/**
 *  Name: 
 *  Course number:
 *  Section:
 *  This program reads a mailing list text file from disk and tells whether
 *  the email addresses are invalid. If the email address is valid, then 
 *  it gives statistics about address and does some string manipulations 
 *  and writes to another text file.
 */
package abc1;
import java.io.*;
public class Lab2C {
        public static void main(String[] args) {
                
                try {
                        File myfile = new File("src/abc1/Lab2A.txt");         //Creating file object representing text file
                        FileReader filereader = new FileReader(myfile);         //creating a connection stream  for chars that connects to text file
                        BufferedReader reader = new BufferedReader(filereader); //chain the FileReader to BufferedReader for efficiency
                                        //For output file
                        File mynewfile = new File("src/abc1/howardBeeMailing.txt");   //creating new file
                        FileWriter filewriter = new FileWriter(mynewfile);
                        BufferedWriter writer = new BufferedWriter(filewriter);
                        
                        String line = null;
                        while((line=reader.readLine())!=null) {         //reading each line till end of file is found
                                boolean valid = false;                                  //initializing validity of each line as false, then we will check
                                if(line.contains("@")) {                                //if email address contains @
                                        valid = true;
                                        System.out.println(line.trim().toLowerCase());  //remove space, print in lowercase
                                        System.out.println("Length: " + line.length());
                                        System.out.println("Characters before @: " + (line.indexOf('@')));      //calculating chars before @
                                        System.out.println("Characters after @: " + (line.length()-line.indexOf('@')-1));       //calculating chars after @
                                                                //writing valid email addresses with @howardcc.edu to another fle
                                        
                                        if(line.contains("[email protected]")) {
                                                String str = line.trim().toUpperCase();
                                                writer.write(str);
                                                writer.write('\n');
                                        }
                                        else if(line.contains("howardcc.edu")) {
                                                writer.write(line.trim());
                                                writer.write('\n');
                                        }
                                }
                                else {                                                                  //if email address doesn't contain @
                                        System.out.println(line + " - " + "Email address unreadable");
                                }
                                
                        }
                        reader.close();
                        writer.close();
                }
                catch(Exception e){
                        e.printStackTrace();
                }
        }
}

Time taken to complete: 55 Mins

Most difficult part: Creating and accessing files.

Add a comment
Know the answer?
Add Answer to:
Java2 Screenshot of the output required Put some comment This is the mailing text file for...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT