Question: JAVA/UNIX Make a program that finds the weighted arithmetic mean for a user specified number of (number,weight) pairs as well as the simple arithmetic mean

JAVA/UNIX

Make a program that finds the weighted arithmetic mean for a user specified number of (number,weight) pairs as well as the simple arithmetic mean of the numbers specified:

ask the user to enter an integer number n for the pairs

prompt and read n pairs (integer number, real number for the weight) provided by the user

displays the weighted arithmetic mean of all the n pairs and the simple arithmetic mean of the n numbers

Be sure:

if n is specified to be 0, the program computes the correct values. Include a sample run for this input.

The program works for any n specified (do not hardcode the number of pairs)

Example 1:

Input file contains:

6

9

3.4

24

46.6

67

9.5

9

23.1

84

45

32

3.1

After running your program with the input redirected to the above input file, the redirected output file should contain the following sample run:

Enter number of pairs: 6

Enter number 1: 9

Enter weight 1: 3.4

Enter number 2: 24

Enter weight 2: 46.6

Enter number 3: 67

Enter weight 3: 9.5

Enter number 4: 9

Enter weight 4: 23.1

Enter number 5: 84

Enter weight 5: 45.

Enter number 6: 32

Enter weight 6: 3.1

Simple arithmetic mean of these 6 numbers is: 37.50

Weighted arithmetic mean of these 6 pairs is: 44.93

Example2:

Input file contains:

0

Output file should contain:

Enter number of pairs: 0

Simple arithmetic mean of these 0 numbers is: 0

Weighted arithmetic mean of these 0 pairs is: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!