SlideShare a Scribd company logo
1 of 7
Download to read offline
For this lab, you will write the following files:
AbstractDataCalc
AverageDataCalc
MaximumDataCalc
MinimumDataCalc
MUST USE ALL 6 FILES PROVIDED
AbstractDataCalc is an abstract class, that AverageDataCalc, MaximumDataCalc and
MinimumDataCalc all inherit.
The following files are provided
CSVReader
To help read CSV Files.
DataSet
This file uses CSVReader to read the data into a List> type structure. Think of this as a Matrix
using ArrayLists. The important methods for you are rowCount() and getRow(int i) - Between
CSVReader and DataSet - all your data is loaded for you!
Main
This contains a public static void String[] args. You are very free to completely change this main
(and you should!). We don't test your main, but instead your methods directly. However, it will
give you an idea of how the following output is generated.
Sample Input / Output
Given the following CSV file
The output of the provided main is:
Note: the extra line between Set results is optional and not graded. All other spacing must be
exact!
Specifications
You will need to implement the following methods at a minimum. You are free to add additional
methods.
AbstractDataCalc
public AbstractDataCalc(DataSet set) - Your constructor that sets your dataset to an instance
variable, and runCalculations() based on the dataset if the passed in set is not null. (hint: call
setAndRun)
public void setAndRun(DataSet set) - sets the DataSet to an instance variable, and if the passed
in value is not null, runCalculations on that data
private void runCalculations() - as this is private, technically it is optional, but you are going to
want it (as compared to putting it all in setAndRun). This builds an array (or list) of doubles,
with an item for each row in the dataset. The item is the result returned from calcLine.
public String toString() - Override toString, so it generates the format seen above. Method is the
type returned from get type, row counting is the more human readable - starting at 1, instead of
0.
public abstract String getType() - see below
public abstract double calcLine(List line) - see below
AverageDataCalc
Extends AbstractDataCalc. Will implement the required constructor and abstract methods only.
public abstract String getType() - The type returned is "AVERAGE"
public abstract double calcLine(List line) - runs through all items in the line and returns the
average value (sum / count).
MaximumDataCalc
Extends AbstractDataCalc. Will implement the required constructor and abstract methods only.
public abstract String getType() - The type returned is "MAX"
public abstract double calcLine(List line) - runs through all items, returning the largest item in
the list.
MinimumDataCalc
Extends AbstractDataCalc. Will implement the required constructor and abstract methods only.
public abstract String getType() - The type returned is "MIN"
public abstract double calcLine(List line) - runs through all items, returning the smallest item in
the list.
MaximumDataCalc.java------ write code from scratch
Main.java
/*
* Copyright (c) 2020.
* This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike
4.0 International License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box
1866, Mountain View, CA 94042, USA.
*/
/**
* @author Albert Lionelle
* lionelle@colostate.edu
* Computer Science Department
* Colorado State University
* @version 20200624
*/
public class Main {
public static void main(String[] args) {
String testFile = "sample.csv";
DataSet set = new DataSet(testFile);
AverageDataCalc averages = new AverageDataCalc(set);
System.out.println(averages);
MinimumDataCalc minimum = new MinimumDataCalc(set);
System.out.println(minimum);
MaximumDataCalc max = new MaximumDataCalc(set);
System.out.println(max);
}
}
MinumumDataCalc.java------ write code from scratch
AverageDataCalc.java------ write code from scratch
AbstractDataCalc.java------ write code from scratch
import java.util.ArrayList;
import java.util.List;
/**
* A simple container that holds a set of Data, by row/col (matrix)
* @version 20200627
*/
public class DataSet {
private final List> data = new ArrayList<>();
/**
* Reads the file, assuming it is a CSV file
* @param fileName name of file
*/
public DataSet(String fileName) {
this(new CSVReader(fileName, false));
}
/**
* Takes in a CSVReader to load the dataset
* @param csvReader a csvReader
*/
public DataSet(CSVReader csvReader) {
loadData(csvReader);
}
/**
* Returns the number of rows in the data set
* @return number of rows
*/
public int rowCount() {
return data.size();
}
/**
* Gets a specific row based on the index. Throws exception if out of bounds
* @param i the index of the row
* @return the row as a List of doubles
*/
public List getRow(int i) {
return data.get(i);
}
/**
* Loads the data from th CSV file
* @param file a CSVReader
*/
private void loadData(CSVReader file) {
while(file.hasNext()) {
List dbl = convertToDouble(file.getNext());
if(dbl.size()> 0) {
data.add(dbl);
}
}
}
/**
* Converts a List of strings to a list of doubles. Ignores non-doubles in the list
* @param next a List of strings
* @return a List of doubles
*/
private List convertToDouble(List next) {
List dblList = new ArrayList<>(next.size());
for(String item : next) {
try {
dblList.add(Double.parseDouble(item));
}catch (NumberFormatException ex) {
System.err.println("Number format!");
}
}
return dblList;
}
/**
* Simple way to view the data
* @return a String of the
*/
@Override
public String toString() {
return data.toString();
}
}
CSVReader.java
/*
* Copyright (c) 2020.
* This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike
4.0 International License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box
1866, Mountain View, CA 94042, USA.
*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* This is a slightly more advanced CSV reader that can handle quoted tokens.
*/
public class CSVReader {
private static final char DELIMINATOR = ',';
private Scanner fileScanner;
/**
* Basic constructor that assumes the first line should be skipped.
* @param file name of file to read
*/
public CSVReader(String file) {
this(file, true);
}
/**
* A constructor that requires the name of the file to open
* @param file filename to read
* @param skipHeader true to skip header, false if it is to be read
*/
public CSVReader(String file, boolean skipHeader) {
try {
fileScanner = new Scanner(new File(file));
if(skipHeader) this.getNext();
}catch (IOException io) {
System.err.println(io.getMessage());
System.exit(1);
}
}
/**
* Reads a line (nextLine()) and splits it into a String array by the DELIMINATOR, if the line is
* empty it will also return null. This is the proper way to check for CSV files as compared
* to string.split - as it allows for "quoted" strings ,",",.
* @return a String List if a line exits or null if not
*/
public List getNext() {
if(hasNext()){
String toSplit = fileScanner.nextLine();
List result = new ArrayList<>();
int start = 0;
boolean inQuotes = false;
for (int current = 0; current < toSplit.length(); current++) {
if (toSplit.charAt(current) == '"') { // the char uses the '', but the " is a simple "
inQuotes = !inQuotes; // toggle state
}
boolean atLastChar = (current == toSplit.length() - 1);
if (atLastChar) {
result.add(toSplit.substring(start).replace(""", "")); // remove the quotes from the quoted item
} else {
if (toSplit.charAt(current) == DELIMINATOR && !inQuotes) {
result.add(toSplit.substring(start, current).replace(""", ""));
start = current + 1;
}
}
}
return result;
}
return null;
}
/**
* Checks to see if the fileScanner has more lines and returns the answer.
* @return true if the file scanner has more lines (hasNext())
*/
public boolean hasNext() {
return (fileScanner != null) && fileScanner.hasNext();
}
}

