194k views
4 votes
Jeremiah is writing a program for a gym, where customers need to scan their gym card to get in and out. The program should keep track of how many people are in the gym and refuse entry once the gym is at maximum capacity. Describe one constant and two variables the program should use. (6 marks)

User Tacet
by
8.1k points

1 Answer

0 votes

One constant that the program should use is the maximum capacity of the gym. This constant value should not change during the program's execution, so it should be declared using the final keyword:

final int MAX_CAPACITY = 100;
This declares a constant integer variable named MAX_CAPACITY with a value of 100.

Two variables that the program should use are:

A variable to keep track of the current number of people in the gym. This variable should be initialized to 0 and updated each time someone enters or exits the gym. It can be declared as an int:

int currentOccupancy = 0;

A variable to store the result of scanning a gym card. This variable can be declared as a boolean, with true indicating that the customer is entering the gym and false indicating that the customer is leaving the gym:


boolean scanResult = true;


These two variables will be used to update the currentOccupancy variable accordingly, and to determine whether a new customer can enter the gym based on the current occupancy and the maximum capacity.





ChatGPT Mar 14 Version. Free Research Preview. Our goal is to make AI systems more natural and safe to interact with. Your feedback will help us improve.
User Jacek Grobelny
by
8.4k points