Hello,
I recently started learning java, and I am trying to make a program and I am running into some trouble. Basically what I want is for the user to input the number of people attending a movie, and then the user could input all of the ages of the people attending the movie, and then the program would print the total cost depending on the ages entered (child, senior, regular adult etc...).
Here is what I have so far:
import java.util.*;
public class movietickets1 {
public static void main(String[] args) {
int numberpeople, answer;
Scanner xx=new Scanner(System.in);
System.out.println("Please enter the number of people attending the movie below:");
numberpeople=xx.nextInt();
int[] attendees = new int[numberpeople];
for (int i = 0; i < attendees.length; i++) {
System.out.print("Please enter the age of person number ");
System.out.print(i+1);
System.out.print(" below:");
attendees[i]=xx.nextInt();
}
}
}
Basically what I was thinking of doing was creating 3 more methods, that would return a variable that counted the number of people that were 12 and under for children, the number of people attending 65 and over for senior, and everything else in between for regular adults. Now I am not sure where to begin for what I want to accomplish for these 3 methods, as I am not sure how to get a method to return a variable that counted the number of items in an array that were above or below a certain value.
So basically - how could I return the number of values in an array greater than or less than a certain number? Like let's say the user entered 2 people who were 16 years of age or less, how could I get that method to return 2?
Thanks!