Question: Design a C# class upDown that encapsulates a number x and: supports puzzle(y) which returns x*y if in up mode returns x/y if in down

  1. Design a C# class upDown that encapsulates a number x and:
  1. supports puzzle(y) which

returns x*y if in up mode

returns x/y if in down mode

  1. supports refine() which

increments x if alive and in up mode

decrements x if alive and in down mode

  1. switches up/down mode whenever x becomes a multiple of 10
  2. negates alive mode when the number of switches (in #c above) exceeds a threshold
  3. supports reset()

Define this class, providing all implementation details

public class upDown() {

private int x;

private bool mode;

private bool alive;

private uint switch;

private uint const SWITCH_LIMIT = 10;

public upDown(int num) {

x = num;

mode = true; // true is up, is false

alive = true;

switch = 0;

}

public int puzzle(int y) {

if (alive) {

if (mode) {

return x*y;

}

return x/y;

}

return 0;

}

public void refine() {

if (alive

if (mode) {

x++;

} else if (!mode) {

x--;

}

if (x % 10 == 0) {

mode = !mode;

switch++;

}

if (switch > SWITCH_LIMIT) {

alive = false;

}

}

}

public void revive() {

if (!alive) {

alive = true;

switch = 0;

}

}

}

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!