Write a program that will call 2 methods from main, but will also ask the user a question between the 2 method calls, and will pass a value to the second method call:
- Get a number between 20 and 30, inclusive, from the user.
Validate that the number entered is indeed in the valid range.
- Once you have a valid number, pass it the method called sumOfNumbers(validNum)
In the displayLoveMessage() method,
- Ask user for their first name
- Convert their first name to upper case
- Ask user for their significant other’s first name
- Convert their significant other’s first name to upper case
- Get the first initial of each name (hint: Use charAt )
- Concatenate the first initial of user’s name with “ loves “ and the first initial of significant other.
- For example, when the user enters “Mary” and then “John” the method will sout “M loves J”
In main, after calling displayLoveMessage() method, ask the user for a number between 20 and 30, inclusive, and keep asking the user that question until a valid number is entered by the user.
In the sumOfNumbers(int validNum) method,
- Use the validNum as the limit of a loop that starts at 1 and loops until validNum, inclusive, printing only the numbers that are divisible by 5.
- For example if the parameter is 20, then the following numbers would be printed, because they range from 1 to 20, and are divisible by 5:
5 10 15 20
- Hint: Use modulus division in an if-statement within a loop
- Add each of the numbers divisible by 5 into a sumOfNums variable, and count how many numbers are divisible by 5 using the countOfNums.
- After the loop is over:
- Display the sumOfNums
- Calculate the average of the sumOfNums divided by the countOfNums
- Display the average like this:
“The average of all numbers divisible by 5, starting from 1 to “ + validNum + “ is “ + average