Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Hi,

I am working on below challenge

http://codingbat.com/prob/p137365

i worote as below

i am failig one test as below

how to fix that and improve my approach and design of this challenge. How do i make a graphical venn or ascii diagram to proceed further. Please advise

I am working on below challenge

http://codingbat.com/prob/p137365

i worote as below

```
public boolean in1To10(int n, boolean outsideMode) {
if(n<=10&&n>=1){
return true;
}
else if(n<=1&&outsideMode==true){
return true;
}
else if(n>=10&&outsideMode==true){
return true;
}
else
return false;
}
```

i am failig one test as below

Expected Run

in1To10(5, false) → true true OK

in1To10(11, false) → false false OK

in1To10(11, true) → true true OK

in1To10(10, false) → true true OK

in1To10(10, true) → true true OK

in1To10(9, false) → true true OK

in1To10(9, true) → false true X

in1To10(1, false) → true true OK

in1To10(1, true) → true true OK

in1To10(0, false) → false false OK

in1To10(0, true) → true true OK

in1To10(-1, false) → false false OK

other tests

how to fix that and improve my approach and design of this challenge. How do i make a graphical venn or ascii diagram to proceed further. Please advise

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

has not tested outsideMode. Hint: start by making testing for outsideMode the first thing you do.`if(n<=10&&n>=1){ return true; }`

Also good methods have one exit point only (usually)

```
public boolean in1To10(int n, boolean outsideMode) {
if(n<=10&&n>=1 && outsideMode==false ){
return true;
}
else if(n<=1&&outsideMode==true){
return true;
}
else if(n>=10&&outsideMode==true){
return true;
}
else
return false;
}
```

i fixed and passing all tests. Please suggest how to improve my code. Description is too short and i have to read in between lines too to exactly understand to get below

has not tested outsideMode

Description is too short and i have to read in between lines too to exactly understand to get belowNonetheless, you fixed it by following my suggestion - but not quite in the way i meant.

Test ONLY for outsideMode at first. That will give you two code paths (outsideMode and !outsideMode) and your other code can go into those

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial```
public boolean in1To10(int n, boolean outsideMode) {
if(outsideMode){
return n <= 1 || n >= 10;
}
return n >=1 && n <= 10;
}
```

please advise

i tried as attached but not complete

vennDia.png

This table shows the answer you are trying to get

```
outsideMode
True | False
---+-------+-------
0 | True | False
---+-------+-------
1 | True | True
---+-------+-------
2 | False | True
---+-------+-------
3 | False | True
---+-------+-------
4 | False | True
---+-------+-------
5 | False | True
---+-------+-------
6 | False | True
---+-------+-------
7 | False | True
---+-------+-------
8 | False | True
---+-------+-------
9 | False | True
---+-------+-------
10 | True | True
---+-------+-------
11 | True | False
```

And this table shows some operators you might wish to combine in some way in order to get those answers:
```
<1 | <=1 | ==1 | >=1 | >1 | <10 | <=10 | ==10 | >=10 | > 10
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
0 | True | True | False | False | False | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
1 | False | True | True | True | False | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
2 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
3 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
4 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
5 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
6 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
7 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
8 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
9 | False | False | False | True | True | True | True | False | False | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
10 | False | False | False | True | True | False | True | True | True | False
---+-------+-------+-------+-------+-------+-------+-------+-------+-------+------
11 | False | False | False | True | True | False | True | False | True | True
```

I would also suggest you get out of the habit of using equality with Booleans. We've all grown up with "=" meaning equals but in Java "==" means equals and "=" is the assignment operator. Looking at the results we know that in1To10(9,true) returns false. But suppose, in our code we had something like if(outsideMode = false && n<=10 && 1<=n) return true, then in1To10(9,true) would return true because the "=" assigned the value of false to outsideMode even though our method call was for outsideMode to be true. Sooner or later you will end up doing something like that and not know why it's not working. Even to say if outsideMode == false is superfluous, just say if !outsideMode

