Help - Avg
Hello to all. I'm new to the Java world and taking a class online. The project that I'm working now is having a user enter age and weight of an indefinite number of people and then calculate the average age and weight. There is more to the project, but need to get this part first. Here is what I have so far:
/*
This program will allow the user to enter the age in years
and weight in pounds of an indefinite number of people. It
will then use a sentinel value to average the
data entered. The program will then calculate the average
weight and age for all the people. */
import java.util.*;
import java.text.DecimalFormat;
public class People911.java
{
public static void peopleAgesandWeight()
{
int people = 0
int agesTotal = 0;
double agesAverage = 0;
int ages;
/*Description of program for user.*/
System.out.println("This program will calculate the average");
System.out.println("age in years and weight in pounds of an");
System.out.println("indefinite number of people. \n");
System.out.println("Enter the ages when prompted.");
System.out.println("Enter -1 when you are done.");
System.out.println("\n\n");
System.out.println("Enter in ages. Press enter after each age. \n");
ages = scannerObject.nextInt();
System.out.println("Now enter the weights when prompted.");
System.out.println("Enter -1 when you are done. \n");
System.out.println("Enter in weights. Press enter after each weight.\n");
ages = scannerObject.nextInt();
/*While statement.*/
while (ages!= -1) /*While loop to enter. Enter -1 to exit*/
{
agesTotal += ages; /*Sums all the ages entered*/
people ++; /*Counts the number of ages entered*/
System.out.println("Enter another score or -1 to end.");
ages = scannerObject.nextInt();
} /*End of while loop.*/
System.out.println("\n");
agesAverage = agesTotal / ages; /*Calculates average
DecimalFormat twoDigits = new DecimalFormat ("0.00"); /*Create new DecimalFormat object*/
System.out.println("You entered" +ages+" years.");
System.out.println("The sum of your ages are" +agesTotal);
System.out.println("Your average age is " + twoDigits.format (agesAverage));
System.out.println("\n\n");
} /*End of method for data.*/
}
Am I in the ballpark?
Thanks in advance.

