From fdd27006551db6e13ef7571f793a1f829a5cfd10 Mon Sep 17 00:00:00 2001 From: Tim <70119791+journich@users.noreply.github.com> Date: Thu, 18 Feb 2021 14:25:12 +1030 Subject: [PATCH] Java version of SineWave basic program --- 78 Sine Wave/java/SineWave.java | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 78 Sine Wave/java/SineWave.java diff --git a/78 Sine Wave/java/SineWave.java b/78 Sine Wave/java/SineWave.java new file mode 100644 index 00000000..7d917a75 --- /dev/null +++ b/78 Sine Wave/java/SineWave.java @@ -0,0 +1,35 @@ +import java.util.Arrays; + +/** + * Sine Wave + * + * Based on the Sine Wave program here + * https://github.com/coding-horror/basic-computer-games/blob/main/78%20Sine%20Wave/sinewave.bas + * + * Note: The idea was to create a version of this 1970's Basic program in Java, without introducing + * new features - no additional text, error checking, etc has been added. + */ +public class SineWave { + + public static void main(String[] args) { + + System.out.println("SINE WAVE"); + System.out.println("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"); + System.out.println(); + + int toggle = 0; + for(double t = 0; t<40; t += .25) { + int a = 26 + (int) (25 * Math.sin(t)); + char[] repeat = new char[a]; + Arrays.fill(repeat,' '); + System.out.print(new String(repeat)); + if (toggle == 1) { + System.out.println("COMPUTING"); + toggle = 0; + } else { + System.out.println("CREATIVE"); + toggle = 1; + } + } + } +}