Write a Java program that generates interesting numerical data and uses Java gra
ID: 3819953 • Letter: W
Question
Write a Java program that generates interesting numerical data and uses Java graphics to visualize the data. Required elements include: Use methods containing loops to generate data from two of the following mathematical descriptions and write the data to files (each sequence is a separate method). The first (Arithmetic sequence) is required; you may choose either of the other two: An Arithmetic sequence is defined as the set of numbers formed by adding a constant value to each successive term beginning with the first term, which is 1. So, for example, if the constant is 5, the first several numbers in the series are: 1, 6, 11, 16, 21, 26, 31, 36 The Square series is the set of n terms where each term is the square of its position, starting from 1 - so, for n = 12 the series is: 1, 4, 9, 16, 25, 49, 64, 81, 100, 121, 144 The Fibonacci series is defined as follows: the first number in the series is 1, the second is 2 - after that, each number is the sum of the two previous numbers. The first several values are thus: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 Using the data files you generated, as input sources, write a Java program that uses graphics to visualize the series using either ASCII art or swing objects. Each visualization is a single method. Examples of some (not very impressive) visualizations are shown below: Fibonacci numbers (2 different representations) Your main method should: 1. call the necessary methods to generate the data files (do this just once per program run) 2. display a menu of visualizations the user can look at 3. display the user's choice of visualizations 4. cycle through steps 2 and 3 as long as the user wishes Sample programs (that deal with random numbers, not deliberate series) are provided with this assignment - take a look for hints on how to cycle between different visualizations Come up with your own interesting number series and create a visualization Your series cannot be random - it must have a mathematical basis, and that must be documented in the code that generates the data.Explanation / Answer
Arithmetic sequence
import java.util.*;
public class ArithmeticSequence {
public static void main(String[] args) {
int d;
double x;
int n;
double s;
int i;
int v;
double z;
Scanner console=new Scanner(System.in);
System.out.print("Enter the Common difference: ");
d=console.nextInt();
System.out.print("Enter the First Term: ");
x=console.nextDouble();
System.out.print("Enter the Number of Terms: ");
n=console.nextInt();
for(i=0,s=0;n>i;i++){
System.out.println(""+(x+(i*d)));
s=s+(x+(i*d));
}
System.out.println("");
System.out.println("The sum is "+s);
}
}
Square series
FIBONACCI SERIES
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.