Question: IN JAVA PLEASE 8) The code below is an attempt to implement the class ParkingMeter described in problem 5. It violates some best practices for

IN JAVA PLEASE

IN JAVA PLEASE 8) The code below is an attempt to implementthe class ParkingMeter described in problem 5. It violates some best practices

8) The code below is an attempt to implement the class ParkingMeter described in problem 5. It violates some best practices for using instance variables (for example, see the section "More about grading" on pp 10-11 of the hwl pdf, and/or the September 9 entry of the Section A/B topics page (front page link #6) As a consequence, this code sometimes works, but sometimes yields incorrect results. a) How are the guidelines for instances variables being violated? b) Give at least two different test cases in which you would get incorrect results. public class ParkingMeter { private int minutesPerQuarter; private int maxTime; private int timeRemaining; private int quartersAdded; private int total Quarters; public parkingMeter (int givenMinutesPerQuarter, int givenMaximumTime) { minutesPerQuarter = givenMinutesPerQuarter; maxTime = givenMaximumTime; } public void insertCoin(int howMany) { quartersAdded = howMany; } public int getTimeRemaining() timeRemaining = timeRemaining + (quartersAdded * minutesPerQuarter); timeRemaining = Math.min(timeRemaining, maxTime); return timeRemaining; } public void passTime (int minutes) { timeRemaining = timeRemaining - minutes; timeRemaining = Math.max (timeRemaining, 0); } public double getTotal() totalQuarters = totalQuarters + quartersAdded; return totalQuarters; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!