From 4a3e9539d9442390262994204ac8705d542e9a16 Mon Sep 17 00:00:00 2001 From: vivek-kumar-2024 Date: Sun, 8 Jun 2025 22:37:41 +0000 Subject: [PATCH] create RadiationController.java --- RadiationController.java | 37 +++++++++++++++++++++++++++++++++++++ RapidInvoker.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 RadiationController.java create mode 100644 RapidInvoker.java diff --git a/RadiationController.java b/RadiationController.java new file mode 100644 index 0000000..650aad7 --- /dev/null +++ b/RadiationController.java @@ -0,0 +1,37 @@ +public class RadiationController { + private boolean isXRayMode = false; + private boolean isElectronMode = false; + private int dose = 0; + + public void setXRayMode() { + isXRayMode = true; + isElectronMode = false; + } + + public void setElectronMode() { + isElectronMode = true; + isXRayMode = false; + } + + public void setDose(int dose) { + this.dose = dose; + } + + public void start() { + if (isXRayMode) { + deliverXRayDose(); + } else if (isElectronMode) { + deliverElectronDose(); + } + } + + private void deliverXRayDose() { + System.out.println("Delivering X-Ray dose: " + dose); + // ... deliver X-Ray dose + } + + private void deliverElectronDose() { + System.out.println("Delivering Electron dose: " + dose); + // ... deliver Electron dose + } +} \ No newline at end of file diff --git a/RapidInvoker.java b/RapidInvoker.java new file mode 100644 index 0000000..aa72051 --- /dev/null +++ b/RapidInvoker.java @@ -0,0 +1,28 @@ +public class RapidInvoker { + public static void main(String[] args) { + RadiationController controller = new RadiationController(); + + // Simulate rapid operator entry switching modes and doses + controller.setXRayMode(); + controller.setDose(100); + controller.setElectronMode(); + controller.setDose(200); + controller.start(); // Should deliver Electron, but due to race, could misbehave + + controller.setXRayMode(); + controller.setDose(150); + controller.start(); // Should deliver X-Ray + + // Repeat rapid switching + for (int i = 0; i < 10; i++) { + if (i % 2 == 0) { + controller.setXRayMode(); + controller.setDose(50 + i); + } else { + controller.setElectronMode(); + controller.setDose(100 + i); + } + controller.start(); + } + } +} \ No newline at end of file