Question

In: Computer Science

(1) Prompt the user to enter five numbers, being five people's weights. Store the numbers in...

(1) Prompt the user to enter five numbers, being five people's weights. Store the numbers in an array of doubles. Output the array's numbers on one line, each number followed by one space. (2 pts)

Ex:

Enter weight 1:
236.0
Enter weight 2:
89.5
Enter weight 3:
142.0
Enter weight 4:
166.3
Enter weight 5:
93.0
You entered: 236.0 89.5 142.0 166.3 93.0

(2) Also output the total weight, by summing the array's elements. (1 pt)

(3) Also output the average of the array's elements. (1 pt)

(4) Also output the max array element. (2 pts)

Ex:

Enter weight 1:
236.0
Enter weight 2:
89.5
Enter weight 3:
142.0
Enter weight 4:
166.3
Enter weight 5:
93.0
You entered: 236.0 89.5 142.0 166.3 93.0

Total weight: 726.8
Average weight: 145.35999999999999
Max weight: 236.0

import java.util.Scanner;

public class PeopleWeights {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);

/* Type your code here. */
}
}

Need in Java

Solutions

Expert Solution

import java.util.Scanner;
public class PeopleWeights
{
    public static void main(String args[])
    {
        Scanner scnr =new Scanner(System.in);
        double weights[]=new double[5];
        double totalWeight = 0, avg, max = 0;
        int i;
        for (i = 0; i < 5; i++)
        {
            System.out.print("Enter Weight " + (i + 1) + ":\n");
            weights[i] = scnr .nextDouble();
        }
        System.out.print("You entered: ");
        for (i = 0; i < 5; i++)
        {
            System.out.print(weights[i] + " ");
            totalWeight = totalWeight + weights[i];
        }
        System.out.println();
        for (i = 0; i < 5; i++)
        {
            if(weights[i]>max)
                max=weights[i];
        }
        System.out.println("");
        avg = totalWeight / 5;
        System.out.println("Total weight: " + totalWeight);
        System.out.println("Average weight: " + avg);
        System.out.println("Max Weight: " + max);
    }
}


Related Solutions

*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the...
*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more...
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
(1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds....
(1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts) Ex: Enter weight 1: 236 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3] (2) Output the average of the list's elements. (1 pt) (3) Output the max list element. (1 pt) Ex: Enter weight 1: 236 Enter weight 2: 89.5 Enter weight 3: 176.0...
JAVA You will then prompt the user to enter each grocery item and store it in...
JAVA You will then prompt the user to enter each grocery item and store it in your array. Afterward, the program will ask the user to enter which grocery item they are looking for in the list, and return a message back on whether it was found or not found. (Hint: You will need two for-loops for this program - one for storing each element into the array and one for searching back through the array.) See below for example...
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199   Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT