/*This is a program that calculates Internet advertising rates based on what features/options you choose.
*
*
*/
import java.util.Scanner;
public class Inter
A good way to avoid such issues is to set the to be assigned variable as final and uninitialized before the checks. This will force you to set a value before you can use/read it.
final textCostTmp;
if (condition1) {
textCostTmp = ...;
} else if (condition2) {
textCostTmp = ...;
}
// if you use textCostTmp here the compiler will complain that it is uninitialized !
textCost = textCostTmp;
To solve this DO NOT initialize the variable as you may miss the missing else case.
The only proper solution is to add an else case to cover all possible cases !
I consider it bad practice to initialize non final variables except for some rare scenarios like a counter in a loop.
The proposed approach will force you to handle all possible cases, now and in the future (easier to maintain). The compiler is a bit stupid at times (cannot figure that numberOfWords > 35 is the else)...but the compiler is your ally not your enemy...