Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Download the program submission template. 2. Create new project, Lab7. Create

ID: 3602503 • Letter: 1

Question

1. Download the program submission template.
2. Create new project, Lab7. Create new package, lab7. Create new class, Main.
3. Study the example code below which is a program that finds the kth percentile of a list of sorted
data. Write a program that extends the example code to find five number summary of a list of
data. Your program should sort the data entered (low to high) and display the sorted data. Next,
your program should give the minimum, first quartile, median, third quartile, and maximum of
the data. Your program should produce the following input and output:
---
Basic Statistics Calculator:
Enter a list of numbers separated by spaces:
5.0 4.0 3.0 2.0 1.0
Sorted data:
1.00 2.00 3.00 4.00 5.00
Five Number Summary:
1.00 2.00 3.00 4.00 5.00
---
Basic Statistics Calculator:
Enter a list of numbers separated by spaces:
20 -83 -27 -49 79 86 21 -11 -63 0
Sorted data:
-83.00 -63.00 -49.00 -27.00 -11.00 0.00 20.00 21.00 79.00 86.00
Five Number Summary:
-83.00 -43.50 -5.50 20.75 86.00
---
Note: Your quartiles may be different, but must be between the same two data values.

Run the code and do the following calculations with it:

Data Set: -72.6 33.9 -49.9 25.9 -21.3 52.9
Data Set: 90.5 97.2 80.2 79.5 86.2 52.6 63.9 79.2 94.4
Data Set: 5.0 5.0 1.0 5.0 5.0 5.0

package lab7;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
String line = ""; // String to store string of data
double[] data; // The array for storing the data set
int n = 0; // The size of the data set
double k = 0.0; // The value of k, for kth percentile
double position = 0.0; // The position of the kth percentile in list
int index = 0; // The integer portion of position
double fraction = 0.0; // The fraction portion of position
double percentile = 0.0; // The variable for storing the kth percentile
double epsilon = 0.0001; // Epsilon for comparing doubles
// Initialize scanner for input.
Scanner input = new Scanner(System.in);
// Prompt the user to enter which percentile to calculate.
System.out.println("Basic Statistics Calculator:");
System.out.print("Enter k, for calculating the kth percentile: ");
k = input.nextDouble();
input.nextLine(); // Consume the from scanner.
// Prompt the user to enter data and read the entire data set as single string.
System.out.println("Enter a list of numbers separated by spaces: ");
line = input.nextLine();
// Create scanner to read the sting line.
Scanner scanLine = new Scanner(line);
// The first pass through just counts how many numbers there are in line.
while (scanLine.hasNextDouble()) {
scanLine.nextDouble();
n++;
}
// Check if any data was entered.
if (n>0) {
// Create the array of appropriate size.
data = new double[n];
// Close and recreate scanner to take it back to beginning of string.
scanLine.close();
scanLine = new Scanner(line);
// The second pass through reads the numbers into the array.
for (int i=0; i data[i]=scanLine.nextDouble();
// Calculate the kth percentile.
if (n==1) percentile = data[0];
else {
position = (k/100.0)*(n-1);
index = (int)position;
fraction = position - (double)index;
if (fraction > epsilon)
percentile = data[index]
+ fraction * (data[index+1]-data[index]);
else
percentile = data[index];
}
// Display results.
System.out.printf("The %.2fth percentile is %.2f. ", k, percentile);
}
else {
System.out.printf("No data entered.");
}
// Close scanners.
scanLine.close();
input.close();
}

}

Explanation / Answer

import java.util.Scanner;
public class main {
public static void main(String[] args) {
String line = ""; // String to store string of data
double[] data; // The array for storing the data set
int n = 0; // The size of the data set
double k = 0.0; // The value of k, for kth percentile
double position = 0.0; // The position of the kth percentile in list
int index = 0; // The integer portion of position
double fraction = 0.0; // The fraction portion of position
double percentile = 0.0; // The variable for storing the kth percentile
double epsilon = 0.0001; // Epsilon for comparing doubles
// Initialize scanner for input.
Scanner input = new Scanner(System.in);
// Prompt the user to enter which percentile to calculate.
System.out.println("Basic Statistics Calculator:");
System.out.print("Enter k, for calculating the kth percentile: ");
k = input.nextDouble();
input.nextLine(); // Consume the from scanner.
// Prompt the user to enter data and read the entire data set as single string.
System.out.println("Enter a list of numbers separated by spaces: ");
line = input.nextLine();
// Create scanner to read the sting line.
Scanner scanLine = new Scanner(line);
// The first pass through just counts how many numbers there are in line.
while (scanLine.hasNextDouble()) {
scanLine.nextDouble();
n++;
}
// Check if any data was entered.
if (n>0) {
// Create the array of appropriate size.
data = new double[n];
// Close and recreate scanner to take it back to beginning of string.
scanLine.close();
scanLine = new Scanner(line);
// The second pass through reads the numbers into the array.
for (int i=0; i data[i]=scanLine.nextDouble();
// Calculate the kth percentile.
if (n==1) percentile = data[0];
else {
position = (k/100.0)*(n-1);
index = (int)position;
fraction = position - (double)index;
if (fraction > epsilon)
percentile = data[index]
+ fraction * (data[index+1]-data[index]);
else
percentile = data[index];
}
// Display results.
System.out.printf("The %.2fth percentile is %.2f. ", k, percentile);
}
else {
System.out.printf("No data entered.");
}
// Close scanners.
scanLine.close();
input.close();
}

}