Project update: Add many functions
This commit is contained in:
parent
ed696f9493
commit
c67a36732d
@ -1,14 +1,161 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.io.FileInputStream;
|
||||
//time 11:10 - 11:22
|
||||
|
||||
|
||||
public class CovidDatabase {
|
||||
private ArrayList<CovidEntry> list;
|
||||
private static final int SAFE = 5;
|
||||
|
||||
|
||||
public CovidDatabase(){
|
||||
list = new ArrayList<CovidEntry>();
|
||||
}
|
||||
|
||||
public ArrayList <CovidEntry> safeToOpen(String st){
|
||||
ArrayList<CovidEntry> result = null;
|
||||
ArrayList<CovidEntry> temp = new ArrayList<CovidEntry>();
|
||||
int match = 0;
|
||||
int previousDailyInfections = -1;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getState().equalsIgnoreCase(st)) {
|
||||
if (previousDailyInfections != -1 && c.getDailyInfections() < previousDailyInfections) {
|
||||
match += 1;
|
||||
temp.add(c);
|
||||
} else {
|
||||
match = 0;
|
||||
temp.clear();
|
||||
}
|
||||
|
||||
previousDailyInfections = c.getDailyInfections();
|
||||
}
|
||||
if (match == 5) {
|
||||
result = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ArrayList <CovidEntry>
|
||||
listMinimumDailyInfections(int m, int d, int min){
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d && c.getDailyInfections() <= min){
|
||||
result.add(c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int countRecords(){
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public int getTotalDeaths(){
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
result += c.getDailyDeaths();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getTotalInfections(){
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
result += c.getDailyInfections();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int countTotalInfections(int m, int d){
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d){
|
||||
result += c.getDailyInfections();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int countTotalDeaths(int m, int d){
|
||||
int result = 0;
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d){
|
||||
result += c.getDailyDeaths();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ArrayList <CovidEntry> getDailyDeaths(int m, int d){
|
||||
ArrayList<CovidEntry> result = new ArrayList<CovidEntry>();
|
||||
|
||||
for (CovidEntry c: list){
|
||||
if (c.getMonth() == m && c.getDay() == d){
|
||||
result.add(c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//State
|
||||
public CovidEntry peakDailyDeaths(String st) {
|
||||
//iterate over our database
|
||||
//find highest deathcount that matches our state (st)
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
|
||||
for(CovidEntry c : list){
|
||||
if( c.getState().equalsIgnoreCase(st)){
|
||||
if( c.getDailyDeaths() > max){
|
||||
max = c.getDailyDeaths();
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//Month day
|
||||
public CovidEntry peakDailyDeaths(int m, int d) {
|
||||
//iterate over our database
|
||||
//find highest deathcount that matches our state (st)
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
|
||||
for(CovidEntry c : list){
|
||||
if( c.getDailyDeaths() > max){
|
||||
max = c.getDailyDeaths();
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public CovidEntry mostTotalDeaths(){
|
||||
CovidEntry result = null;
|
||||
int max = 0;
|
||||
|
||||
for(CovidEntry c : list){
|
||||
if( c.getTotalDeaths() > max){
|
||||
max = c.getTotalDeaths();
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void readCovidData(String filename){
|
||||
Scanner scnr = null;
|
||||
FileInputStream fs = null;
|
||||
@ -19,8 +166,8 @@ public class CovidDatabase {
|
||||
scnr.nextLine();
|
||||
while(scnr.hasNext()){
|
||||
String state = scnr.next();
|
||||
int day = scnr.nextInt();
|
||||
int month = scnr.nextInt();
|
||||
int day = scnr.nextInt();
|
||||
int di = scnr.nextInt();
|
||||
int dd = scnr.nextInt();
|
||||
int ti = scnr.nextInt();
|
||||
|
@ -1,7 +1,6 @@
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class CovidEntry {
|
||||
//time1 - 10:10 10:30
|
||||
|
||||
//Private vars
|
||||
private String state;
|
||||
|
@ -1,3 +1,9 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
//time 11:10 - 11:22
|
||||
//time 12:00
|
||||
//time1 - 10:10 10:30
|
||||
|
||||
public class CovidManager {
|
||||
public static void main( String[] args){
|
||||
CovidEntry covidObject =
|
||||
@ -11,7 +17,37 @@ public class CovidManager {
|
||||
|
||||
CovidDatabase db = new CovidDatabase();
|
||||
db.readCovidData("data/covid_data.csv");
|
||||
System.out.println("");
|
||||
System.out.println("highest daily d for texas");
|
||||
CovidEntry highestTX = db.peakDailyDeaths("TX");
|
||||
System.out.println(highestTX);
|
||||
|
||||
ArrayList<CovidEntry> may5th = db.getDailyDeaths(5, 5);
|
||||
System.out.println("May 5th Data");
|
||||
for (CovidEntry c: may5th){
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
int totalInfections = db.getTotalInfections();
|
||||
System.out.println("Total Infections " + totalInfections);
|
||||
|
||||
System.out.println("Total Records: " + db.countRecords());
|
||||
System.out.println("Total Deaths: " + db.getTotalDeaths());
|
||||
System.out.println("Total Deaths for May 5th: " + db.countTotalDeaths(5, 5));
|
||||
System.out.println("Peak deaths for May 5th: " + db.peakDailyDeaths(5, 5));
|
||||
System.out.println("Most total deaths: " + db.mostTotalDeaths() + " Total: " +
|
||||
db.mostTotalDeaths().getTotalDeaths());
|
||||
System.out.println("States with less than 300 infections on may 5th: ");
|
||||
may5th = db.listMinimumDailyInfections(5, 5, 300);
|
||||
for (CovidEntry c: may5th){
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
System.out.println("MI safe to open: ");
|
||||
ArrayList<CovidEntry> MISafe = db.safeToOpen("MI");
|
||||
for (CovidEntry c: MISafe){
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
10347
java/final-project/covid_data.csv
Normal file
10347
java/final-project/covid_data.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user