Question

Hello can somebody please help me with Project 15-3 File Cleaner assignment? This project is to...

Hello can somebody please help me with Project 15-3 File Cleaner assignment? This project is to be done while using Java programming. Here are what the assignment says…

Create an application that reads a file that contains an email list, reformats the data, and writes the cleaned list to another file.

Below are the grading criteria…

  1. Fix formatting. The application should fix the formatting problems.
  2. Write the File. Your application should write a file named prospects_clean.csv.
  3. Use title case. All names should use title case (an initial capital letter with the rest lowercase).
  4. Fix email addresses. All email addresses should be lowercase.
  5. Trim spaces. All extra spaces at the start or end of a string should be removed.

Here is the code work I was working on. It seems that there are errors happening and I get message that file is not found when using this code…

import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

public class CSVReader {

   // Used to read CSV file
   public static ArrayList readCSV(String fileName) throws IOException {

       String line = " ";
       BufferedReader br = null;
       ArrayList ar = new ArrayList();

       br = new BufferedReader(new FileReader(fileName));
       // Reading content from CSV file
       while ((line = br.readLine()) != null) {
           ar.add(line);
       }
       // Closing Buffered Reader
       br.close();
       return ar;
   }
}

import java.util.ArrayList;

public class Cleaner {

   // Convert to title case
   static String convert(String str) {
       str = str.toLowerCase();
       char[] array = str.toCharArray();
       // Modify first element in array.
       array[0] = Character.toUpperCase(array[0]);
       // Return string.
       return new String(array);
   }

   // CSV cleaner
   public ArrayList CSVCleaner(ArrayList fileContent) {

       ArrayList cleanerCon = new ArrayList();
       String delimiter = ",";
       StringBuilder newLine = null;

       for (String str : fileContent) {
           String[] fullLine = str.split(delimiter);
           newLine = new StringBuilder();

           for (int i = 0; i < fullLine.length - 1; i++) {
               newLine.append(convert(fullLine[i]) + ",");
           }
           if (EmailValidator.isValidEmail(fullLine[fullLine.length - 1].toLowerCase())) {
               newLine.append(fullLine[fullLine.length-1].toLowerCase());
           } else {
               newLine.append(convert(fullLine[fullLine.length - 1]));
           }

        cleanerCon.add(newLine.toString());
       }

       return cleanerCon;
   }
}

Below is how output kind of looks like…

Console:

File Cleaner

Source file:  prospects.csv

Cleaned file: prospects_clean.csv

Congratulations! Your file has been cleaned!

Prospect.csv file:

FIRST,LAST,EMAIL

