объясни, что здесь делает программа?
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Activity {
private final String name;
private final int quantity;
private final LocalDate date;
public Activity(String name, int quantity, LocalDate date) {
this.name = name;
this.quantity = quantity;
this.date = date;
}
public int calculateCalories() {
if (name.equals("steps")) {
return quantity / 1000 * 50;
} else if (name.equals("running")) {
return (int) (quantity * 75);
} else if (name.equals("strength training")) {
return quantity * 9;
}
return 0;
}
public String toString() {
return "Name: " + name + ", Quantity: " + quantity + ", Date: " + date;
}
}
public class ActivityTracker {
private final List
activities;
public ActivityTracker() {
activities = new ArrayList<>();
}
public void addActivity(String name, int quantity, LocalDate date) {
activities.add(new Activity(name, quantity, date));
}
public int getTotalCalories(LocalDate startDate, LocalDate endDate) {
int totalCalories = 0;
for (Activity activity : activities) {
LocalDate activityDate = activity.getDate();
if (activityDate.isAfter(startDate) || activityDate.isEqual(startDate)) {
if (activityDate.isBefore(endDate) || activityDate.isEqual(endDate)) {
totalCalories += activity.calculateCalories();
}
}
}
return totalCalories;
}
public void printActivities(LocalDate startDate, LocalDate endDate) {
for (Activity activity : activities) {
LocalDate activityDate = activity.getDate();
if (activityDate.isAfter(startDate) || activityDate.isEqual(startDate)) {
if (activityDate.isBefore(endDate) || activityDate.isEqual(endDate)) {
System.out.println(activity);
}
}
}
}
public static void main(String[] args) {
ActivityTracker tracker = new ActivityTracker();
Scanner scanner = new Scanner(System.in);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
while (true) {
System.out.println("Enter activity (steps / running / strength training): ");
String name = scanner.nextLine();
if (name.equals("exit")) {
break;
}
System.out.println("Enter quantity: ");
int quantity = Integer.parseInt(scanner.nextLine());
System.out.println("Enter date (yyyy-MM-dd): ");
LocalDate date = LocalDate.parse(scanner.nextLine(), formatter);
tracker.addActivity(name, quantity, date);
}
System.out.println("Enter start date (yyyy-MM-dd): ");
LocalDate startDate = LocalDate.parse(scanner.nextLine(), formatter);
System.out.println("Enter end date (yyyy-MM-dd): ");
LocalDate endDate = LocalDate.parse(scanner.nextLine(), formatter);
int totalCalories = tracker.getTotalCalories(startDate, endDate);
System.out.println("Total calories burned: " + totalCalories);
System.out.println("Activities during the specified period:");
tracker.printActivities(startDate, endDate);
scanner.close();
}
}