Write A Class Named Parkingmeter Containing:

(Correct Answer Below)

Reveal the answer to this question whenever you are ready.

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.
Front

Advertisement

public class ParkingMeter { private int maxTime, timeLeft = 0; public ParkingMeter(int i) { maxTime = i; } public boolean add(int i) { timeLeft = (30 + timeLeft) > maxTime ? timeLeft : i == 25 ? timeLeft + 30 : timeLeft; return (30 + timeLeft < maxTime) && i == 25 ? true : false; } public void tick() { timeLeft = timeLeft > 0 ? timeLeft-1 : timeLeft; } public boolean isExpired(){ return timeLeft == 0 ? true : false; } }

About the flashcard:

This flashcard is meant to be used for studying, quizzing and learning new information. Many scouting web questions are common questions that are typically seen in the classroom, for homework or on quizzes and tests. Flashcards vary depending on the topic, questions and age group. The cards are meant to be seen as a digital flashcard as they appear double sided, or rather hide the answer giving you the opportunity to think about the question at hand and answer it in your head or on a sheet before revealing the correct answer to yourself or studying partner. Some questions will include multiple choice options to show you the options involved and other questions will just have the questions and corrects answers. Simply reveal the answer when you are ready to check your work. Absolutely no cheating is acceptable.