1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tensa zangetsu [6.8K]
3 years ago
8

The class shown below called is called CSVReader. Use this class exactly as it is written (specifically don’t add any instance v

ariables) except add the code for the methods readFile, numberOfRows, numberOfFields, and field. Not that this class stores the data in a 2-dimensional ArrayList of String. You can assume that the fields in a CSV file are separated by commas. You will find it useful to have a Scanner object that reads the file line by line, and a second Scanner object that processes each line.
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;

public class CSVReader
{
ArrayList> fields;
public CSVReader()
{
fields = new ArrayList>();
}
public void readFile(String filename) throws FileNotFoundException
{
File inputFile = new File (filename);
String word;
String line;
int index = 0;
Scanner in = new Scanner(inputFile);
while(in.hasNextLine())
{
line = in.nextLine();
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter(",");
fields.add(new ArrayList());
while(lineScanner.hasNext())
{
word = lineScanner.next();
fields.get(index).add(word);
}
lineScanner.close();
index++;
}
in.close();
}
public int numberOfRows()
{
return fields.size();
}
public int numberOfFields(int row)
{
if(row < 0) {return 0;}
if(row >= fields.size()){return 0;}
return fields.get(row).size();
}
String field(int row, int column)
{
if( row >= 0 && row < fields.size()){
if(column >= 0 && column < fields.size())
{
return fields.get(row).get(column);
}
else return "";
}
else return "";
}
}

Note: Your program should ignore the first row of data (which is the column headers) even though your CSVReader class will read and store these values.
• You can assume that the names of the realtors in Realty.csv consist of a single-word first name followed by one blank followed by a single-word last name.
• The MLS number should be left justified in a field 8 characters wide
• The name should be written as Lastname, Firstname left justified in a field 20 characters wide
• The street address should be left justified in a field 20 characters wide
• The city should be left-justified in a field 12 characters wide
• The state should be left justified in a field 3 characters wide
• The zip should be left justified in a field 6 characters wide
• The price should be right justified in a field 12 characters wide, preceded by a dollar sign, with decimal separators and 2 digits of precision.
• The square footage, number of bedrooms, number of baths, and price per square foot should look like the example, with price per square foot right justified.
Include the summary information at the bottom.
M5678 Smith, Jane 606 Cardinal St. Maryville TN 37803 $230,000.00 1800 SF 4 beds 2 baths price/sf: $127.78

M3499 McCormick, Lance 418 Scenic Dr. Knoxville TN 37919 $649,000.00 3900 SF 4 beds 4 baths price/sf: $166.41
M2345 Smith, Jane 814 St. Andrew St. La Crosse WI 54601 $99,000.00 1100 SF 2 beds 1 baths price/sf: $90.00
M1265 Finley, Heather 517 Avon St. La Crosse WI 54601 $110,000.00 1200 SF 3 beds 1 baths price/SF: $91.67
M8690 Burmeister, Georgia 728 Alice Bell Rd Knoxville TN 37917 $169,000.00 2100 SF 3 beds 2 baths price/sf: $80.48
M8356 Nichols, Roger 119 Cherokee Blvd Knoxville TN 37919 $999,999.00 3800 SF 5 beds 4 baths price/sf: $263.16
M8211 Jones, Steven 619 Derby St Chattanooga TN 37404 $549,000.00 2800 SF 4 beds 3 baths price/sf: $196.07
M8044 Smith, Harold 872 La Crosse St. La Crosse WI 54603 $210,000.00 2250 SF 3 beds 2 baths price/sf: $93.33
M4789 O'Connor, Judy 4000 McArthur Ave Chattanooga TN 37404 $179,000.00 1675 SF 3 beds 3 baths price/sf: $106.87
M9000 Smith, Alice 1901 3rd St. Chattanooga TN 37411 $158,000.00 2400 SF 3 beds 3 baths price/sf: $65.83
There is a total of 10 homes on the market with an average price of $335,299.90