More Related Content

Similar to For this lab, you will write the following filesAbstractDataCalc.pdf

Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdfarshiartpalace
 
Spring data ii
Spring data iiSpring data ii
Spring data ii명철 강
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancementRakesh Madugula
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat SheetLaura Hughes
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbcphanleson
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptxcherryreddygannu
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programmingTim Essam
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfConint29
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfadmin463580
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docxwilcockiris
 

Similar to For this lab, you will write the following filesAbstractDataCalc.pdf (20)

Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
Spring data ii
Spring data iiSpring data ii
Spring data ii
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat Sheet
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Database programming
Database programmingDatabase programming
Database programming
 
Ado.net
Ado.netAdo.net
Ado.net
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
 

More from alokindustries1

Select the TRUE statement Group of answer choicesA. An arthropod�.pdf
Select the TRUE statement Group of answer choicesA. An arthropod�.pdfSelect the TRUE statement Group of answer choicesA. An arthropod�.pdf
Select the TRUE statement Group of answer choicesA. An arthropod�.pdfalokindustries1
 
Select one of the scenarios listed below and explain the best soluti.pdf
Select one of the scenarios listed below and explain the best soluti.pdfSelect one of the scenarios listed below and explain the best soluti.pdf
Select one of the scenarios listed below and explain the best soluti.pdfalokindustries1
 