james,butler,jbutler(atsign or the small letter a at logo)geemail(This is google mail. I can't say the g word mail).com

Josephine,Darakjy,josephine_darakjy(atsign)darakjy.org

ART,VENERE,ART(atsign)VENERE.ORG

...

Prospect_clean.csv file:

First,Last,email

James,Butler,jbutler(atsign)geemail.com

Josephine,Darakjy,josephine_darakjy(atsign)darakjy.org

Art,Venere,art(atsign)venere.org

...

Thank you for the assistance. I truly appreciate it!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class CSVReader {
   private static String outputFileName = "prospects_clean.csv";
   private static String outputFileHeader = null;

   public static void main(String[] args) throws IOException {
       try {
           ArrayList<FilePojo> transformedInput = new ArrayList<FilePojo>();
           File f = new File("C:\\Users\\Prospect.csv");
           BufferedReader reader = new BufferedReader(new FileReader(f));
           outputFileHeader = reader.readLine();
           System.out.println("output file header::" + outputFileHeader);
           String readLine = "";
           Validator validate = null;
           while ((readLine = reader.readLine()) != null) {
               if (readLine.length() > 0) {
                   validate = new Validator(readLine);
                   transformedInput.add(validate.transformContents());
               }
           }

           transformedInput.stream().forEach(System.out::println);
           ArrayList<FilePojo> outputContents = validate.formatContents(transformedInput);

           outputContents.stream().forEach(x -> System.out.println("Output Object::" + x));

           FileWriter writer = new FileWriter(outputFileName);
           BufferedWriter bwr = new BufferedWriter(writer);
           bwr.write(outputFileHeader);
           bwr.write("\n");
           for (FilePojo filePojo : outputContents) {
               bwr.write(filePojo.getFirstName());
               bwr.write(",");
               bwr.write(filePojo.getLastName());
               bwr.write(",");
               bwr.write(filePojo.getEmail());
               bwr.write("\n");
           }
           bwr.close();
           System.out.println("succesfully written to a file");

       } catch (IOException e) {
           e.printStackTrace();
       }
   }

}
**********************************************************************************************************************************

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Validator {
   private String line;
   private String[] linesArray;
   private FilePojo filePojo;

   public Validator(String line) {
       this.line = line.trim();
       linesArray = this.line.split(",");
   }

   public FilePojo transformContents() {
       filePojo = new FilePojo();
       for (int i = 0; i < linesArray.length; i++) {
           if (i == 0) {
               filePojo.setFirstName(linesArray[i].trim());
           } else if (i == 1) {
               filePojo.setLastName(linesArray[i].trim());

           } else if (i == 2) {
               filePojo.setEmail(linesArray[i].trim());
           }
       }
       return filePojo;
   }

  
   public ArrayList<FilePojo> formatContents(ArrayList<FilePojo> input){
       ArrayList<FilePojo> outputArrayList=new ArrayList<>();
       String regex = "^(.+)@(.+)$";
       Pattern pattern=null;
       for (FilePojo filePojo : input) {
           FilePojo outputpojo=new FilePojo();
           StringBuffer fName=new StringBuffer(filePojo.getFirstName());
           fName.replace(0,1, fName.substring(0,1).toUpperCase()).replace(1, fName.length(), fName.substring(1).toLowerCase());
           //fName.append(fName.substring(0,1).toUpperCase()).append(fName.substring(1).toLowerCase());
           outputpojo.setFirstName(fName.toString());
           //System.out.println("fname::"+fName);
           StringBuffer lName=new StringBuffer(filePojo.getLastName());
           lName.replace(0,1, lName.substring(0,1).toUpperCase()).replace(1, lName.length(), lName.substring(1).toLowerCase());
           //System.out.println("lname::"+lName);
           outputpojo.setLastName(lName.toString());
          
           StringBuffer eMail=new StringBuffer(filePojo.getEmail());
           pattern=Pattern.compile(regex);
           Matcher matcher=pattern.matcher(eMail);
           //System.out.println("Does email has a atleast one '@' sign::"+matcher.matches());
           if(matcher.matches()) {
               eMail.replace(0, eMail.length(), eMail.substring(0, eMail.length()).toLowerCase());
               //System.out.println("EMail:"+eMail);
               outputpojo.setEmail(eMail.toString());
           }
           outputArrayList.add(outputpojo);
       }
       return outputArrayList;
   }
     

}
*************************************************************************************************************************************

public class FilePojo {
   String firstName;
   String lastName;
   String email;
   public String getFirstName() {
       return firstName;
   }
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }
   public String getLastName() {
       return lastName;
   }
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }
   public String getEmail() {
       return email;
   }
   public void setEmail(String email) {
       this.email = email;
   }
   @Override
   public String toString() {
       return "FilePojo [firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]";
   }
  
  

}
***********************************************************************************************************

INPUT FILE

FIRST,LAST,EMAIL

james,butler,jbutler@geemail.com

Josephine,Darakjy,josephine_darakjy@darakjy.org

ART,VENERE,ART@VENERE.ORG

*****************************************************************************************

Just Copy-paste the files to any IDE of your preference. In the CLASS CSVReader, you only need to change the input file location. I have used the input file as pasted above.

The output file will be generated in the current working directory where you have placed the code. In order to see the output file, you might need to refresh the project in case you are using eclipse or any other IDE.

