Get startedGet started for free

Building a workflow

1. Building a workflow

So far, we've learned how to write custom methods, how to use loops, and how to add logic with conditional statements. In this video, we'll bring it all together to build a flexible workflow - something we'd use in real-world projects!

2. Double odd numbers, halve even numbers

We'll combine everything we've practiced: looping through data, using `if` and `else if` to make decisions, and calling our own methods to keep the code organized and reusable. For example, we might loop through a list of numbers, check whether each one meets a certain condition, and then send it into a method for further processing. Here, we have a method that doubles odd numbers and halves even numbers.

3. Method chaining

As we combine more logic in one place, we might want to use several built-in methods at once. That is called method chaining. It is when we call one method directly after another, on the same value. For example, if we want to compare two Strings without worrying about capitalization, we might write something like: `message.toLowerCase().equals(input)`. This returns the message converted to lowercase, then immediately compares it using `.equals()`. Method chaining keeps the code short and readable, and it's something one sees often in real-world Java code.

4. Structure

As our programs grow, how we structure our code really starts to matter. Breaking work into clear steps, using meaningful method names, and keeping logic grouped together not only makes your code easier to understand but also easier to update and maintain.

5. Let's practice!

Now let's practice combining loops, conditionals, and methods to build something that works from start to finish. Let's get into it!