Select the combination of the following statements relating to sourc.pdf
Select the combination of the following statements relating to sourc.pdfSelect the combination of the following statements relating to sourc.pdf
Select the combination of the following statements relating to sourc.pdfalokindustries1
 
select each of the following which relate to the term homozygous .pdf
select each of the following which relate to the term homozygous  .pdfselect each of the following which relate to the term homozygous  .pdf
select each of the following which relate to the term homozygous .pdfalokindustries1
 
Select the combination of the following statements regarding stakeho.pdf
Select the combination of the following statements regarding stakeho.pdfSelect the combination of the following statements regarding stakeho.pdf
Select the combination of the following statements regarding stakeho.pdfalokindustries1
 
select each of the following which relate to the term heterozygous.pdf
select each of the following which relate to the term heterozygous.pdfselect each of the following which relate to the term heterozygous.pdf
select each of the following which relate to the term heterozygous.pdfalokindustries1
 
Select all that are true regarding Economic Value Added (EVA) a) .pdf
Select all that are true regarding Economic Value Added (EVA) a) .pdfSelect all that are true regarding Economic Value Added (EVA) a) .pdf
Select all that are true regarding Economic Value Added (EVA) a) .pdfalokindustries1
 
Select the case that would most likely be filed under disparate impa.pdf
Select the case that would most likely be filed under disparate impa.pdfSelect the case that would most likely be filed under disparate impa.pdf
Select the case that would most likely be filed under disparate impa.pdfalokindustries1
 
Select all that are true about plasmid DNA.a.The DNA in plasmids.pdf
Select all that are true about plasmid DNA.a.The DNA in plasmids.pdfSelect all that are true about plasmid DNA.a.The DNA in plasmids.pdf
Select all that are true about plasmid DNA.a.The DNA in plasmids.pdfalokindustries1
 
Select a current event (local or international) that is relevant to .pdf
Select a current event (local or international) that is relevant to .pdfSelect a current event (local or international) that is relevant to .pdf
Select a current event (local or international) that is relevant to .pdfalokindustries1
 
Seleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdf
Seleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdfSeleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdf
Seleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdfalokindustries1
 
Seleccione todas las cualidades que pertenecen a los sistemas parlam.pdf
Seleccione todas las cualidades que pertenecen a los sistemas parlam.pdfSeleccione todas las cualidades que pertenecen a los sistemas parlam.pdf
Seleccione todas las cualidades que pertenecen a los sistemas parlam.pdfalokindustries1
 
Seleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdf
Seleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdfSeleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdf
Seleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdfalokindustries1
 
Seismic waves travel faster when the rock is less stiff.A) TrueB.pdf
Seismic waves travel faster when the rock is less stiff.A) TrueB.pdfSeismic waves travel faster when the rock is less stiff.A) TrueB.pdf
Seismic waves travel faster when the rock is less stiff.A) TrueB.pdfalokindustries1
 
Seg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdf
Seg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdfSeg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdf
Seg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdfalokindustries1
 
Seg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdf
Seg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdfSeg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdf
Seg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdfalokindustries1
 
Seg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdf
Seg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdfSeg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdf
Seg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdfalokindustries1
 
Seg�n el texto, �qu� es un factor Persona a la que se le da autori.pdf
Seg�n el texto, �qu� es un factor  Persona a la que se le da autori.pdfSeg�n el texto, �qu� es un factor  Persona a la que se le da autori.pdf
Seg�n el texto, �qu� es un factor Persona a la que se le da autori.pdfalokindustries1
 