Add a comment
Know the answer?
Add Answer to:
Hello can somebody please help me with Project 15-3 File Cleaner assignment? This project is to...
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
  • I can't get the program to read from prospect.csv file and produce the correct prospect_clean.csv file....

    I can't get the program to read from prospect.csv file and produce the correct prospect_clean.csv file. Can you help with explanation to the answer? Project 15-3: File Cleaner Create an application that reads a file that contains an email list, reformats the data, and writes the cleaned list to another file. Console File Cleaner Source file:  prospects.csv Cleaned file: prospects_clean.csv Congratulations! Your file has been cleaned! The prospect.csv file FIRST,LAST,EMAIL james,butler,jbutler@gail.com Josephine,Darakjy,josephine_darakjy@darakjy.org ART,VENERE,ART@VENERE.ORG ... The prospect_clean.csv file First,Last,email James,Butler,jbutler@gail.com Josephine,Darakjy,josephine_darakjy@darakjy.org Art,Venere,art@venere.org...

  • I need help with this Java question. Please only answer in Java. Also, please answer it...

    I need help with this Java question. Please only answer in Java. Also, please answer it as simple as possible thanks. Create an application that reads a file that contains an email list, reformats the data, and writes the cleaned list to another file. Console File Cleaner Source file:  prospects.csv Cleaned file: prospects_clean.csv Congratulations! Your file has been cleaned! The prospect.csv file FIRST,LAST,EMAIL james,butler,jbutler@random.com Josephine,Darakjy,josephine_darakjy@darakjy.org ART,VENERE,ART@VENERE.ORG The prospect_clean.csv file First,Last,email James,Butler,jbutler@random.com Josephine,Darakjy,josephine_darakjy@darakjy.org Art,Venere,art@venere.org Specifications Your instructor should provide a CSV file...

  • Java Email Template Application: Create an application that creates a series of emails as outlined below....

    Java Email Template Application: Create an application that creates a series of emails as outlined below. Create an array of email addresses that include the following data: "   james   ,butler,jbutler@hotmail.com" "Josephine,Darakjy,Josephine_Darakjy@darakjy.org" "ART,VENERE,ART@VENERE.ORG" Store a template for a mass email like this: String template =     "To:      {email}\n" +     "From:    noreply@deals.com\n" +     "Subject: Deals!\n\n" +     "Hi {first_name},\n\n" +     "We've got some great deals for you. Check our website!"; When the application starts, it should read the email...

  • In C++ please! Project 6-1: Email Creator Create a program that reads a file and creates...

    In C++ please! Project 6-1: Email Creator Create a program that reads a file and creates a series of emails Console Email Creator jbutler@gmail.com noreply@deals.com Тo: From: Subject: Deals! Hi James, We've got some great deals for you. Check our website! josephine_darakjy@darakjy.org noreply@deals.com To From Subject: Deals! Hi Josephine, We've got some great deals for you. Check our website! art@venere.org To From noreply@deals.com Subject: Deals! Hi Art We've got some great deals for you. Check our website! Specifications Your instructor...

  • Can someone please help me? I'm having trouble with this assignment and have been stuck trying...

    Can someone please help me? I'm having trouble with this assignment and have been stuck trying to figure it out for over an hour. Here's the assignment details below: For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text flie, sort and store the contents of the text file into an ArrayList, then write the sorted contents...

  • Can someone help me with this code, I not really understanding how to do this? import...

    Can someone help me with this code, I not really understanding how to do this? import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * @version Spring 2019 * @author Kyle */ public class MapProblems { /** * Modify and return the given map as follows: if the key "a" has a value, set the key "b" to * have that value, and set the key "a" to have the value "". Basically "b" is confiscating the * value and replacing it...

  • Information About This Project             In the realm of database processing, a flat file is a...

    Information About This Project             In the realm of database processing, a flat file is a text file that holds a table of records.             Here is the data file that is used in this project. The data is converted to comma    separated values ( CSV ) to allow easy reading into an array.                         Table: Consultants ID LName Fee Specialty 101 Roberts 3500 Media 102 Peters 2700 Accounting 103 Paul 1600 Media 104 Michael 2300 Web Design...

  • can some one help me solve this and explain it please Input Format A line indicating...

    can some one help me solve this and explain it please Input Format A line indicating the size of the array the array on the next line Constraints n < 10000 Output Format One line printing the array in order input (given to you) One line printing the array, followed by its maximum value Sample Input 0 5 1 3 5 7 9 Sample Output 0 1 3 5 7 9 9 7 5 3 1 9 Contest ends in...

  • Can you help me rearrange my code to make it look cleaner but still give the...

    Can you help me rearrange my code to make it look cleaner but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string, double and int array containing * the command line arguments. * @exception Any exception * @return an arraylsit of...

  • Please help me fix my errors. I would like to read and write the text file...

    Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors. below is my code import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.FileWriter; import java.io.IOException; public class LinkedList {    Node head;    class Node    {        int data;        Node next;       Node(int d)        {            data = d;            next = null;        }    }    void printMiddle()    {        Node slow_ptr...

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