Question: Part 0 - Download Code Template Download the following code template files for use as starter code: Lab 4 . java Download Lab 4 .
Part Download Code Template
Download the following code template files for use as starter code: Labjava Download Labjava
As you progress through the lab, look over the relevant starter code file and make sure you know what material has been provided for you.
Part
Starting with one grain of rice, double the number of grains of rice you receive each day. If a king paid you for days, how many grains of rice would you have? Write a short, method with the name countGrains that calculates and prints the number of grains you earn each day and the running sum of all the grains to date.
Note: Do you observe anything unusual in your output when you run your code? Explain, in comments.
Day and you got grains of rice for a total of grains
Day and you got grains of rice for a total of grains
Day and you got grains of rice for a total of grains
Day and you got X grains of rice for a total of Y grains
Day and you got X grains of rice for a total of Y grains
Day and you got X grains of rice for a total of Y grains
Part
Single Loops
Write a method powerOfTwo that takes an integer argument named exponent and prints to the console what is raised to the exponent. For example,
powerOfTwo; should print: to the power of is
powerOfTwo; should print: to the power of is
Note: you are not allowed to use any library functions!
Write a method numBackward that reverses the digits of a given integer that is an integer passed in as an argument Use a single loop and modular arithmetic to accomplish this goal. If you don't want to use modular arithmetic, you can also use String methods. Play around with ideas on paper first. After you reverse the digits, compare the number you got with the original argument and determine if the original argument is a palindrome. Your method should print a message to the screen that states the reversed number and whether or not it is a palindrome. For example,
numBackwardshould print: "backward: not palindrome!"
numBackwardshould print: "backward: palindrome!"
Part
Nested Loops
In this section, well produce more complex output by wrapping one loop inside another. This socalled nesting produces more complex results at the cost of increasing program complexity, and in the worst case can make some programs intractable. Well limit our degree of nesting to k here to get started. Build a method called StraightLine that produces a straight line, just as in loop in section above. Use a loop variable called size to terminate the loop. The output should look like:
size
size
Now, wrap this loop that produces a line inside another loop, as demonstrated in loop in section Make the outer loop also terminate using the "size" variable. The only thing to add to the outer loop is a System.out.println; to move the cursor to the next line. When youre done, the output should look like the square below, with the same number of rows and columns.
size
size
Part
Nested Loops
Write a method called BoxMaker that asks the user for an integer x using Scanner and then builds a box of x asterisks. For example, if x then your output would be:
x
inner body" : x numLidson each side x
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
