I have been on this part for about 5 days and see no issue with the output. I have tried my code and others and am not certain what is going on for it to not pass.
It appears the output is correct, totaling up the day's revenue and displaying it in descending order.
public Map<String, Long> getAdPerDayMap() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
List<EventDataRow> dataRows = statisticsStorage.storage.get(EventType.VIDEOS_SELECTED);
Map<String, Long> revenueByDay = new TreeMap<>(Comparator.reverseOrder());
dataRows.forEach((dataRow -> {
dayOfTheMonth++;
String currDay = dateFormat.format(dataRow.getDate());
long amount = ((VideosSelectedEventDataRow) dataRow).getAmount();
revenueByDay.put(currDay, revenueByDay.getOrDefault(currDay, 0L) + amount);
}));
return revenueByDay;
}
public void printAdRevenue() {
Map<String, Long> adRevenuePerDay = StatisticsManager.getInstance().getAdPerDayMap();
adRevenuePerDay.forEach((key, value) -> {
totalRevenuePerDay += value;
ConsoleHelper.writeMessage(String.format(Locale.ENGLISH, "%s - %.2f", key, value / 100.0));
});
ConsoleHelper.writeMessage(String.format(Locale.ENGLISH, "Total - %.2f", totalRevenuePerDay / 100.0));
}
package com.codegym.task.task27.task2712;
import com.codegym.task.task27.task2712.statistics.StatisticsManager;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
public class Test {
private long totalAdRevenue = 0;
static public TreeMap<Date, Long> getDailyRevenues() {
TreeMap<Date, Long> dailyRevenues = new TreeMap<>(Comparator.reverseOrder());
dailyRevenues.put(new Date("Jul 12 12:23:07 EDT 2022"), 10l);
dailyRevenues.put(new Date("Jul 12 11:23:07 EDT 2022"), 100l);
dailyRevenues.put(new Date("Jul 12 10:23:07 EDT 2022"), 50l);
dailyRevenues.put(new Date("Jul 13 12:23:07 EDT 2022"), 5l);
dailyRevenues.put(new Date("Jul 13 11:23:07 EDT 2022"), 20l);
dailyRevenues.put(new Date("Jul 13 10:23:07 EDT 2022"), 30l);
dailyRevenues.put(new Date("Jul 14 12:23:07 EDT 2022"), 1000l);
dailyRevenues.put(new Date("Jul 14 11:23:07 EDT 2022"), 70l);
dailyRevenues.put(new Date("Jul 14 10:23:07 EDT 2022"), 15l);
return dailyRevenues;
}
public static void main(String[] args) {
// TreeMap<Date, Long> dailyRevenue = getDailyRevenues();
// double revenueAsDouble;
// double sumRevenue = 0;
// DateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
// for (Map.Entry<Date, Long> dateWithRevenue : dailyRevenue.entrySet()) {
// revenueAsDouble = ((double) dateWithRevenue.getValue()) / 100;
// sumRevenue += revenueAsDouble;
// System.out.println(df.format(dateWithRevenue.getKey()) + " - " + String.format("%.2f", revenueAsDouble));
// }
// System.out.println("Total - " + String.format("%.2f", sumRevenue));
// System.out.println();
System.out.printf(Locale.ENGLISH, "%.2f", 11000/100.0);
}
}