00:01 - 00:04

let's jump into intellij

00:03 - 00:06

which is the environment we're going to

00:04 - 00:08

be programming programming in

00:06 - 00:10

for the rest of the class and so what

00:08 - 00:12

i'm going to do here is i've just

00:10 - 00:13

created the array of dogs that you did

00:12 - 00:15

in your exercise so it's just this array

00:13 - 00:18

right here

00:15 - 00:21

and when i run this it should print out

00:18 - 00:22

an array of dogs such as 20 and 22 but

00:21 - 00:25

as you'll note it's actually just

00:22 - 00:26

printing out all of the array

00:25 - 00:28

so the way that this works the reason

00:26 - 00:30

this is happening is that

00:28 - 00:31

our function larger than four neighbors

00:30 - 00:33

is supposed to return

00:31 - 00:35

only the big dogs the ones that are

00:33 - 00:37

bigger than their four neighbors

00:35 - 00:38

so this is just the code that gets those

00:37 - 00:39

and prints them but right now the

00:38 - 00:43

function simply returns

00:39 - 00:46

dogs so we need it so it returns

00:43 - 00:47

only uh the dogs which are larger than

00:46 - 00:49

their four neighbors

00:47 - 00:50

okay so it's clear that what we need to

00:49 - 00:52

do is something like

00:50 - 00:54

iterate over all the dogs right that

00:52 - 00:56

seems very natural

00:54 - 00:58

but this is a little tricky because i

00:56 - 01:00

need to iterate over the neighbors

00:58 - 01:03

so one way i could do this this may not

01:00 - 01:06

be your first thought but it's like well

01:03 - 01:09

if we do minus 2 to 2

01:06 - 01:11

then this should iterate

01:09 - 01:14

over the neighbors of the dog so for

01:11 - 01:17

example we could call this

01:14 - 01:19

neighbor dog that would be dogs i plus j

01:17 - 01:21

okay now we run into a problem

01:19 - 01:23

immediately we kind of see it here that

01:21 - 01:24

there's like a minus two thing where

01:23 - 01:28

like if this starts at zero

01:24 - 01:30

and this is minus 2 well then it can go

01:28 - 01:32

negative right like this could be a

01:30 - 01:33

negative value in fact if i look at this

01:32 - 01:35

it says there's a potential that the

01:33 - 01:35

array can go out of balance bounce one

01:35 - 01:37

of the things that's great about

01:35 - 01:38

intellij is it warns you about things

01:37 - 01:39

like this but

01:38 - 01:41

i don't know yeah so it's something i

01:39 - 01:43

need to deal with so i could do

01:41 - 01:48

something like if

01:43 - 01:51

i plus j is less than zero

01:48 - 01:54

then what should we do well

01:51 - 01:55

actually what we should do is i guess we

01:54 - 01:58

are going to

01:55 - 01:59

um continue right we're too early so

01:58 - 02:01

we're just going to say that

01:59 - 02:03

and continue along okay so if at least

02:01 - 02:05

handled we go off the array on the other

02:03 - 02:07

side

02:05 - 02:09

okay but then we also of course have the

02:07 - 02:12

issue like what if it's greater than

02:09 - 02:13

or equal to dogs.length okay well in

02:12 - 02:17

that case

02:13 - 02:18

uh i guess we can well we're at the end

02:17 - 02:20

of this loop right we don't need to be

02:18 - 02:21

iterating anymore so i can say break

02:20 - 02:23

and so i have this code here to

02:21 - 02:25

basically handle going out of bounds

02:23 - 02:26

okay already this code is getting pretty

02:25 - 02:28

complicated

02:26 - 02:29

and helper functions are going to make

02:28 - 02:30

our life easier but let's just keep

02:29 - 02:33

trying to write it okay

02:30 - 02:34

so now we get the neighbor dog um what

02:33 - 02:38

do we do now that we have this neighbor

02:34 - 02:40

dog i guess what we can do is

02:38 - 02:40

if

02:41 - 02:46

well the pattern might be something like

02:43 - 02:48

this i'm going to say boolean

02:46 - 02:51

let's say largest and by default we'll

02:48 - 02:53

say that by that we are the largest dog

02:51 - 02:55

