Record.java
public class Record {
private String firstName, lastName, dateOfBirth, SSN, role;
private double salary;
private String zip, phone;
public Record(String firstName, String lastName, String
dateOfBirth, String SSN, String role,
double salary, String zip, String phone)
{
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
this.SSN = SSN;
this.role = role;
this.salary = salary;
this.zip = zip;
this.phone = phone;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getDateOfBirth() {
return dateOfBirth;
}
public String getSSN() {
return SSN;
}
public String getRole() {
return role;
}
public double getSalary() {
return salary;
}
public String getZip() {
return zip;
}
public String getPhone() {
return phone;
}
}
American_Health_Tech_Assessment.java (Main class)
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class American_Health_Tech_Assessment {
private static final String FILENAME = "data.csv";
public static void main(String[]args)
{
File file = new File(FILENAME);
ArrayList<Record> records = new ArrayList<>();
Scanner fileReader;
try
{
fileReader = new Scanner(file);
fileReader.nextLine(); // ignore the first line(column header) in
the file
while(fileReader.hasNextLine())
{
String[] data = fileReader.nextLine().split(",");
String firstName = data[0];
String lastName = data[1];
String dob = data[2];
String ssn = data[3];
String role = data[4];
double salary = Double.parseDouble(data[5]);
String zip = data[6];
String phone = data[7];
Record record = new Record(firstName, lastName, dob, ssn, role,
salary, zip, phone);
records.add(record);
}
fileReader.close();
// get all the roles(unique) from the records
ArrayList<String> roles = new ArrayList<>();
for(Record rec : records)
{
if(!roles.contains(rec.getRole()))
roles.add(rec.getRole());
}
// now display the average salary for all the roles
System.out.println("*** AVERAGE SALARY FOR ALL ROLES
***\n------------------------------------");
for(String role : roles)
{
calculateAverageSalaryBasedOnRole(role, records);
}
// calculate average salary based on parts of a given zip
String userAskedZip = "35";
System.out.println("*** AVERAGE SALARY FOR ALL ZIP STARTING WITH "
+ userAskedZip
+ "
***\n---------------------------------------------------");
calculateAverageSalaryBasedOnZip(userAskedZip, records);
}catch(FileNotFoundException fnfe){
System.out.println("File not found: " + FILENAME);
}
}
public static void calculateAverageSalaryBasedOnRole(String role,
ArrayList<Record> records)
{
double totalSalary = 0;
int count = 0;
for(Record rec : records)
{
if(rec.getRole().equals(role))
{
totalSalary += rec.getSalary();
count++;
}
}
double average = (totalSalary / count);
System.out.println("Number of records having " + role + " as role
is = " + count
+ "\nTheir average salary is = $" + String.format("%.2f", average)
+ "\n");
}
public static void calculateAverageSalaryBasedOnZip(String zip,
ArrayList<Record> records)
{
double totalSalary = 0;
int count = 0;
for(Record rec : records)
{
if(rec.getZip().substring(0, 2).equals(zip))
{
totalSalary += rec.getSalary();
count++;
}
}
double average = (totalSalary / count);
System.out.println("Number of records having zip starting with " +
zip + " is = " + count
+ "\nTheir average salary is = $" + String.format("%.2f", average)
+ "\n");
}
}
***************************************************************** SCREENSHOT **********************************************************
Reading and parsing a CSV file in Java NOTE: a.) The first row contains the field...
Reading and parsing a CSV data file in java Note: I.) the first row contains the field definition II.) Columns are separated by comma This is the data.csv file These are the instructions This is my code so far A D F G H J K 1 FirstName LastName DateOfBirth SSN Role Salary Zip Phone 2 Radioactive Man BMockingbird 4Captain Triumph 5 Deathstroke, th Chief garlic 9/29/1912 846330158 Administration 39157 7166875260 69989 persimmon 9/22/1956 835340509 Administration 13884 39157 1421813391 usb...
Reading and parsing a CSV data file in java Note: I.) the first row contains the field definition II.) Columns are separated by comma This is the data.csv file These are the instructions This is my code so far A D F G H J K 1 FirstName LastName DateOfBirth SSN Role Salary Zip Phone 2 Radioactive Man BMockingbird 4Captain Triumph 5 Deathstroke, th Chief garlic 9/29/1912 846330158 Administration 39157 7166875260 69989 persimmon 9/22/1956 835340509 Administration 13884 39157 1421813391 usb...
Question 2 If you read in a csv file using read.csv() function into R, what is the resulting datastructure in which R stores the read-in data? A. numeric B. matrix C. data.frame D. vector Question 3 Suppose you have 4 integers, 4 characters, and 4 logical values. Which datastructure can you use to store all 12 values? Choose one or more options. A. a vector B. a matrix C. a list D. a data frame Question 4 Suppose you have...
Write a program that will accept from the user a text file containing hurricane data along with an output filename. The data consists of the year, the number of storms, the number of hurricanes, and the damage in millions of US Dollars. The first line contains the word “Years” followed by the first year listed and the last year listed separated by tabs. The following lines contain the data separated by tabs. A sample text file is available in this...
Sample of CSV file tweet tweet_id airline_sentiment airline 567591480085463000 negative United 567588278875213000 neutral Delta 567590027375702000 negative Delta 5 567592368451248000 negative United 6 567594449874587000 negative Southwest United United United @united yes. We waited in line for almost an hour to do so. Some passengers just left not wanting to wait past 1am. @JetBlue's new CEO seeks the right balance to please passengers and Wall ... - Greenfield Daily Reporter http://t.co/LM3opxkxch @JetBlue is REALLY getting on my nerves !! YOY#nothappy @united the...
The file containing the JAVA files, pseudocode file and doc file that have written for this lab. Preamble The file releasedates.txt contains a list of video games and their release dates. Each line of the file contains the release date, a tab character, and then the name. The list is currently totally unsorted. The object of today's lab is to write a series of methods that allow us to perform the following tasks: read contents from a file and store...
1.b) Create a Java application Lab3Part1b. Make sure you create a NEW project with the specific name just given. You need to make sure the projects you create and submit have the correct names and the name of the file and name of the class are the same. The names are case sensitive. In this new project, set up your program to read in the data from the file SciFiDataBMTClean.txt using a Scanner. {file/Scanner setup 2 points} Declare the variables...
Q2. Retrieve the names of all employees from the employee table to produce output on CSV format or delimited format with a common delimeter, rather than separete columns. Hint:Put the whole row into a string with a semicolon as the seperator(delimeter) between thecolumns: FORMAT:(fname;minit;lname) Example: EMPLOYEES -------------- James;E;Borg Frank;T;Wong Q3. Write a query to show the employees name from the employee table in this format: first letter of the first name, followed by a dot, a blank, and the full...
Excel file Homework1 - invoices.xlsx contains data about invoices of a reseller of office equipment that ships its products to customers in several countries. The tables in the workbook refer to data collected from different systems within the company. a) Copy worksheet “InvoiceHeader” into a new worksheet. For each invoice in the new worksheet, show the matching information from the other tables: Invoice date, Invoice Number, Customer ID, Customer Name, Country, Invoice Quantity, Unit Cost, Unit Price. b) In the...
Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date. You will make some modific ation to the Date class so that it mccts the folowing specific ations: The Date class consists of three private member variables: Member Variable year month day Description An int variable that hokls the value of a year. An int variable that hokds the value of a month An int variable that hokis the value of a day. The...