Security X has an actual rate of return of 11.8 and a beta of 0.72..pdf
Security X has an actual rate of return of 11.8 and a beta of 0.72..pdfSecurity X has an actual rate of return of 11.8 and a beta of 0.72..pdf
Security X has an actual rate of return of 11.8 and a beta of 0.72..pdfalokindustries1
 
Seg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdf
Seg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdfSeg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdf
Seg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdfalokindustries1
 

More from alokindustries1 (20)

Select the TRUE statement Group of answer choicesA. An arthropod�.pdf
Select the TRUE statement Group of answer choicesA. An arthropod�.pdfSelect the TRUE statement Group of answer choicesA. An arthropod�.pdf
Select the TRUE statement Group of answer choicesA. An arthropod�.pdf
 
Select one of the scenarios listed below and explain the best soluti.pdf
Select one of the scenarios listed below and explain the best soluti.pdfSelect one of the scenarios listed below and explain the best soluti.pdf
Select one of the scenarios listed below and explain the best soluti.pdf
 
Select the combination of the following statements relating to sourc.pdf
Select the combination of the following statements relating to sourc.pdfSelect the combination of the following statements relating to sourc.pdf
Select the combination of the following statements relating to sourc.pdf
 
select each of the following which relate to the term homozygous .pdf
select each of the following which relate to the term homozygous  .pdfselect each of the following which relate to the term homozygous  .pdf
select each of the following which relate to the term homozygous .pdf
 
Select the combination of the following statements regarding stakeho.pdf
Select the combination of the following statements regarding stakeho.pdfSelect the combination of the following statements regarding stakeho.pdf
Select the combination of the following statements regarding stakeho.pdf
 
select each of the following which relate to the term heterozygous.pdf
select each of the following which relate to the term heterozygous.pdfselect each of the following which relate to the term heterozygous.pdf
select each of the following which relate to the term heterozygous.pdf
 
Select all that are true regarding Economic Value Added (EVA) a) .pdf
Select all that are true regarding Economic Value Added (EVA) a) .pdfSelect all that are true regarding Economic Value Added (EVA) a) .pdf
Select all that are true regarding Economic Value Added (EVA) a) .pdf
 
Select the case that would most likely be filed under disparate impa.pdf
Select the case that would most likely be filed under disparate impa.pdfSelect the case that would most likely be filed under disparate impa.pdf
Select the case that would most likely be filed under disparate impa.pdf
 
Select all that are true about plasmid DNA.a.The DNA in plasmids.pdf
Select all that are true about plasmid DNA.a.The DNA in plasmids.pdfSelect all that are true about plasmid DNA.a.The DNA in plasmids.pdf
Select all that are true about plasmid DNA.a.The DNA in plasmids.pdf
 
Select a current event (local or international) that is relevant to .pdf
Select a current event (local or international) that is relevant to .pdfSelect a current event (local or international) that is relevant to .pdf
Select a current event (local or international) that is relevant to .pdf
 
Seleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdf
Seleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdfSeleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdf
Seleccione SOLO UNO de los siguientes Objetivos de Desarrollo Sosten.pdf
 
Seleccione todas las cualidades que pertenecen a los sistemas parlam.pdf
Seleccione todas las cualidades que pertenecen a los sistemas parlam.pdfSeleccione todas las cualidades que pertenecen a los sistemas parlam.pdf
Seleccione todas las cualidades que pertenecen a los sistemas parlam.pdf
 
Seleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdf
Seleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdfSeleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdf
Seleccione la declaraci�n FALSA de las siguientes A. Trabajar con o.pdf
 
Seismic waves travel faster when the rock is less stiff.A) TrueB.pdf
Seismic waves travel faster when the rock is less stiff.A) TrueB.pdfSeismic waves travel faster when the rock is less stiff.A) TrueB.pdf
Seismic waves travel faster when the rock is less stiff.A) TrueB.pdf
 
