-3

I have 3 conditions based on my Boolean values.

Condition 1: When the value is false, the user should get a blank form with a submit button

Condition 2: When the user submits the form, the Boolean value is set to true and the form becomes a read only form, so that the user cannot edit the form and resubmit. At this point of time, the submit button is hidden.

Condition 3: Suppose it is absolutely necessary to make an update, the owner of the application can go to the database and change the value of Boolean bit to false, so that the form becomes editable. But at this point of time, I need the Submit button to change to Modify button.

So there are 3 possibilities here with only 2 Boolean values. So my question is, how can I know between the two false calls (Condition 1 and Condition 3) that which one is Submit call i.e the user is filling the form for the first time and which one is Modify call i.e user is updating the same form? Any help is appreciated. Thank you.

RamPrakash
  • 1,687
  • 3
  • 20
  • 25
Anan
  • 181
  • 1
  • 2
  • 14
  • Make the return a boxed `Boolean`, and return null for one of the conditions, or return 1, 0, -1 if you aren't strictly required to use a boolean value. – Carcigenicate Feb 17 '17 at 13:37
  • You could use Integer as state – MikeKeepsOnShine Feb 17 '17 at 13:39
  • 1
    This is a typical home work question, it's better if you solve it by your own, you will learn concepts. – Sanjit Kumar Mishra Feb 17 '17 at 13:48
  • You could use a bitmask. 000 (0) being no bit set. 111 (7) being all bits set. 010 (2) only bit 2 is set. 110 (6) only bit 2 and 3 are set. And so on. The math on how to do is described in many texts about `binary bitwise operations`. – Phantômaxx Feb 17 '17 at 13:52

2 Answers2

2

You need Enum https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html .

Please have a look

Mithilesh Gupta
  • 2,800
  • 1
  • 17
  • 17
1

You can use integer instead of boolean with state of 1, 2 ,3 and store this. or you can add another boolean for modifying state.

with switch case you can handle situations

switch(state){
    case 1:
    //your code for state one
    break;
    case 2:
    //your code for state one
    break;
    case 3:
    //your code for state one
    break;
}
Siavash Abdoli
  • 1,852
  • 3
  • 22
  • 38