Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class called Battery that serves as a blueprint for objects representing a battery for a cell phone or other similar device. Each Battery object keeps

Class called Battery that serves as a blueprint for objects representing a battery for a cell phone or other similar device. Each Battery object keeps track of (1) the percentage of charge remaining in the battery (an integer) and (2) whether the battery is being charged (true if it is, and false if it is not).

Write only the five components of the class that we have requested below. You should assume that all of the other methods of the class are being written by someone else. You should not write them, and you should not call them.

Make sure that your class employs proper encapsulation to prevent clients of the class from putting a Battery object into an invalid state. In particular, you should not allow a Battery to have a negative charge; rather, you should throw an IllegalArgument- Exception to prevent this from happening. You only need to worry about this in the context of the code that that you write below.

a)  Define the fields of the object. Choose appropriate names.

b)  Write a constructor that takes an initial value for the charge remaining and assumes that the battery is not being charged.

c) Write an accessor method for whether the battery is being charged. Choose an appropriate name.

 Sulliva

d) Write a method called decrementCharge that decreases the charge remaining in the battery by 1. For example, if the charge remaining is 50, calling this method should reduce it to 49.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Java public class Battery a Fields private int charge... 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_2

Step: 3

blur-text-image_3

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

Analytics Data Science And Artificial Intelligence Systems For Decision Support

Authors: Ramesh Sharda, Dursun Delen, Efraim Turban

11th Global Edition

1292341556, 9781292341552

More Books

Students also viewed these Programming questions

Question

=+ What are our strongest assets?

Answered: 1 week ago

Question

please dont use chat gpt or other AI 8 0 5 . .

Answered: 1 week ago