Heya, I've tried to make a program that plots a sinus curve.
The user is asked what width and scale he wants the plot to be.
The problem is that the scale is messed up and I would appreciate if someone could help me out
Code:public class Trigonometry { public static void main(String[] args) { double[] sinusarray = { 0.3, 0.7, 1, 1.3, 1.6, 1.9, 2.2, 2.5, 2.8, 3.1, 3.4, 3.7, 4, 4.3, 4.6, 4.9, 5.2, 5.5, 5.8, 6.1 }; sinus(sinusarray); System.out.print("scale: "); double scale = Keyboard.readDouble(); System.out.print("width: "); double width = Keyboard.readDouble(); plotFunctionstable(sinusarray, scale, width); } static void sinus(double[] array) { for (int i = 0; i < array.length; i++) { array[i] = Math.sin(array[i]) / array[i]; // } } static void plotFunctionstable(double[] array, double width, double scale) { for (int i = 0; i < array.length; i++) { double blanksteg = scale * (width + array[i]); for (int j = 0; j < blanksteg; j++) { System.out.print(' '); } System.out.println('*'); } } }


Reply With Quote
Bookmarks