Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[SCALA] Write a program with: 1. A class named Battery that: - Has a constructor that takes a variable named charge of type Int 2.

[SCALA]

Write a program with:

1. A class named "Battery" that:

- Has a constructor that takes a variable named "charge" of type Int

2. A class named Flashlight that:

- Has a constructor that takes no parameters

- When a new FlashLight is created, declare a state variable named "battery" of type Battery and set it to a new Battery with 5 charge (ie. Batteries included)

- A method named "use" that takes no parameters and returns Unit

--- This method(use) will decrease the charge of the FlashLight's battery by 1 - If the charge is 0, this method does nothing

- A method named "replaceBattery" that takes a Battery as a parameter and returns a Battery

--- This method(replaceBattery) swaps the input Battery with the Battery currently stored in this FlashLight's state variable

--- The returned Battery is the one that was in the state variable when the method is called

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

What is the typical process of friendship development?

Answered: 1 week ago