Extra Strength Methods.
Head First Java Edition ii Chapter v.
*We’d played around with variables, objects, and rudimentary programs before. In this chapter, we’ll look at For Loops, Random Number Generators, and parsing a string to an int. This chapter may differ from those that came before it. since we’ll be learning how to design a program today from the ground up.
*You should have a process/methodology for writing programs as a programmer. If you prefer, you can follow the steps below.
- Firstly figure out what the class is supposed to do.
- Should be list instance variables and methods.
- Next write a pre code for methods
- Write test code for methods.
- Implement the class
- Test the methods.
- Debug and reimplement as needed.
*You will write a class on these three items.

*A sort of pseudocode that allows you to focus on the logic rather than the syntax is known as prep code. The majority of prep code is divided into three sections: instance variable declarations, method declarations, and method logic. The method logic is the most important part of the prep code since it describes what needs to happen, which we subsequently convert into how when writing the method code.

*Test code is a class or set of methods that checks if the real code is doing the right thing. It was best to start with the test code and then move on to the actual code. Despite the fact that the test code won’t be able to be compiled until the real code is developed, this ensures that you develop the real code first and then test it as soon as possible.

*The term “real code” refers to the class’s actual implementation. This is where the real Java code is written. You can test your code using the methods you’ve already completed to confirm that you’re getting the desired results from the methods.

Converting String to Int,

Random and getUserInput(),
- Make a random Number.

*(int) is used to convert the number to an int. In addition, this formula returns a value ranging from 0 to 4.
Get a user input,
String guess = helper. GetUserInput(“enter a number”);
GetUserInput function asks the user to command line Input.
For loops,
Regular (non-enhanced) for Loops.

Initialization,
*In this section, declare and initialize a variable to use in the loop body. The most typical application of this variable is as a counter. This approach can be used to build up a lot of variables.
Boolean test,
*This is where the conditional test is carried out. It makes no difference what’s inside; it must resolve to a Boolean value (you know, true or false). You can use a test (such as I >= 4) or a method that returns a Boolean value to do this.
Iteration expression,
*It alters the value of the variable by raising or lowering it. It’s a condition that can be reversed.
Enhanced For Loops,

- Create a String variable called name and set it to null.
- Assign the first value in name Array to name.
- Run the body of the loop .The code is bounded by {}
- Assign the next value in name Array to name.
- Repeat while there are still elements in the array.
Key points,
- Adding 1 from a variable. i++; is the same as: i= i+ 1;
- Using the pre or post decrement to subtract 1 from a variable (i- -;).
References,
[1]Sierra, Kathy, and Bert Bates. “Head First Java™ Second Edition.” (2021)