Untitled
unknown
java
a year ago
1.7 kB
2
Indexable
Never
import java.util.Scanner; public class NarcosisCalculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the gender (M/F): "); char gender = scanner.next().charAt(0); System.out.print("Enter the duration of the surgery in hours: "); double durationInHours = Double.parseDouble(scanner.next()); int durationInMinutes = (int) (durationInHours * 60); Narcosis(gender, durationInMinutes); scanner.close(); } public static void Narcosis(char gender, int durationInMinutes) { double narcosisLevel = 100.0; int dosage = 1; int time = 0; while (narcosisLevel > 30) { double effectiveness = gender == 'M' ? 97.2 : 97.4; System.out.printf("Minute: %d Effectiveness: %.1f Dose: %d%n", time, narcosisLevel, dosage); narcosisLevel *= effectiveness / 100; time += 1; if (narcosisLevel <= 30 && time < durationInMinutes) { dosage++; narcosisLevel = 100.0; } if (time >= durationInMinutes) { System.out.println("The duration of the surgery is over."); break; } } if (narcosisLevel <= 30) { double effectiveness = gender == 'M' ? 97.2 : 97.4; System.out.printf("Minute: %d Effectiveness: %.1f Dose: %d%n", time, narcosisLevel, dosage); System.out.println("The patient is at risk of awakening."); } else { System.out.println("The surgery is completed without risk."); } } }