1 answer

*q3: Write a public static method named q3 that takes no parameters and has return type...

Question:

*q3: Write a public static method named q3 that takes no parameters and has return type void. In this method, you may assume there is a file named properties.csv with lines in the format name, opposed, pure,glad where name is a String and all other values are well-formed integers. There is no header line in this file. This method will create a new * file named output.csv in the format name, pure containing only these two columns from properties.csv and only for lines with a name of refuse, being, poll, or essential

*q3: Write a public static method named q3 that takes no parameters and has return type void. In this method, you may assume there is a file named "properties.csv" with lines in the format "name, opposed, pure,glad" where "name" is a String and all other values are well-formed integers. There is no header line in this file. This method will create a new * file named "output.csv" in the format "name, pure" containing only these two columns from "properties.csv" and only for lines with a name of "refuse", "being", "poll", or "essential"

Answers

Please find the below implemented public static void q3() method. Also find the ProcessCSVFile class with q3 and main method to test the functionality of the q3 method.

Please find the below input dummy properties.csv and generated output.csv file by q3 method.

Please revert back in case anything else needs to do.

****** q3 method ******


public static void q3() {
Scanner sacnnerReader = null;
BufferedWriter bufferedWriter = null;
FileWriter fileWriter = null;
try {
File file = new File("properties.csv");
if (file.exists()) {
// creating File Writer to write CSV file
fileWriter = new FileWriter("output.csv");
// creating Buffered Writer to write CSV file
bufferedWriter = new BufferedWriter(fileWriter);
// creating sacnner Reader to read CSV file
sacnnerReader = new Scanner(file);
while (sacnnerReader.hasNextLine()) {
String line = sacnnerReader.nextLine();
String lineArray[] = line.split(",");
String name = lineArray[0];
int pure = Integer.parseInt(lineArray[2]);
if (name != null && (name.equals("refuse") || name.equals("being") ||
name.equals("poll") || name.equals("essential"))) {
bufferedWriter.write(name+","+pure);
bufferedWriter.newLine();
}
}
bufferedWriter.flush();
} else {
System.out.println("Input File not found");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (sacnnerReader != null) {
sacnnerReader.close();
}
if (bufferedWriter != null) {
bufferedWriter.close();
}
if (fileWriter != null) {
fileWriter.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

****** ProcessCSVFile Class ********


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class ProcessCSVFile {
public static void main(String[] args) {
q3();
}
public static void q3() {
Scanner sacnnerReader = null;
BufferedWriter bufferedWriter = null;
FileWriter fileWriter = null;
try {
File file = new File("properties.csv");
if (file.exists()) {
// creating File Writer to write CSV file
fileWriter = new FileWriter("output.csv");
// creating Buffered Writer to write CSV file
bufferedWriter = new BufferedWriter(fileWriter);
// creating sacnner Reader to read CSV file
sacnnerReader = new Scanner(file);
while (sacnnerReader.hasNextLine()) {
String line = sacnnerReader.nextLine();
String lineArray[] = line.split(",");
String name = lineArray[0];
int pure = Integer.parseInt(lineArray[2]);
if (name != null && (name.equals("refuse") || name.equals("being") ||
name.equals("poll") || name.equals("essential"))) {
bufferedWriter.write(name+","+pure);
bufferedWriter.newLine();
}
}
bufferedWriter.flush();
} else {
System.out.println("Input File not found");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (sacnnerReader != null) {
sacnnerReader.close();
}
if (bufferedWriter != null) {
bufferedWriter.close();
}
if (fileWriter != null) {
fileWriter.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

****** properties.csv ******

***** output.csv *******

.

Similar Solved Questions

1 answer
Define the problem of level pool routing. Describe a commonly used method of reservoir routing.
Define the problem of level pool routing. Describe a commonly used method of reservoir routing....
1 answer
How do you find the antiderivative of #e^(-2x)#?
How do you find the antiderivative of #e^(-2x)#?...
1 answer
Kool Beans Gourmet Coffee uses a periodic inventory system. Prepare general Journal entries to record the...
Kool Beans Gourmet Coffee uses a periodic inventory system. Prepare general Journal entries to record the following transactions for Kool Beans: Kool Beans purchased merchandise on credit from Trice Foods for June $9,000, terms 2/10,n/30, FOB destination. Transportation costs of $350 were paid by Tr...
1 answer
3. Using a long rod that has length y, you are going to lay out a...
3. Using a long rod that has length y, you are going to lay out a square plot in which the length of each side is p. Thus the area of the plot will be j?. However, you do not know the value of u, so you decide to make n independent measurements X1, X2, ..., Xn of the length. Assume that each X; has ...
1 answer
Please just explain how to know how much is deducted. i dont understand the question. History...
please just explain how to know how much is deducted. i dont understand the question. History Bookmarks People Tab Window Help sot.it/V2/ameblockquizid.c83ef961-214-4672-089-80c chio and taxes for an employee are below. How much is deducted for FICA Medicare Wages Fed Inc Tax o o State Income FI...
1 answer
Need help. write clearly please Problem 4: A bag containing O'C ice is much more effective...
need help. write clearly please Problem 4: A bag containing O'C ice is much more effective in absorbing energy than one containing the same amount of 0°C water. Part (a) What heat transfer, in joules, is necessary to raise the temperature of 0.75 kg of water (e-4186J/kg "ch) from 0°C...
1 answer
Hoping to improve customer service, Bob is considering hiring a second mechanic to work in the...
Hoping to improve customer service, Bob is considering hiring a second mechanic to work in the second bay. As before, on average customers arrive at a rate of 2 per hour and he can typically service a customer in 20 minutes on average. Assume interarrival times and service times are exponentially di...
1 answer
Journalize the following transactions for Matt's Carpentry, Inc. (If no entry is required, select "No Entry...
Journalize the following transactions for Matt's Carpentry, Inc. (If no entry is required, select "No Entry for the account titles and enter for the amounts. Credit account titles are automatically indented when amount is entered. Do not indent manually. Record journal entries in the order p...
1 answer
Question 1 0.3125 points Transcripts for gene Q are relatively stable, so when a cell needs...
Question 1 0.3125 points Transcripts for gene Q are relatively stable, so when a cell needs to turn off gene expression for gene Qit expresses gene T, which produces RNA that is complementary to gene QmRNA. This is an example of regulation aposttranslational b. posttranscriptional transcriptional d....
1 answer
#25,27,29,31,33 Ages of Adults in the United States Who Own Automobiles Incomes of Home Owners in...
#25,27,29,31,33 Ages of Adults in the United States Who Own Automobiles Incomes of Home Owners in 23. Ages of adults in the US who own Honda home owners in Massachusetts Incomes of home owners in Massachusetts without mortgages Ages of adults in the U.S who own automobiles made by a company other t...
1 answer
The large box is for drawing and labeling the distribution and is part of the grade....
The large box is for drawing and labeling the distribution and is part of the grade. 1.(10pts) What proportion of the t-distribution with 38 degrees of freedom is above a t-value of -2.02? | -0.025 = 0.975 0.975 2.(10pts) What proportion of the t-distribution with a sample size of 14 is above a t-va...
1 answer
Based on the 3 Domain system of classification, Bacteria evolved from Archea True False
Based on the 3 Domain system of classification, Bacteria evolved from Archea True False...
1 answer
Suppose you require a peak output voltage of 15.0 V and have available an AC source...
Suppose you require a peak output voltage of 15.0 V and have available an AC source whose peak voltage is 110 V. You have access to an iron core transformer on which there are 200 turns of conducting wire on the side that you have decided to use as the secondary side of the transformer. How many tur...
1 answer
He bookstore at the University of Southern Alabama is owned and operated by the university through...
he bookstore at the University of Southern Alabama is owned and operated by the university through an independent corporation with its own board of directors. The bookstore has three locations on or near the university campus. It stocks a range of items, including textbooks, trade books, logo appare...
1 answer
The bank officer rates applicants for credit
The bank officer rates applicants for credit. Ratings are normally distributed. The mean is 240 and the standard deviation is 60. If 36 applicants are randomly chosen, what is the probability that they will have a rating between 230 and 260?...
1 answer
Betty’s Boards sells a snowboard, Xpert, that is popular with snowboard enthusiasts. Information relating to Betty’s...
Betty’s Boards sells a snowboard, Xpert, that is popular with snowboard enthusiasts. Information relating to Betty’s purchases of Xpert snowboards during September is shown below. During the same month, 121 Xpert snowboards were sold. Betty’s uses a periodic inventory system. D...
1 answer
The Opioid Crisis is affecting New England like many other parts of the country. After reading...
The Opioid Crisis is affecting New England like many other parts of the country. After reading the Boston Magazine article, please discuss the role that you think police should play in addressing the crisis. Do you agree or disagree with the article and your classmates?...
1 answer
I just need answer for b. Thanks You are a manger who employs a participative control...
I just need answer for b. Thanks You are a manger who employs a participative control approach. You have concluded that corrective action is necessary to improve customer satisfaction, but first you need to convince your employees that the problem exists. What kind of evidence di you think employees...