Question

In: Computer Science

Write an error-free Java program to do the following things. Prompt the user to input a...

Write an error-free Java program to do the following things.

Prompt the user to input a set of numbers. The numbers represent hourly wages so they will be between 7.25 (peon) and 50 (big boss). The user should be able to input up to 35 numbers but if the user enters 0 then the data input ceases. All of the data that the user enters should be stored in a single array. You do not need to check the input data to see if it is in the proper range – assume the user will input correct data.

The program should calculate the average, the variance and the kurtosis of the numbers that were entered. The equation for the average is given in the book. The formula for the variance and the kurtosis (fourth centralized moment) is given by

Variance = SIGMA (xi-x(bar))^2/(n-1)

kurtosis = SIGMA ((xi-x(bar))^4/(n*var)^2) - 3

where xi are the individual numbers, n is the number of data points, var is the variance, and is the average of the sample. Kurtosis gives an indication of how “peaked” the data samples are relative to a normal (Gaussian) distribution.

The kurtosis must be calculated via a call to a method.

At the end, the program should repeat all of the numbers on one line and then print the average, variance, and kurtosis of the data sample.

MM§MEnter a data value (0 to quit)
¼¼§M10.5
MM§MEnter a data value (0 to quit)
¼¼§M48
MM§MEnter a data value (0 to quit)
¼¼§M8.25
MM§MEnter a data value (0 to quit)
¼¼§M8.50
MM§MEnter a data value (0 to quit)
¼¼§M20
MM§MEnter a data value (0 to quit)
¼¼§M0
MM§Msize = 5
MM§MThe data values are . . .
MM§M10.5 48.0 8.25 8.5 20.0
MM§MThe average is 19.05
MM§MThe variance is 285.0125
MM§MThe kurtosis is -1.1934395407885128


Remember to put the usual header at the top of the program and to submit via Canvas.

Solutions

Expert Solution

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Kurtosis {

   public static double kurtosis(List<Double> dataList, double average, double variance)
   {
      
       double total = 0;
       for(Double d: dataList)
       {
           total += Math.pow((d - average), 4);
       }
      
       total = total/(Math.pow(dataList.size()*variance, 2)) - 3;
       return total;
   }
  
   public static double variance(List<Double> dataList, double average)
   {
       double total = 0;
       for (Double d: dataList)
       {
           total += (d-average)*(d-average);
       }
       return total/(dataList.size() -1);
   }
   public static double average(List<Double> dataList)
   {
       int size = dataList.size();
       double total = 0;
       for(Double d : dataList)
       {
           total += d;
       }
       return total/size;
   }
   public static void main(String[] args)
   {
       List<Double> dataList = new ArrayList<>();
       Scanner sc = new Scanner(System.in);
      
       while(true)
       {
           System.out.println("MM§MEnter a data value (0 to quit)");
           double data;
           data = sc.nextDouble();
           if (data == 0)
           {
               break;
           }
           dataList.add(data);
       }
      
       if (dataList.size() != 0)
       {
           double avg = average(dataList);
           double var = variance(dataList, avg);
           double kurt = kurtosis(dataList, avg, var);
           System.out.println("size = " + dataList.size());
          
          
           System.out.println("Data values are...");
           for(Double d: dataList)
           {
               System.out.print(d + " ");
           }
          
           System.out.println();
          
           System.out.println("The average is " + avg);
           System.out.println("The variance is " + var);
           System.out.println("The kurtosis is " + kurt);
       }
      
       sc.close();
   }
}


Related Solutions

IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the number of Adult tickets to purchase Prompt user to input the number of Children tickets to purchase Prompt user to input the number of Senior tickets to purchase Write a method named, ticketCost(), which will be invoked by main() with statement similar to: cost = ticketCost( adults, children, senior ); Ticket costs structure: $15.00 for each adult $10.00 for each child $5.00 for each...
Write a program that uses input to prompt a user for their name and then welcomes...
Write a program that uses input to prompt a user for their name and then welcomes them. Note that input will pop up a dialog box. Enter Sarah in the pop-up box when you are prompted so your output will match the desired output.(In Python)
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
Write a program that will input the information for 2 different employees. Prompt the user for...
Write a program that will input the information for 2 different employees. Prompt the user for the first employee’s name, hours worked and rate. Compute the salary and display it. Do the same for the second and third employees. Then, display a message to the effect that the highest salary is whatever and the lowest salary is whatever. When the program runs, the following should display information should line up just as I have it below. E:\> java Quiz4 Name:...
Write a program that will read user input, and do the following: 1. The user can...
Write a program that will read user input, and do the following: 1. The user can input letters [A-Z] as much as he wants (ignore case). 2. If the user input other than letters or two characters, stop the input process and start to print unduplicated sorted pairs such as the below examples: User input: A a e b d d D E a B 1 Output: AB AD AE BD BE DE User Input: a q w e dd...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT