52.3k views
1 vote
Write the definition of a class named ParkingMeter containing the following members:

A. A public field named timeLeft of type int, initialized to 0.
B. A public method named add that accepts an int argument. If the value of the argument is equal to 25, the value of timeLeft is increased by 30; otherwise no increase is performed. The add method returns a boolean value. It returns true if timeLeft was increased, false otherwise.
C. A public method named tick that accepts no arguments and returns no value. The tick method decreases the value of timeLeft by 1, but only if the value of timeLeft is greater than 0.
D. A public method named isExpired that accepts no arguments and returns a boolean value. It returns true if the value of timeLeft is equal to 0; false otherwise.
E. Java.

User Denitra
by
8.4k points

1 Answer

3 votes

Final answer:

To define the class named ParkingMeter, we can create a Java class with a public field called timeLeft of type int. This field should be initialized to 0.

Step-by-step explanation:

To define the class named ParkingMeter, we can create a Java class with a public field called timeLeft of type int. This field should be initialized to 0.

Next, we can add a public method named add to the class, which accepts an int argument. In this method, we can check if the argument is equal to 25. If it is, we can increase the value of timeLeft by 30 and return true. If the argument is not equal to 25, no increase is performed and we return false.

Another method we can add to the class is tick, which accepts no arguments and returns no value. This method should decrease the value of timeLeft by 1, but only if the value of timeLeft is greater than 0.

Finally, we can add a public method named isExpired, which accepts no arguments and returns a boolean value. This method should return true if the value of timeLeft is equal to 0, and false otherwise.

User Rob Vermeulen
by
8.3k points