Seg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdf
Seg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdfSeg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdf
Seg�n TCPS 2, �qu� es la investigaci�n de riesgo m�nimo (seleccione .pdf
 
Seg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdf
Seg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdfSeg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdf
Seg�n Juan Linz (1990), �c�mo los sistemas presidenciales crean disc.pdf
 
Seg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdf
Seg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdfSeg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdf
Seg�n Holton en la fuente 1, �cu�les fueron los motivos de los padre.pdf
 
Seg�n el texto, �qu� es un factor Persona a la que se le da autori.pdf
Seg�n el texto, �qu� es un factor  Persona a la que se le da autori.pdfSeg�n el texto, �qu� es un factor  Persona a la que se le da autori.pdf
Seg�n el texto, �qu� es un factor Persona a la que se le da autori.pdf
 
Security X has an actual rate of return of 11.8 and a beta of 0.72..pdf
Security X has an actual rate of return of 11.8 and a beta of 0.72..pdfSecurity X has an actual rate of return of 11.8 and a beta of 0.72..pdf
Security X has an actual rate of return of 11.8 and a beta of 0.72..pdf
 
Seg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdf
Seg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdfSeg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdf
Seg�n el C�digo y las Normas, �cu�l de las siguientes afirmaciones c.pdf
 

Recently uploaded

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

For this lab, you will write the following filesAbstractDataCalc.pdf

  • 1. For this lab, you will write the following files: AbstractDataCalc AverageDataCalc MaximumDataCalc MinimumDataCalc MUST USE ALL 6 FILES PROVIDED AbstractDataCalc is an abstract class, that AverageDataCalc, MaximumDataCalc and MinimumDataCalc all inherit. The following files are provided CSVReader To help read CSV Files. DataSet This file uses CSVReader to read the data into a List> type structure. Think of this as a Matrix using ArrayLists. The important methods for you are rowCount() and getRow(int i) - Between CSVReader and DataSet - all your data is loaded for you! Main This contains a public static void String[] args. You are very free to completely change this main (and you should!). We don't test your main, but instead your methods directly. However, it will give you an idea of how the following output is generated. Sample Input / Output Given the following CSV file The output of the provided main is: Note: the extra line between Set results is optional and not graded. All other spacing must be exact! Specifications You will need to implement the following methods at a minimum. You are free to add additional methods. AbstractDataCalc public AbstractDataCalc(DataSet set) - Your constructor that sets your dataset to an instance variable, and runCalculations() based on the dataset if the passed in set is not null. (hint: call setAndRun) public void setAndRun(DataSet set) - sets the DataSet to an instance variable, and if the passed in value is not null, runCalculations on that data private void runCalculations() - as this is private, technically it is optional, but you are going to want it (as compared to putting it all in setAndRun). This builds an array (or list) of doubles,
  • 2. with an item for each row in the dataset. The item is the result returned from calcLine. public String toString() - Override toString, so it generates the format seen above. Method is the type returned from get type, row counting is the more human readable - starting at 1, instead of 0. public abstract String getType() - see below public abstract double calcLine(List line) - see below AverageDataCalc Extends AbstractDataCalc. Will implement the required constructor and abstract methods only. public abstract String getType() - The type returned is "AVERAGE" public abstract double calcLine(List line) - runs through all items in the line and returns the average value (sum / count). MaximumDataCalc Extends AbstractDataCalc. Will implement the required constructor and abstract methods only. public abstract String getType() - The type returned is "MAX" public abstract double calcLine(List line) - runs through all items, returning the largest item in the list. MinimumDataCalc Extends AbstractDataCalc. Will implement the required constructor and abstract methods only. public abstract String getType() - The type returned is "MIN" public abstract double calcLine(List line) - runs through all items, returning the smallest item in the list. MaximumDataCalc.java------ write code from scratch Main.java /* * Copyright (c) 2020. * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. */ /** * @author Albert Lionelle * lionelle@colostate.edu
  • 3. * Computer Science Department * Colorado State University * @version 20200624 */ public class Main { public static void main(String[] args) { String testFile = "sample.csv"; DataSet set = new DataSet(testFile); AverageDataCalc averages = new AverageDataCalc(set); System.out.println(averages); MinimumDataCalc minimum = new MinimumDataCalc(set); System.out.println(minimum); MaximumDataCalc max = new MaximumDataCalc(set); System.out.println(max); } } MinumumDataCalc.java------ write code from scratch AverageDataCalc.java------ write code from scratch AbstractDataCalc.java------ write code from scratch import java.util.ArrayList; import java.util.List; /** * A simple container that holds a set of Data, by row/col (matrix) * @version 20200627 */ public class DataSet { private final List> data = new ArrayList<>(); /**
  • 4. * Reads the file, assuming it is a CSV file * @param fileName name of file */ public DataSet(String fileName) { this(new CSVReader(fileName, false)); } /** * Takes in a CSVReader to load the dataset * @param csvReader a csvReader */ public DataSet(CSVReader csvReader) { loadData(csvReader); } /** * Returns the number of rows in the data set * @return number of rows */ public int rowCount() { return data.size(); } /** * Gets a specific row based on the index. Throws exception if out of bounds * @param i the index of the row * @return the row as a List of doubles */ public List getRow(int i) { return data.get(i); } /** * Loads the data from th CSV file * @param file a CSVReader */ private void loadData(CSVReader file) { while(file.hasNext()) { List dbl = convertToDouble(file.getNext()); if(dbl.size()> 0) {
  • 5. data.add(dbl); } } } /** * Converts a List of strings to a list of doubles. Ignores non-doubles in the list * @param next a List of strings * @return a List of doubles */ private List convertToDouble(List next) { List dblList = new ArrayList<>(next.size()); for(String item : next) { try { dblList.add(Double.parseDouble(item)); }catch (NumberFormatException ex) { System.err.println("Number format!"); } } return dblList; } /** * Simple way to view the data * @return a String of the */ @Override public String toString() { return data.toString(); } } CSVReader.java /* * Copyright (c) 2020. * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box
  • 6. 1866, Mountain View, CA 94042, USA. */ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * This is a slightly more advanced CSV reader that can handle quoted tokens. */ public class CSVReader { private static final char DELIMINATOR = ','; private Scanner fileScanner; /** * Basic constructor that assumes the first line should be skipped. * @param file name of file to read */ public CSVReader(String file) { this(file, true); } /** * A constructor that requires the name of the file to open * @param file filename to read * @param skipHeader true to skip header, false if it is to be read */ public CSVReader(String file, boolean skipHeader) { try { fileScanner = new Scanner(new File(file)); if(skipHeader) this.getNext(); }catch (IOException io) { System.err.println(io.getMessage()); System.exit(1); } } /** * Reads a line (nextLine()) and splits it into a String array by the DELIMINATOR, if the line is
  • 7. * empty it will also return null. This is the proper way to check for CSV files as compared * to string.split - as it allows for "quoted" strings ,",",. * @return a String List if a line exits or null if not */ public List getNext() { if(hasNext()){ String toSplit = fileScanner.nextLine(); List result = new ArrayList<>(); int start = 0; boolean inQuotes = false; for (int current = 0; current < toSplit.length(); current++) { if (toSplit.charAt(current) == '"') { // the char uses the '', but the " is a simple " inQuotes = !inQuotes; // toggle state } boolean atLastChar = (current == toSplit.length() - 1); if (atLastChar) { result.add(toSplit.substring(start).replace(""", "")); // remove the quotes from the quoted item } else { if (toSplit.charAt(current) == DELIMINATOR && !inQuotes) { result.add(toSplit.substring(start, current).replace(""", "")); start = current + 1; } } } return result; } return null; } /** * Checks to see if the fileScanner has more lines and returns the answer. * @return true if the file scanner has more lines (hasNext()) */ public boolean hasNext() { return (fileScanner != null) && fileScanner.hasNext(); } }