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

Can someone get this to work in NetBeans and or ZyBooks Thanks!!! 7.5 Warm up: P

ID: 3812146 • Letter: C

Question

Can someone get this to work in NetBeans and or ZyBooks

Thanks!!!

7.5 Warm up: People's weights (Java)

Instructor notes

While you will be submitting this assignment through Zybooks, make sure you are still applying appropriate formatting and in-line commenting.

[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 89.5 142 166.3 93

(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:

Lab 7.5.1: Warm up: People's weights (Java) Submission People Weights. java Load default template. 1 import java util Scanner 3 public class Peopleweights f 4 public static void main(String args Type your code here. return; n "Develop" mode, you can run your program as often as you'd like, before submitting for grading. Type input Develop Submit values (if desired) in the first box below, then click "Run program" and observe the program's output in the second box. RUN PROGRAM Enter program input (optional) If your code requires input values, provide them here.

Explanation / Answer

PeopleWeights.java


import java.text.DecimalFormat;
import java.util.Scanner;
public class PeopleWeights {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int i = 0;
int n = 5;
double arr[]=new double[n];

for(i = 0; i < n; i++){
System.out.print("Enter weight " + (i+1)+": ");
arr[i]=scnr.nextDouble();
}
System.out.println();
System.out.print("You entered: ");
for(i = 0; i < n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
double total = 0;
double max = 0;
for(i=0; i<n; i++){
   if(max < arr[i]){
       max = arr[i];
   }
   total = total + arr[i];
}
DecimalFormat df = new DecimalFormat("#.##");
double average = total/n;
System.out.println("Total weight: "+df.format(total));
System.out.println("Average weight: "+df.format(average));
System.out.println("Max weight: "+df.format(max));
  
return;
}
}

Output:

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.0 89.5 142.0 166.3 93.0
Total weight: 726.8
Average weight: 145.36
Max weight: 236