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:");

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(" below:");




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?


5 Years
Discussion Span
Last Post by shootingrubber

Hmm... I think you may need to read about Object Oriented Programming concept first before you tackle a problem in programming. You can read some basic at this link http://download.oracle.com/javase/tutorial/java/concepts/.

I understand that get right to programming may help you understand faster, but it is better off and will pay off in the future if you get your fundamental right. Coding is easy and most anyone can do, but understand the concept and code properly is a different story. :) Once you understand the concept or at least know what it talks about, then you should be able to correctly formulate your solution for a problem. :)


System.out.print("Please enter the age of person number ");

In line 16 you are asking the user to input age of the person but you did not use your scanner.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.