Question
Create a public class called MultiPass It should store in an instance variable a double that we term the value It should define a single
Create a public class called MultiPass
It should store in an instance variable a double that we term "the value"
It should define a single method called double function(). that behaves slightly differently depending upon which constructor was used to define a MultiPass instance.
It should define three different constructors. Each describes how function should respond
MultiPass()
"the value" should be a Randomly-generated in the constructor
function should simply return "the value" that was created when constructed
MultiPass(double val)
"the value" should be initialized to val
function should update "the value" by multiplying it by 2, It should return the updated version of "the value"
MultiPass(double val, int mult)
"the value" should be initialized to val
mult should also be stored
function should update "the value" by multiplying it by mult, It should return the updated version of "the value"
Examples:
MultiPass mp = new MultiPass();
execute the code: double x1 = mp.function(); double x2 = mp.function();
Then, x1 == x2 evaluates to true
MultiPass mp = new MultiPass(35);
execute the code: double x1 = mp.function(); double x2 = mp.function();
then x1 == 70 evaluates to true
and x2 == 140 evaluates to true
MultiPass mp = new MultiPass(35,3);
execute the code: double x1 = mp.function(); double x2 = mp.function();
then x1 == 105 evaluates to true
and x2 == 315 evaluates to true
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started