has not tested outsideMode. Hint: start by making testing for outsideMode the first thing you do.

how to know which to start first.

how to draw venn diagram for this?

i tried but not right though.

- but not quite in the way i meant.

```
public boolean in1To10(int n, boolean outsideMode) {
if(outsideMode==true){
return true;
}
else if(n<=10&&n>=1){
return true;
}
else
return false;
}
```

i tried as above based on your advise but failing one test case```
Expected Run
in1To10(5, false) → true true OK
in1To10(11, false) → false false OK
in1To10(11, true) → true true OK
in1To10(10, false) → true true OK
in1To10(10, true) → true true OK
in1To10(9, false) → true true OK
in1To10(9, true) → false true X
in1To10(1, false) → true true OK
in1To10(1, true) → true true OK
in1To10(0, false) → false false OK
in1To10(0, true) → true true OK
in1To10(-1, false) → false false OK
other tests
OK
```

please advise
```
public boolean in1To10(int n, boolean outsideMode) {
if(outsideMode==true &&!(n<=10&&n>=1)){
return true;
}
else if(n<=10&&n>=1){
return true;
}
else
return false;
}
```

i tried as above still failing one

```
Expected Run
in1To10(5, false) → true true OK
in1To10(11, false) → false false OK
in1To10(11, true) → true true OK
in1To10(10, false) → true true OK
in1To10(10, true) → true true OK
in1To10(9, false) → true true OK
in1To10(9, true) → false true X
in1To10(1, false) → true true OK
in1To10(1, true) → true true OK
in1To10(0, false) → false false OK
in1To10(0, true) → true true OK
in1To10(-1, false) → false false OK
other tests
OK
```

please advise

in1To10(9, true) → false true XIs your question, "Why is the expected result false?" or is it "Why did the above code return true?"

If the former, what leads you to believe that the expected answer would not be "false"?

If the later, what leads you to believe that the above code would not return "true"?

Different misunderstandings may call for different explanations.

public boolean in1To10(int n, boolean outsideMode) {

if(outsideMode==true &&!(n<=10&&n>=1)){

return true;

}

else if(n<=10&&n>=1){

return true;

}

else

return false;

}

my question is above code written by me is not passing all test cases(failing only 1 for whatever reason). Is there is a way i can fix above code to make it pass all the tests? please advise

```
public boolean in1To10(int n, boolean outsideMode) {
if((n<=10&&n>=1)){
return true;
}
else if(outsideMode){
return true;
}
else
return false;
}
```

i modified as above which also failing one same test case

diagram.png

in1To10(9, true) → false

i think i need clarity on above as well

why for above test test expected result is false

As per description of challenge

Given a number n, return true if n is in the range 1..10, inclusive.??

Given a number n, return true if n is in the range 1..10, inclusive.Those criteria are invalidated as outsideMode is

By those criteria the result is false since 9 is NOT less than or equal to 1. Neither is it greater than or equal to 10

```
public boolean in1To10(int n, boolean outsideMode) {
boolean resuklt=false;
if(outsideMode){
if((n>=10 || n<=1))
resuklt=true;
else
resuklt=false;
}
if(!outsideMode){
if((n<=10 && n>=1))
resuklt=true;
else
resuklt=false;
}
return resuklt;
}
```

i passed as above.

'Unless' word is confused me.

Given a number n, return true if n is in the range 1..10, inclusive. Unless "outsideMode" is true, in which case return true if the number is less or equal to 1, or greater or equal to 10.

outside mode true means i have to use || as one condition is enough to see n less than 1 or n greater than 10

outside mode false (ie inside mode) means i have to use && as both conditions needed to be tested( greater than 1 and less than 10)

