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,[email protected]

Josephine,Darakjy,[email protected]

ART,VENERE,[email protected]

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

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,[email protected] Josephine,Darakjy,[email protected] ART,VENERE,[email protected] ... The prospect_clean.csv file First,Last,email James,Butler,[email protected] Josephine,Darakjy,[email protected] Art,Venere,[email protected]...

  • Exception handling is a powerful tool used to help programmers understand exception errors. This tool separates...

    Exception handling is a powerful tool used to help programmers understand exception errors. This tool separates the error handling routine from the rest of the code. In this application, you practice handling exception errors. You use sample code that was purposefully designed to generate an exception error, and then you modify the code so that it handles the errors more gracefully. For this Assignment, submit the following program: The following code causes an exception error: import java.io.BufferedReader; import java.io.IOException; import...

  • 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 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...

  • 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...

  • 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...

  • I need help with this code This is what I need to do: Implement the Stack...

    I need help with this code This is what I need to do: Implement the Stack Class with an ArrayList instead of an array, including the following functions: • empty • push • peek • pop • overrided toString( ) function which returns all of the stack’s contents Things to note: • You no longer need a size. • You no longer need to define a constant DEFAULT_CAPACITY. Since ArrayLists grow dynamically. • Whenever possible, use ArrayList functions instead of...

  • I need help understanding this programming assignment. I do not understand it at all. Someone provided...

    I need help understanding this programming assignment. I do not understand it at all. Someone provided me with the code but when I run the code on eclipse it gives an error. Please explain this assignment to me please. Here is the code: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class TextEditor { public static List<String> lines = new ArrayList<String>(); public static void main(String[] args) throws IOException { Scanner s = new...

  • Java: Hello, can someone please find a way to call my arraylist "list" and linkedhashmap called...

    Java: Hello, can someone please find a way to call my arraylist "list" and linkedhashmap called "jobMap" in my main method instead of calling them in the 2 classes? Also, is there a way to avoid the "Suppress Warning" portion in RoundRobin.java? I haven't been able to find a way for some reason. This is a job scheduling program, so the output should give the same values. To run: javac Main.java, java Main 5jobs.txt . txt file will be provided...

  • The names of the two input files as well as the output file are supposed to be provided as arguments. Could you please fix it? Thanks. DPriorityQueue.java: // Import the required classes import java....

    The names of the two input files as well as the output file are supposed to be provided as arguments. Could you please fix it? Thanks. DPriorityQueue.java: // Import the required classes import java.io.*; import java.util.*; //Create the class public class DPriorityQueue { //Declare the private members variables. private int type1,type2; private String CostInTime[][], SVertex, DVertex; private List<String> listOfTheNodes; private Set<String> List; private List<Root> ListOfVisitedNode; private HashMap<String, Integer> minimalDistance; private HashMap<String, Integer> distOfVertices; private PriorityQueue<City> priorityQueue; // prove the definition...

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