Answered step by step
Verified Expert Solution
Question
1 Approved Answer
post a brief description of a problem which to program a solution would require complex decisions (a decision required to test more than one condition)
post a brief description of a problem which to program a solution would require complex decisions (a decision required to test more than one condition) and/or loops. Provide a code snippet under your description which implements a solution using the most appropriate Java constructs.
please see similar example:
A particular clothes washing machine main control can instruct the machine to perform different tasks which include Off, Normal Wash, Delicate Wash, Rinse, and Spin. One way to process this is below:
switch (WashMachineCmd) {
case OffCmd:
{ /* Turn the washing machine off. Dont care about previous state. */
currentState = OFF;
break; }
case NormalWash:
{ /* Start Normal wash cycle. */
If (previousState == OFF) {
currentState = NORMAL_WASH; }
else {
System.out.println(ERROR: Cannot do Normal Wash from + displayState(previousState) + .);
}
break; }
case DelicateWash:
{ /* Start Delicate wash cycle. */
If (previousState == OFF) {
currentState = DELICATE_WASH; }
else {
System.out.println(ERROR: Cannot do Delicate Wash from + displayState(previousState) + .);
}
break; }
case Rinse:
{ /* Start Rinse cycle. */
If ((previousState == NORMAL_WASH) || previousState == DELICATE_WASH) {
currentState = RINSE; }
else
{
System.out.println(ERROR: Cannot do Delicate Wash from +
displayState(previousState) + .); }
break; }
case Spin:
{ /* Start Spin cycle. */
If (previousState == RINSE) {
currentState = SPIN; }
else {
System.out.println(ERROR: Cannot do Delicate Wash from + displayState(previousState) + .);
}
break; }
}
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