Using the class provided above make a Tester method that prints out the file provided Realty.csv as well as making sure other files like Realty.csv can also be used in the Tester made us the Class provided. Make it to where any CSV file can be used by hardcoding it in but for this question only focus on the file shown
CSV File contents:
MLS Realtor name Street Address City State Zip Price square footage number of bedrooms number of bathrooms
M5678 Jane Smith 606 Cardinal St. Maryville TN 37803 230000 1800 4 2
M3499 Lance McCormick 418 Scenic Dr. Knoxville TN 37919 649000 3900 4 4
M2345 Jane Smith 814 St. Andrew St. La Crosse WI 54601 99000 1100 2 1
M1265 Heather Finley 517 Avon St. La Crosse WI 54601 110000 1200 3 1
M8690 Georgia Burmeister 728 Alice Bell Rd Knoxville TN 37917 169000 2100 3 2
M8356 Roger Nichols 119 Cherokee Blvd Knoxville TN 37919 999999 3800 5 4
M8211 Steven Jones 619 Derby St Chattanooga TN 37404 549000 2800 4 3
M8044 Harold Smith 872 La Crosse St. La Crosse WI 54603 210000 2250 3 2
M4789 Judy O'Connor 4000 McArthur Ave Chattanooga TN 37404 179000 1675 3 3
M9000 Alice Smith 1901 3rd St. Chattanooga TN 37411 158000 2400 3 3
Computers and Technology
1 answer:
Vesna [10]3 years ago
3 0

Answer:

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class CSVReader {

  ArrayList fields;

  public CSVReader() {

      fields = new ArrayList();

  }

  public void readFile(String filename) throws FileNotFoundException {

      File inputFile = new File(filename);

      String word;

      String line;

      int index = 0;

      int ind2 = 0;

      int valPrice = 0, valSqft = 0, valSum = 0;

      Scanner in = new Scanner(inputFile);

      while (in.hasNextLine()) {

          line = in.nextLine();

          Scanner lineScanner = new Scanner(line);

          lineScanner.useDelimiter(",");

          fields.add(new ArrayList());

          while (lineScanner.hasNext()) {

              word = lineScanner.next();

              if (index != 0) {

                  if (ind2 == 2) {

                      System.out.print(", " + word);

                  } else if (ind2 == 8) {

                      System.out.printf(" $" + Integer.valueOf(word) / 1000);

                      if (Integer.valueOf(word) % 1000 > 0) {

                          System.out.printf(",%.2f", (float) Integer.valueOf(word) % 1000);

                      } else {

                          System.out.print(",000.00");

                      }

                      valPrice = Integer.valueOf(word);

                      valSum += Integer.valueOf(word);

                  } else if (ind2 == 9) {

                      System.out.print(" SF " + word);

                      valSqft = Integer.valueOf(word);

                  } else if (ind2 == 11) {

                      System.out.print(" beds " + word);

                      System.out.printf(" baths price/sf: $ %.2f\n", (float) valPrice / valSqft);

                  } else if (ind2 > 0) {

                      System.out.print(" " + word);

                  } else if (ind2 == 0) {

                      System.out.print(word);

                  }

              }

              ((ArrayList) fields.get(index)).add(word);

              ind2++;

          }

          lineScanner.close();

          index++;

          ind2 = 0;

          valPrice = 0;

          valSqft = 0;

      }

      System.out.printf(

              "There is a total of " + (numberOfRows() - 1) + " homes on the market with an average price of $"+(valSum / (numberOfRows() - 1))/1000+",%.2f",

              (float) (valSum / (numberOfRows() - 1))%1000);

      in.close();

  }

  public int numberOfRows() {

      return fields.size();

  }

  public int numberOfFields(int row) {

      if (row < 0) {

          return 0;

      }

      if (row >= fields.size()) {

          return 0;

      }

      return ((ArrayList) fields.get(row)).size();

  }

  String field(int row, int column) {

      if (row >= 0 && row < fields.size()) {

          if (column >= 0 && column < fields.size()) {

              return (String) ((ArrayList) fields.get(row)).get(column);

          } else

              return "";

      } else

          return "";

  }

  public static void main(String[] args) throws FileNotFoundException {

      CSVReader test = new CSVReader();

      test.readFile("R.csv");

  }

}

Explanation:

