Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

1. Where will you recommend that she hold the focus group?

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago