Create a Java program for generating mathematical statistics. The program should store a total of 1000 decimal numeric values in a data array and provide a menu with various user-selectable options. It will run until the user selects the exit option. The program menu should include the following options (1-5):
Functionalities:
1. Add 2. Show 3. Search 4. Statistics 5. Exit Enter a option (1-5): 1 7 1. Add 2. Show 3. Search 4. Statistics 5. Exit Enter a option (1-5): 2 1. Add 2. Show 3. Search 4. Statistics 5. Exit Enter a option (1-5): 3 6 1. Add 2. Show 3. Search 4. Statistics 5. Exit Enter a option (1-5): 4 1. Add 2. Show 3. Search 4. Statistics 5. Exit Enter a option (1-5): 5
7 Not found Total data: 1 Sum: 7 Average: 7 Min value: 7 Max value: 7
import java.util.Scanner; public class Statistics { public static void main(String[] args) { int total = 1000; float[] numbers = new float[total]; int counter = 0; float max_value = Float.MIN_VALUE; float min_value = Float.MAX_VALUE; float total_values = 0.0f; int choice; Scanner scanner = new Scanner(System.in); do { System.out.println("1. Add"); System.out.println("2. View"); System.out.println("3. Search"); System.out.println("4. Statistics"); System.out.println("5. Exit"); System.out.println(); System.out.print("Enter an option (1-5): "); choice = scanner.nextInt(); switch (choice) { case 1: // Add if (counter < total) { System.out.print("Enter a value: "); numbers[counter] = scanner.nextFloat(); if (max_value < numbers[counter]) { max_value = numbers[counter]; } if (min_value > numbers[counter]) { min_value = numbers[counter]; } total_values += numbers[counter]; counter++; } else { System.out.println("The database is full"); } break; case 2: // View if (counter > 0) { for (int i = 0; i < counter; i++) { System.out.print(numbers[i] + " "); } System.out.println(); } else { System.out.println("Data not available"); } break; case 3: // Search if (counter > 0) { System.out.print("Enter a value to search: "); float search_number = scanner.nextFloat(); boolean found_number = false; for (int i = 0; i < counter; i++) { if (numbers[i] == search_number) { found_number = true; break; } } if (found_number) { System.out.println("Number " + search_number + " found"); } else { System.out.println("Number not found"); } } else { System.out.println("Data not available"); } break; case 4: // Statistics if (counter > 0) { System.out.println("Total data: " + counter); System.out.println("Sum: " + total_values); System.out.println("Mean: " + (total_values / counter)); System.out.println("Minimum value: " + min_value); System.out.println("Maximum value: " + max_value); } else { System.out.println("Data not available"); } break; default: System.out.println("Valid options (1-5)"); break; } } while (choice != 5); scanner.close(); } }
Click here to view the exercise solution
Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.
The code has been successfully copied to the clipboard.
Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!
Create a Java program that prompts the user for 5 integers to store them in an integer array and displays them in reverse order.
Create a program in Java that serves to search an array of integer values.
Write a Java program that prompts the user to enter 10 integers. Then, store these numbers in an integer array and display only the even numbers.
Write a Java program that prompts the user to enter 10 real numbers and displays the arithmetic mean of positive and negative numbers.
Create a Java program that mimics the functionality of the banner command on Unix.
Create a Java program that prompts the user for 10 integers and sorts them using the bubble sort algorithm.
Create a Java program that prompts the user to input the scores of 10 students, divided into 2 groups of 5 students each.
Create a Java program that declares a two-dimensional character array of 20 rows by 70 columns and stores the letter 'X' to display on the screen.
Java Program for Mathematical Statistics: Store, Analyze, and Visualize Data. Enhance Your Skills!
Create a Java program that draws a 360 screen circumference.
Practice with exercises in Java that use arrays of different dimensions to store the information.
Free programming course with practical exercises and solutions in C#. Start learning right now!
Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play
Own and third party cookies to improve our services. If you go on surfing, we will consider you accepting its use.