Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class named ParkingMeter containing: Two instance variables named timeLe

ID: 3906146 • Letter: W

Question

Write a class named ParkingMeter containing: Two instance variables named timeLeft and maxTime of type int. The value of timeLeft should be initialized to 0. A constructor accepting a single integer parameter whose value is used to initialize the maxTime instance variable. A method named add that accepts an integer parameter. If the value of the parameter is equal to 25, the value of timeLeft is increased by 30; otherwise no increase is performed. Furthermore, the increase occurs only if the value of timeLeft will not exceed the value of maxTime. add returns a boolean value: true if timeLeft was increase, false otherwise. A method named tick that accepts no parameters and returns no value. tick decreases the value of timeLeft by 1, but only if the value of timeLeft is greater than 0. A method named isExpired that accepts no parameters. isExpired returns a boolean value: true if the value of timeLeft is equal to 0; false otherwise.

Explanation / Answer

//ParkingMeter.java public class ParkingMeter { private int timeLeft; private int maxTime; public ParkingMeter(int maxTime) { this.maxTime = maxTime; this.timeLeft = 0; } boolean add(int val){ if(val == 25 && timeLeft+30 0) timeLeft--; } boolean isExpired(){ if(timeLeft == 0){ return true; } else return false; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote