Question

14.5 Prog 5: People's weights (arrays) JAVA (1) Prompt the user to enter five numbers, being...

14.5 Prog 5: People's weights (arrays) JAVA

(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 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class PeopleWeights {
    //Main1 method
    public static void main(String[] args) {
        //Array to hold weights
        double[] weights = new double[5];
        int i;
        double total = 0, average, max = 0;

        Scanner sc = new Scanner(System.in);

        //Reading 5 weights from user
        for (i = 0; i < 5; i++) {
            System.out.println("Enter weight " + (i + 1) + ": ");
            //Storing weights in array
            weights[i] = sc.nextDouble();
        }

        //Printing, calculating total and average of weights
        System.out.print("You entered: ");
        for (i = 0; i < 5; i++) {
            //Printing each weight
            System.out.print(" " + weights[i]);
            //Calculating total weight
            total += weights[i];
            //Finding findMaximumIndex weight
            if (weights[i] > max)
                max = weights[i];
        }
        average = total / 5.0;

        //Printing total weight
        System.out.println("\n\nTotal weight: " + total);

        //Printing average weight
        System.out.println("Average weight: " + average);

        //Printing max weight
        System.out.println("Max weight: " + max);
    }
}
Add a comment
Know the answer?
Add Answer to:
14.5 Prog 5: People's weights (arrays) JAVA (1) Prompt the user to enter five numbers, being...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5.23 LAB: Warm up: People's weights (1) Prompt the user to enter five numbers, being five...

    5.23 LAB: Warm up: People's weights (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....

  • 5.18 Ch 5 Warm up: People's weights (Vectors) (C++) (1) Prompt the user to enter five...

    5.18 Ch 5 Warm up: People's weights (Vectors) (C++) (1) Prompt the user to enter five numbers, being five people's weights. Store the numbers in a vector of doubles. Output the vector'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 89.5 142 166.3 93 (2) Also output the total weight, by summing...

  • Need a basic program in C using the instructions above. Thanks. (1) Prompt the user to...

    Need a basic program in C using the instructions above. Thanks. (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 Enter weight 2: 89.5 Enter weight 3: 142 Enter weight 4: 166.3 Enter weight 5: 93 You entered 236.000000 89.500000 142.000000 166.300000 93.000000 (2) Also output the total weight,...

  • 11.6 Week 8 Lab: Arrays Boulder Weights Solve in C! (1) Prompt the user to enter...

    11.6 Week 8 Lab: Arrays Boulder Weights Solve in C! (1) Prompt the user to enter an integer for the number of boulders they have (assume the value is always less than 50). Then, prompt the user to enter that many numbers, representing the boulders’ weights. Store the weights in an array of doubles. Output the array's numbers on one line, each number followed by one space. (2 pts) (2) Also output the total weight, by summing the array's elements....

  • Hello, can someone please help me correct this code? I greatly appreciate it. 7.16 Ch 7...

    Hello, can someone please help me correct this code? I greatly appreciate it. 7.16 Ch 7 Warm up: People's weights (Lists) (Python 3) (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.0 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...

  • Hi, I need some help with the following question. I need the answer in Python please....

    Hi, I need some help with the following question. I need the answer in Python please. 10.23 LAB: Warm up: People's weights (Lists) (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.0 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...

  • ZYBOOKS LAB: 10.23.1 Hello, I'm trying to solve this problem with creating a program code in...

    ZYBOOKS LAB: 10.23.1 Hello, I'm trying to solve this problem with creating a program code in Python about People's Weights. Here is the question: 10.23 LAB: Warm up: People's weights (Lists) (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.0 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3]...

  • I cannot seem to find a single answer to this question. The output of this code...

    I cannot seem to find a single answer to this question. The output of this code is You entered: 236.0 89.5 142.0 166.3 93.0 with a trailing space at the end of the number 93.0. These inputs are changed and always have a trailing space on the last number. Now, I know it's because I have System.out.print(m[i] + " "); with the " " creating the space in between each number. How do I write it so each number has...

  • 6.17.1 Lab #5 - Chapter 6 Text analyzer & modifier (C) (1) Prompt the user to...

    6.17.1 Lab #5 - Chapter 6 Text analyzer & modifier (C) (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. (2) Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. We encourage you to use a for loop in this...

  • Please and thank you 2) (5 pts) Arrays & Vectors: write a program which prompts the...

    Please and thank you 2) (5 pts) Arrays & Vectors: write a program which prompts the user to enter numbers (terminated with a non-numeric), reads them simultaneously into an array of doubles and into a vector of doubles, then prints A) the array elements in the original order B) the vector elements in reverse order C) the average of the vector elements D) the largest of the vector elements Example program output, user input shown underlined Enter a list of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT