I am trying to get a basic java program running but it is not adding up and its giving me an infinite loop. Any help will be greatly appreciated.
Input : age of each patron (end of input denoted by a value < 0)
There are two categories of patrons:
Age 0 through 5 : Kids – no charge($0)
Age 5 through 18 : Students - $5
I am supposed to
Get the age of the patron
Determine which category that patron falls into & increase the number for that category
Keep doing steps 1 & 2 until the end of input is reached
Once end of input is reached • Calculate the revenue generated for each category (number of patrons in a category * rate for that category) • Total revenue for the day (sum of revenues of all 4 categories)
Generate output in the following format
• Perot Museum : Today’s Revenue
• Number of kids : *****
• Revenue from kids : $0
• Number of students : ****
• Revenue from students : $****
This is my code:
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
int kidsPrice = 0;
int studentPrice=5;
Scanner input = new Scanner(System.in);
int number = input.nextInt();
while(number > 0 ){
if (number >= 0 && number <= 5){
for(int i = 0; i < number; i++) {
int numOfKids = i;
System.out.println("Kids " + numOfKids);
}
System.out.println("Kids " + kidsPrice);
}
else if (number >= 5 && number <= 18){
for(int i = 0; i < number; i++) {
int numOfStudents = i;
}
System.out.println("Students");
}
--number;
}
}
}
It is not really doing any of the things I want, it is not adding the numbers and I need some pointers on what I am doing wrong and need to fix