import java.util.Scanner;
public class LongDistanceCallCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean repeat = true;
while (repeat) {
System.out.println("Enter the day of the week (Mo, Tu, We, Th, Fr, Sa, Su):");
String day = scanner.next().trim().toUpperCase();
System.out.println("Enter the time the call started (HH:MM):");
String time = scanner.next();
String[] timeParts = time.split(":");
int hour = Integer.parseInt(timeParts[0]);
System.out.println("Enter the length of the call in minutes:");
int minutes = scanner.nextInt();
double cost = calculateCost(day, hour, minutes);
System.out.printf("The cost of the call is: $%.2f%n", cost);
System.out.println("Do you want to repeat the calculation? (yes/no)");
String response = scanner.next().trim().toLowerCase();
repeat = response.equals("yes");
}
scanner.close();
}
private static double calculateCost(String day, int hour, int minutes) {
double rate = 0.0;
if (isWeekday(day) && isBusinessHour(hour)) {
rate = 0.40;
} else if (isWeekday(day) && !isBusinessHour(hour)) {
rate = 0.25;
} else if (isWeekend(day)) {
rate = 0.15;
}
return rate * minutes;
}
private static boolean isWeekday(String day) {
return day.equals("MO") || day.equals("TU") || day.equals("WE") || day.equals("TH") || day.equals("FR");
}
private static boolean isBusinessHour(int hour) {
return hour >= 8 && hour < 18;
}
private static boolean isWeekend(String day) {
return day.equals("SA") || day.equals("SU");
}
}