diff --git a/HISTORY.md b/HISTORY.md index 7ac6c7c..368c5be 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ This file is a version history of jacotest amendments. Entries appear in versio | `Date` | `Version` | `Contents` | | :------------: | :---: | :--- | |||| +| 2024-12-06 | 3.4.30 | Fixed calculations in test case bohr-atom. | | 2024-12-04 | 3.4.29 | Updated test case jj-field-static to include more static variable types. | | 2024-12-03 | 3.4.28 | Updated test case jj-field-static. | | 2024-12-01 | 3.4.27 | Updated and renamed test case JACOBIN-0626-DumpObject-DumpStatics to jj-field-static. | diff --git a/VERSION.txt b/VERSION.txt index 8c88503..69f0fc4 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -v3.4.29 +v3.4.30 diff --git a/tests/bohr-atom/main.java b/tests/bohr-atom/main.java index 990209e..7d4f6e3 100644 --- a/tests/bohr-atom/main.java +++ b/tests/bohr-atom/main.java @@ -1,171 +1,176 @@ -import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; public class main { + // Constants + private static final double Ry = -2.18e-18; // J + private static final double c = 299792458; // m/s + private static final double h = 6.62607015e-34; // J*s + + // EMF Table using a List of Object arrays + private static final List EMF_TABLE = new ArrayList<>(); + + static { + EMF_TABLE.add(new Object[]{30e3, "Radio Very Low Frequency (VLF)"}); + EMF_TABLE.add(new Object[]{300e3, "Radio Low Frequency (LF)"}); + EMF_TABLE.add(new Object[]{3000e3, "Radio Medium Frequency (MF)"}); + EMF_TABLE.add(new Object[]{30e6, "Radio High Frequency (HF)"}); + EMF_TABLE.add(new Object[]{300e6, "Radio Very High Frequency (VHF)"}); + EMF_TABLE.add(new Object[]{1e9, "Radio Ultra High Frequency (UHF)"}); + EMF_TABLE.add(new Object[]{2e9, "Radio NASA Band L"}); + EMF_TABLE.add(new Object[]{4e9, "Radio NASA Band S"}); + EMF_TABLE.add(new Object[]{8e9, "Radio NASA Band C"}); + EMF_TABLE.add(new Object[]{12e9, "Radio NASA Band X"}); + EMF_TABLE.add(new Object[]{18e9, "Radio NASA Band Ku"}); + EMF_TABLE.add(new Object[]{27e9, "Radio NASA Band K"}); + EMF_TABLE.add(new Object[]{40e9, "Radio NASA Band Ka"}); + EMF_TABLE.add(new Object[]{75e9, "Radio NASA Band V"}); + EMF_TABLE.add(new Object[]{110e9, "Radio NASA Band W"}); + EMF_TABLE.add(new Object[]{300e9, "Radio Extremely High Frequency (EHF)"}); + EMF_TABLE.add(new Object[]{4e14, "Infrared (IR)"}); + EMF_TABLE.add(new Object[]{450e12, "Visible Red"}); + EMF_TABLE.add(new Object[]{508e12, "Visible Orange"}); + EMF_TABLE.add(new Object[]{540e12, "Visible Yellow"}); + EMF_TABLE.add(new Object[]{597e12, "Visible Green"}); + EMF_TABLE.add(new Object[]{610e12, "Visible Cyan"}); + EMF_TABLE.add(new Object[]{666e12, "Visible Blue"}); + EMF_TABLE.add(new Object[]{689e12, "Visible Indigo"}); + EMF_TABLE.add(new Object[]{750e12, "Visible Violet"}); + EMF_TABLE.add(new Object[]{3e16, "Ultraviolet (UV)"}); + EMF_TABLE.add(new Object[]{1e19, "X-ray"}); + EMF_TABLE.add(new Object[]{1e21, "Gamma ray"}); + } - private static final double RH = -2.18e-18; // RHdberg constant (J) - private static final double c = 299792458.0; // Speed of light (m/s) - private static final double h = 6.62607015e-34; // Planck's constant (J*s) + private static double deltaE(int ni, int nf) { + return Ry * (1.0 / (ni * ni) - 1.0 / (nf * nf)); + } - // Define a class to represent an entry in the EMF table - static class EMFEntry { - double frequency; - String description; + private static long newNf(int ni, double energy) { + double denom = (1.0 / (ni * ni)) - (energy / Ry); + return Math.round(ni * Math.sqrt(1.0 / denom)); + } - EMFEntry(double frequency, String description) { - this.frequency = frequency; - this.description = description; + private static String getSeries(int ni, int nf, double energy) { + // Validate input + if (ni == nf || ni < 1 || nf < 1) { + return "Invalid transition: ni and nf must be different, and both must be >= 1"; } - } - // Create an array of EMFEntry objects - private static final EMFEntry[] EMF_TABLE = { - new EMFEntry(30e3, "Radio Very Low Frequency (VLF)"), - new EMFEntry(300e3, "Radio Low Frequency (LF)"), - new EMFEntry(3000e3, "Radio Medium Frequency (MF)"), - new EMFEntry(30e6, "Radio High Frequency (HF)"), - new EMFEntry(300e6, "Radio Very High Frequency (VHF)"), - new EMFEntry(1e9, "Radio Ultra High Frequency (UHF)"), - new EMFEntry(2e9, "Radio NASA Band L"), - new EMFEntry(4e9, "Radio NASA Band S"), - new EMFEntry(8e9, "Radio NASA Band C"), - new EMFEntry(12e9, "Radio NASA Band X"), - new EMFEntry(18e9, "Radio NASA Band Ku"), - new EMFEntry(27e9, "Radio NASA Band K"), - new EMFEntry(40e9, "Radio NASA Band Ka"), - new EMFEntry(75e9, "Radio NASA Band V"), - new EMFEntry(110e9, "Radio NASA Band W"), - new EMFEntry(300e9, "Radio Extremely High Frequency (EHF)"), - new EMFEntry(4e14, "Infrared (IR)"), - new EMFEntry(450e12, "Visible Red"), - new EMFEntry(508e12, "Visible Orange"), - new EMFEntry(540e12, "Visible Yellow"), - new EMFEntry(597e12, "Visible Green"), - new EMFEntry(610e12, "Visible Cyan"), - new EMFEntry(666e12, "Visible Blue"), - new EMFEntry(689e12, "Visible Indigo"), - new EMFEntry(750e12, "Visible Violet"), - new EMFEntry(3e16, "Ultraviolet (UV)"), - new EMFEntry(1e19, "X-ray"), - new EMFEntry(1e21, "Gamma ray") - }; - - public static double deltaE(int ni, int nf) { - return RH * (1.0 / (nf * nf) - 1.0 / (ni * ni)); - } + // Determine the hydrogen series based on nf + String seriesName = ""; + String transitionType = ""; - public static String getSeries(int nf) { - return switch (nf) { - case 1 -> "Liman (UV)"; - case 2 -> "Balmer (vis)"; - case 3 -> "Paschen (IR)"; - case 4 -> "Bracket (Far IR)"; - case 5 -> "Pfund (IR)"; - case 6 -> "Humphreys (IR)"; - default -> "nf>6 (IR)"; - }; - } + if (ni > nf) { + // Emission: electron falls from ni to nf + transitionType = "Emission"; + } else { + // Absorption: electron is excited from ni to nf + transitionType = "Absorption"; + } - // ninf2info: - // Input: - // * ni = initial electron shell level - // * nf = final electron shell level - // Return 4 strings: - // * EMR subset name - // * Wavelength in String format - // * Change in energy in String format - // * Series name - public static String[] ninf2info(int ni, int nf) { - double E = deltaE(ni, nf); - String ser = E < 0 ? getSeries(nf) : "n/a"; - double freq = Math.abs(E) / h; - double wavelength = c * 1e9 / freq; - - for (EMFEntry entry : EMF_TABLE) { - if (freq < entry.frequency) { - return new String[]{entry.description, String.format("%.1f", wavelength), String.format("%.5e", E), ser}; - } + // Determine series based on nf + switch (nf) { + case 1: + seriesName = "Lyman (UV)"; + break; + case 2: + seriesName = "Balmer (Visible)"; + break; + case 3: + seriesName = "Paschen (IR)"; + break; + case 4: + seriesName = "Brackett (Far IR)"; + break; + case 5: + seriesName = "Pfund (Far IR)"; + break; + case 6: + seriesName = "Humphreys (Far IR)"; + break; + default: + seriesName = "Unknown Series (nf > 6)"; } - return new String[]{"Gamma", String.format("%.1f", wavelength), String.format("%.5e", E), getSeries(nf)}; - } - public static double newNf(int ni, double energy) { - return ni * Math.sqrt(RH / (energy * ni * ni + RH)); + // Return the series and transition type + return String.format("%s (%s Transition)", seriesName, transitionType); } - public static void p1() { - int ni = 4; - int nf = 2; - double E = deltaE(ni, nf); - System.out.printf("1. Energy (J): %e\n", E); - double freq = Math.abs(E) / h; - System.out.printf("Frequency (Hz): %.3e\n", freq); - double wavelength = c / freq; - System.out.printf("Wavelength (nm): %.1f\n\n", wavelength * 1e9); + private static Object[] ninf2info(int ni, int nf) { + double E = deltaE(ni, nf); // Energy in J + String series = getSeries(ni, nf, E); + double freq = Math.abs(E) / h; // Frequency in Hz + double wavelength = c * 1e9 / freq; // Wavelength in nm + + for (Object[] row : EMF_TABLE) { + double rowFreq = (double) row[0]; + String rowDesc = (String) row[1]; + if (freq < rowFreq) { + return new Object[] {rowDesc, wavelength, E, series}; + } + } + return new Object[] {"Gamma", wavelength, E, series}; } - public static void p2() { - double wavelength = 1283.45 / 1e9; - int ni = 3; - double freq = c / wavelength; - System.out.printf("2. Frequency (Hz): %.3e\n", freq); - double E = freq * h; - System.out.printf("Energy (J): %e\n", E); - double nf = newNf(ni, E); - System.out.printf("nf: %f\n", nf); + private static void p1() { + System.out.println("\n1. Given ni=4 and nf=2, calculate E gained by the emitted photon, F, and Lambda. Blue light emission."); + int ni = 4, nf = 2; + double E = deltaE(ni, nf); // Energy in J + System.out.println("\tE: " + E); + double freq = Math.abs(E) / h; // Frequency in Hz + System.out.printf("\tF: %.3e\n", freq); + double lambdaNm = (c / freq) * 1e9; // Wavelength in nm + System.out.printf("\tLambda: %.1f\n", lambdaNm); } - public static void p3() { - System.out.printf("A. %e\n", deltaE(2, 5)); - System.out.printf("B. %e\n", deltaE(6, 4)); - System.out.printf("C. %e\n", deltaE(1, 7)); - System.out.printf("D. %e\n", deltaE(3, 1)); - System.out.printf("E. %e\n", deltaE(7, 2)); + private static void p2() { + System.out.println("\n2. Calculate the electron energy difference between ni and nf. Electron absorption: photon E < 0, emission: E > 0."); + System.out.println("\t1 to 7 (E loss): " + deltaE(1, 7)); + System.out.println("\t2 to 5 (E loss): " + deltaE(2, 5)); + System.out.println("\t3 to 1 (E gain): " + deltaE(3, 1)); + System.out.println("\t6 to 4 (E gain): " + deltaE(6, 4)); + System.out.println("\t7 to 2 (E gain): " + deltaE(7, 2)); } - public static void p4() { - System.out.printf("A. %s\n", Arrays.toString(ninf2info(5, 3))); - System.out.printf("B. %s\n", Arrays.toString(ninf2info(5, 1))); - System.out.printf("C. %s\n", Arrays.toString(ninf2info(4, 2))); - System.out.printf("D. %s\n", Arrays.toString(ninf2info(6, 4))); - System.out.printf("E. %s\n", Arrays.toString(ninf2info(7, 5))); - System.out.printf("8 to 6. %s\n", Arrays.toString(ninf2info(8, 6))); - System.out.printf("11 to 6. %s\n", Arrays.toString(ninf2info(11, 6))); - System.out.printf("8 to 7. %s\n", Arrays.toString(ninf2info(8, 7))); - System.out.printf("11 to 7. %s\n", Arrays.toString(ninf2info(11, 7))); - System.out.printf("11 to 10. %s\n", Arrays.toString(ninf2info(11, 10))); - } - - private static void prtNinf2Info(String fmt1, String fmt2, String[] strArray) { - String fmt = fmt1.concat(fmt2); - System.out.printf(fmt, strArray[0], strArray[1], strArray[2], strArray[3]); + private static void p3() { + System.out.println("\n3. Photon emission info after electron collision (band, Lambda, E, series:"); + System.out.println("\t5 to 3: " + String.join(", ", toStringArray(ninf2info(5, 3)))); + System.out.println("\t5 to 1: " + String.join(", ", toStringArray(ninf2info(5, 1)))); + System.out.println("\t4 to 2: " + String.join(", ", toStringArray(ninf2info(4, 2)))); + System.out.println("\t6 to 4: " + String.join(", ", toStringArray(ninf2info(6, 4)))); + System.out.println("\t7 to 5: " + String.join(", ", toStringArray(ninf2info(7, 5)))); + System.out.println("\t7 to 1: " + String.join(", ", toStringArray(ninf2info(7, 1)))); } - public static void p5() { - String fmt = "%s, wl=%snm, E=%sJ, Series=%s\n"; - prtNinf2Info("3 >> 2: ", fmt, ninf2info(3, 2)); - prtNinf2Info("4 >> 2: ", fmt, ninf2info(4, 2)); - prtNinf2Info("5 >> 2: ", fmt, ninf2info(5, 2)); - prtNinf2Info("6 >> 2: ", fmt, ninf2info(6, 2)); - prtNinf2Info("2 >> 3: ", fmt, ninf2info(2, 3)); - prtNinf2Info("2 >> 4: ", fmt, ninf2info(2, 4)); - prtNinf2Info("2 >> 5: ", fmt, ninf2info(2, 5)); - prtNinf2Info("2 >> 6: ", fmt, ninf2info(2, 6)); + private static void p4() { + System.out.println("\n4. Photon absorption info after electron collision (band, Lambda, E, series:"); + System.out.println("\t3 to 5: " + String.join(", ", toStringArray(ninf2info(3, 5)))); + System.out.println("\t1 to 5: " + String.join(", ", toStringArray(ninf2info(1, 5)))); + System.out.println("\t2 to 4: " + String.join(", ", toStringArray(ninf2info(2, 4)))); + System.out.println("\t4 to 6: " + String.join(", ", toStringArray(ninf2info(4, 6)))); + System.out.println("\t5 to 7: " + String.join(", ", toStringArray(ninf2info(5, 7)))); + System.out.println("\t1 to 7: " + String.join(", ", toStringArray(ninf2info(1, 7)))); } - - public static void p6() { - String fmt = "%s, wl=%snm, E=%sJ, Series=%s\n"; - prtNinf2Info("4 >> 3: ", fmt, ninf2info(4, 3)); - prtNinf2Info("5 >> 3: ", fmt, ninf2info(5, 3)); - prtNinf2Info("6 >> 3: ", fmt, ninf2info(6, 3)); + + private static String[] toStringArray(Object[] array) { + String[] result = new String[array.length]; + for (int i = 0; i < array.length; i++) { + result[i] = array[i].toString(); + } + return result; } public static void main(String[] args) { + System.out.println("In the upcoming exercises, the following symbols are used in reporting:"); + System.out.println("ni - initial electron energy level"); + System.out.println("nf - final electron energy level"); + System.out.println("E - energy in joules"); + System.out.println("F - frequency in Hz"); + System.out.println("Lambda - wavelength in nm"); p1(); p2(); p3(); p4(); - p5(); - p6(); } }