Question
DataPoint class public class DataPoint { // The number and races represented in this data point. DO NOT CHANGE. public int numRaces = 8; private
DataPoint class
public class DataPoint { // The number and races represented in this data point. DO NOT CHANGE. public int numRaces = 8; private String[] races = {"White", "Black", "LatinX", "Asian", "AIAN", "NHPI", "Multiracial", "Other"};
// TODO: Add private member variables here. private String date; private String state; private int totalCases; private int[] casesByRace;
// TODO: Add comment and implement public DataPoint(String dateIn, String stateIn, int totalCasesIn, int[] casesByRaceIn) { // TODO date = dateIn; state = stateIn; totalCases = totalCasesIn; casesByRace = casesByRaceIn; }
// TODO: Add comment and implement. public String getDate() { // TODO: change the line below return date; }
// TODO: Add comment and implement. public String getState() { // TODO: change the line below return state; }
// TODO: Add comment and implement. public int getCasesByRace(int raceIndex) { // TODO: Change the line below and add more code. return casesByRace[raceIndex]; }
// TODO: Add comment and implement. public int getTotalCases() { // TODO: Change the line below return totalCases; }
/** * Return the race name associated with the given index in this data point. * Preconditions: index is between 0 (inclusive) and numRaces (8) (exclusive) * * DO NOT CHANGE. * * @param index The index of the race. * @return The name of the race (e.g. "White" or "LatinX") */ public String getRaceName(int index) { return this.races[index]; } }
Please do a java class:
In CovidCalculator.java you will be calculating different statistics about the dataset. You will be writing a total of 4 methods and can write additional methods for star points.
You are provided a mostly empty CovidCalculator class in the file CovidCalculator.java. Complete or add the methods specified below. For examples of how these methods should work, see the
Methods to be implemented
public CovidCalculator(DataPoint[] input)
The constructor should initialize the member variable (the array of DataPoints) that statistics will be calculated for. Note: it is better style if this constructor should copy the data in inputData into the existing array (which is created when points is declared) referenced by points. It should NOT contain the following line:
this.points = inputData // THIS IS WRONG
Instead it should use a loop to copy the data from inputData to points.
public double findAverageCases(String date)
Return the average number of total cases/infections on the given date across all states as a double. Be careful to cast ints to doubles when taking the average or your average will not be correct. This reading was not assigned because we assume you know it from a previous course, but you can reference it for review.
public String findRaceWithHighestCases(String date, String state)
Return the String representing the name of the race that has the highest number of infections on the given date in the given state.
public [retType] myStat([args])
This method is up to you. You will implement one more method that calculates a statistic of your choice. Your method can return any type that you like (but not void) and it can take any number and type of parameters (including none at all). The only requirements are that this method contain at least a loop and an if-statement, and that it uses both of these structures meaningfully in calculating the statistic. The comment for this method must clearly describe what it calculates. We will not autograde this method. It will be up to you to demonstrate its functionality (see below).
Here are some ideas of what you might calculate:
- The number of distinct states that have a total number of cases on a given data above some threshold.
- The state with the biggest average difference between two given races across all dates.
- The state with the fewest total cases in the data
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started