-2

I'm trying to compile a simple program to bake a cake. The variables are basically

  1. If cake burning = Yes then turn over off.
  2. If temp < 120deg turn over up.
  3. If temp > 190deg turn over down.

Also if the cake is burning and the answer is yes then the program should end there.

I'm all good for parts 2 and 3 using if-else but I've hit a bit of a roadblock with the yes/no option. I want the user to select the value of cake_burning variable via an JOptionPane.

Paul K.
  • 796
  • 2
  • 7
  • 20
RWCIII
  • 1
  • 2
  • 1
    So what have you tried? Post the code or a screenshot of what you have so far _for the part you need help with_. – Arc676 Nov 19 '15 at 10:52
  • i am not quite sure, but this could be a possible duplicate of [how do i compare string in java](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) since theyr topic seems to be the same. – SomeJavaGuy Nov 19 '15 at 10:54
  • Is "cake burning" a variable? What about making a boolean out of it? Otherwise I'd go with @KevinEsche, you actually need to compare strings: `if("Yes".equals(cake_burning) {//do stuff}` – Keews Nov 19 '15 at 10:58

2 Answers2

0

YES or NO is still only a choice of TRUE/FALSE responses.

You will still use your IF THEN scenario, substituting (even if only in your head) YES where you test for TRUE and NO where you test for FALSE.

You COULD define variables or constants for YES and NO if you wanted, but there's no need:

if (CakeBurning) then {     // cake is burning, true (or yes)
    Oven.power=0;
}

In most languages if (CakeBurning) will return the same as if (CakeBurning==TRUE)

Madivad
  • 2,999
  • 7
  • 33
  • 60
0

If you want the user to select if the cake is burning or not in a JOption pane, you can proceed like this.

int cake_burning = JOptionPane.showConfirmDialog(null,
             null, 
             "Is the cake burning?",
             JOptionPane.YES_NO_OPTION);

if(cake_burning == JOptionPane.YES_OPTION) {
    // turn the oven off
}
Paul K.
  • 796
  • 2
  • 7
  • 20