```
Expected Run
in1To10(5, false) → true true OK
in1To10(11, false) → false false OK
in1To10(11, true) → true true OK
in1To10(10, false) → true true OK
in1To10(10, true) → true true OK
in1To10(9, false) → true true OK
in1To10(9, true) → false false OK
in1To10(1, false) → true true OK
in1To10(1, true) → true true OK
in1To10(0, false) → false false OK
in1To10(0, true) → true true OK
in1To10(-1, false) → false false OK
other tests
```

```
public boolean in1To10(int n, boolean outsideMode) {
if(outsideMode){
if(n<=1||n>=10){
return true;
}
else
return false;
}
else{
if(n>=1&& n<=10){
return true;
}
else {
return false;
}
}
}
```

above also passed all

```
return (1<=n&&n<=10) ^ (outsideMode&&n!=1&&n!=10);
```

can you please advise above solution. I have not understood it.

cap ^ means either left or right is true then only true right XOR operator we discussed.

what is the need of != here?

But I would still prefer the solution of http:#a41241525, which more directly parallels the description of the problem.

It even places n outside the 1,10 in the outsideMode case, and inside the 1,10 in the !outsideMode case

ID: 41301625

i was not clear on above comment. what is row and column names here. I am pretty confused on the both tables esp column like 0, 1, 2,....what the mean??

And what the each cell boolean values mean?

The cell in the column corresponding to the value of outsideMode,

and the row corresponding to the value of n,

contains the Expected result of in1To10(n,outsideMode)

e.g, for in1To10(1, false)

n=1, outsideMode=false, and the Expected result is true

I'm not sure what seems ambiguous about that representation

But if you want to use a different representation that makes more sense to you,

then I would suggest using that instead.

There's nothing magical about any particular representation,

and anything that helps you to see what's going on can be useful.

Different representations may be helpful for different people or for different aspects of different problems.

But having more ways of looking at problems can make it easier to find one that seems a natural fit, or easier to shift from one to another.

If you think of a program as a way to transform one problem into another, then the goal can be to transform the given problem into a set of problems that have already been solved.

outsideMode

True | False

---+-------+-------

0 | True | False

---+-------+-------

1 | True | True

---+-------+-------

2 | False | True

---+-------+-------

3 | False | True

---+-------+-------

4 | False | True

---+-------+-------

5 | False | True

---+-------+-------

6 | False | True

---+-------+-------

7 | False | True

---+-------+-------

8 | False | True

---+-------+-------

9 | False | True

---+-------+-------

10 | True | True

---+-------+-------

11 | True | False

above is very clear.

<1 | <=1 | ==1 | >=1 | >1 | <10 | <=10 | ==10 | >=10 | > 10

+-------+-------+-------+-------+--- ----+----- --+------- +-------+- ------+--- ----

0 | True | True | False | False | False | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ -------

1 | False | True | True | True | False | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

2 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

3 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

4 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

5 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

6 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

7 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

8 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

9 | False | False | False | True | True | True | True | False | False | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

10 | False | False | False | True | True | False | True | True | True | False

---+-------+-------+-------+-------+ -------+-- -----+---- ---+------ -+-------+ ------

11 | False | False | False | True | True | False | True | False | True | True

in above i got row which represents first argument of the method which is n value which is fine.

Does not column values supposed to be outSide range boolean instead of below??

<1 | <=1 | ==1 | >=1 | >1 | <10 | <=10 | ==10 | >=10 | > 10

some of which may turn out to be useful, some of which may not, some of which may need to be combined with other tests to be useful.

But seeing them all at once may help you to find a useful combination, if you find it helpful to think visually.

!=1 and !=10 are missing from that table, but all the information they would provide is given in the ==1 and ==10 columns, (and it was not obvious what the natural order would be to place those columns if they were included)

There was also some judgement involved in deciding that columns like ==1000 might not be worth including in the table.

It may be less clear whether something like <11 or <=9 might be useful, so if you are so inclined you might wish to try adding them to see if they suggest any other solutions.

Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.