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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.