You might be interested in
FREE POINTS FIRST TO ANSWER GETS BRANLIEST!!! :)
kicyunya [14]

Answer:

THX

Explanation:

4 0
3 years ago
Read 2 more answers
A(n)…………is the interface used toconnect external devices to the computer.
Mama L [17]

Answer:

D. PORT

Explanation:

A Port is the interface used to connect external devices to  computer.

Ports are of various types based on the type of communication interface:

For example:

  • Serial port : information transfer takes place one bit at a time.
  • Parallel port : transfer of multiple bits at a time.
  • Ethernet : used for connecting network cable
  • USB : Universal Serial Bus

Computer peripherals like mouse,keyboard, modem, printer etc connect to the computer via the port which is in accordance with their specified communication interface.

6 0
4 years ago
1. Why isn't solar energy usually the only power source for a region?
ale4655 [162]
1. Every region doesnt get the same amount of sunlight as the rest due to whether or location an example would be that a region with alot of rain could have clouds that wouldnt let the solar panels to absorb as much sunlight as a more dry and sunny place 
2 wind farms can be used to store energy for a power outage and a way to lower the cost of electricity to a farmer 
3 using hydro energy requires people to build a dam that pours the water over a mill that rotates and stores energy from it 
4 a type of waste created by nuclear power plants would be daily uses that have radiation such as plastic containers ,gloves , disposable overalls, boots or just plain radioactive waste.
5 would be the total mass of organisms in a given area or volume 
6 is a process to further limit carbon dioxide emissions from burning coal
7 is basically the means to tap into energy savings that over time become an asset 
8 turning down the water heater thermostat and turning off lights when not in use can save energy 
9 smart grids use timing grid to determine how long you use electricity for and for how much you used
6 0
3 years ago
Read 2 more answers
oe, a user, receives an email from a popular video streaming website. the email urges him to renew his membership. the message a
ale4655 [162]

Where Joe, a user, receives an email from a popular video-streaming website and the email urges him to renew his membership. If the message appears official, but Joe has never had a membership before, and if when Joe looks closer, he discovers that a hyperlink in the email points to a suspicious URL, note that the security threat that this describes is: "Phishing" (Option B)

<h3>What is Phishing?</h3>

Phishing is a sort of social engineering in which an attacker sends a fake communication in order to fool a person into disclosing sensitive data to the perpetrator or to install harmful software, such as ransomware, on the victim's infrastructure.

To avoid phishing attacks, make sure you:

  • understand what a phishing scheme looks like
  • Please do not click on that link.
  • Get anti-phishing add-ons for free.
  • Don't provide your information to an untrusted website.
  • Regularly change passwords.
  • Don't disregard those updates.
  • Set up firewalls.
  • Don't give in to those pop-ups.

Learn more about Phishing:
brainly.com/question/23021587
#SPJ1

Full Question:

Joe, a user, receives an email from a popular video streaming website. The email urges him to renew his membership. The message appears official, but Joe has never had a membership before. When Joe looks closer, he discovers that a hyperlink in the email points to a suspicious URL.

Which of the following security threats does this describe?

  • Trojan
  • Phishing
  • Man-in-the-middle
  • Zero-day attack
5 0
2 years ago
Tricia is managing tasks that have been assigned to her. She needs to enter mileage information in relation to a
Lady bird [3.3K]

Answer:

Task

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Ipv6 includes a native information security framework (ipsec) that provides both data and control packets. true false
    15·1 answer
  • What is a different paragph formatting tools
    6·1 answer
  • Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the
    5·1 answer
  • I have to writea piece of code to calculate the factorial of somewhat large numbers so the long long type won't suffize, so usin
    7·1 answer
  • What is virtual office?
    11·1 answer
  • What would be the best thing you could do to prepare yourself to work for a company that has embraced globalization. A) learn ho
    12·2 answers
  • What is subscriber billing in Google Play and where does the money go?
    5·1 answer
  • Match the data types to the types of value they are: Currency, Text, Date/time, and Name.
    11·1 answer
  • The Zoom feature allows you to either increase or decrease the size of your document on the screen,
    6·1 answer
  • What is the introduction of an algorithm and programming and how does it work?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!