but if it's ever the case that the

02:53 - 03:00

neighbor dog's weight in pounds is

02:55 - 03:00

greater than or equal to um

03:00 - 03:06

dogs dot or let's see dogs i

03:04 - 03:08

that's the current dog that weight in

03:06 - 03:12

pounds

03:08 - 03:15

then we will say largest equals false

03:12 - 03:19

okay um and then

03:15 - 03:21

once we get to the end so here in theory

03:19 - 03:23

what all this code does is when it's

03:21 - 03:28

done the largest value is true

03:23 - 03:29

only if the current dog is the biggest

03:28 - 03:31

now there's actually one other little

03:29 - 03:33

bug that i've spotted here that i like

03:31 - 03:37

you may not have noticed which is like

03:33 - 03:38

what if uh j is equal to zero

03:37 - 03:40

we don't wanna compare the neighbor dog

03:38 - 03:43

to ourself because you know like

03:40 - 03:45

we're gonna be greater than or equal to

03:43 - 03:48

ourself so we actually also need to say

03:45 - 03:49

for j equals zero uh we should continue

03:48 - 03:51

and that code's getting complicated then

03:49 - 03:54

we still have to do more work

03:51 - 03:54

now i think this is all just a little

03:54 - 03:56

messy

03:54 - 03:58

and the problem is that we were just

03:56 - 04:00

trying to like

03:58 - 04:01

make it up as we went along and we ended

04:00 - 04:04

up with something that is

04:01 - 04:05

you know i'd say a little clumsy okay we

04:04 - 04:07

can make this work

04:05 - 04:08

but let's try again okay so that's the

04:07 - 04:09

end of this video this is me trying to

04:08 - 04:12

do it

04:09 - 04:14

without thinking about a strategy

04:12 - 04:15

without thinking about a specific

04:14 - 04:17

thing i'd like to do i just started

04:15 - 04:17

writing code and i ended up with special

04:17 - 04:20

cases

04:17 - 04:21

and it being a little complicated and a

04:20 - 04:23

dangerous way to go

04:21 - 04:26

so next video we're going to start all

04:23 - 04:26

over and do it differently

Mastering IntelliJ: Writing Efficient Code for Finding Big Dogs

In this instructional segment, we delve into using IntelliJ as our primary programming environment to work on a class exercise involving an array of dogs. The goal is to create a function that identifies and returns only the big dogs amongst the array based on set criteria. However, as we navigate through the process, we encounter challenges that lead to complex and potentially error-prone code.

Identifying and Refining the Problem

As we run into the issue where the function is returning the entire array instead of just the big dogs, we realize the need to iterate over the dogs array and compare the size of each dog with its neighbors. This seemingly straightforward task unveils complexities, especially when handling the boundaries of the array. IntelliJ's warnings about potential out-of-bounds errors serve as useful reminders to address these issues promptly.

To tackle the problem efficiently, we attempt to determine a strategy that involves iterating over the neighbors of each dog. While a direct approach using a simple loop may seem plausible, we encounter pitfalls such as negative indexes and exceeding array bounds. By incorporating conditional statements like checking if the index is less than zero or greater than the array length, we strive to mitigate these concerns and ensure the code's robustness.

Streamlining the Code with Helper Functions

The evolving complexity of the code necessitates the consideration of employing helper functions to enhance readability and maintainability. Despite the intricate nature of the task at hand, adopting a strategic and organized approach is crucial to prevent the code from becoming convoluted and error-prone.

As we reflect on our initial attempt and acknowledge the inherent challenges of coding without a clear strategy in mind, we recognize the significance of reevaluating our approach. Moving forward, the focus will shift towards restructuring the code from scratch, emphasizing a methodical and premeditated coding process to achieve a more streamlined and effective solution.

In the upcoming segment, we will reset our approach, leveraging the lessons learned to craft a more efficient and structured code framework. By incorporating a well-thought-out strategy and utilizing IntelliJ's capabilities effectively, we aim to optimize the code implementation process and enhance our programming proficiency.

Let's embark on this journey of code refinement and optimization, paving the way for smoother problem-solving and improved coding practices in IntelliJ. Stay tuned for the next installment where we tackle the challenge with a fresh perspective and a structured plan in place.