Question: In JAVA: Method main() should: 1. In the main method call the following methods: a. comparison(); b. forLoop(); c. whileSwitch(); Write method comparison() to do
In JAVA:
Method main() should:
1. In the main method call the following methods:
a. comparison();
b. forLoop();
c. whileSwitch();
Write method comparison() to do the following:
1. Return type of void
2. Declare as static
3. Empty parameter list
4. Instantiate and instance of class Scanner, pass as an argument to the constructor the value System.in
5. Declare two variables of primitive data type int representing two numbers
6. Using method System.out.println(), prompt the user to enter an integer
7. Store the value in one of the variables of primitive data type int by setting it equal to method nextInt() in class Scanner
8. Using method System.out.println(), prompt the user to enter a second integer
9. Store the value in the second variable of primitive data type int by setting it equal to method nextInt() in class Scanner
10. Using the comparison operators, determine if the two variables of primitive data type int are
a. Equal
b. Not equal
c. Less than
d. Greater than
e. Less than or equal to
f. Greater than or equal to
Output to the console the results of each comparison
Write method forLoop() to do the following:
1. Return type of void
2. Declare as static
3. Empty parameter list
4. Declare the following variables all of primitive data type double
a. amount = 0;
b. principle;
c. rate;
d. time;
e. ci;
f. t = 1;
5. Instantiate and instance of class Scanner, pass as an argument to the constructor the value System.in
6. Using method System.out.println(), prompt the user to enter the initial principle investment
7. Store the value in the variable principle by setting it equal to method nextDouble() in class Scanner
8. Using method System.out.println(), prompt the user to enter the interest rate
9. Store the value in the variable rate by setting it equal to method nextDouble() in class Scanner
10. Using method System.out.println(), prompt the user to enter the number of years of the investment
11. Store the value in the variable time by setting it equal to method nextDouble() in class Scanner
12. Update the value of variable rate by setting it equal to the calculation (1 + rate / 100) to generate a percentage value
13. In a for loop
a. Loop for the number of years stored in the variable time
b. Set variable t equal (t * rate)
14. Update variable amount setting it equal to the calculation (principle * t)
15. Output to the user the amount
16. Calculate the compounded interest, setting variable ci equal to the calculation (amount principle)
Output to the user their compounded interest
Write method whileSwitch() to do the following:
1. Return type of void
2. Declare as static
3. Empty parameter list
4. Declare the following variables all of primitive data type int
a. day
b. rain
5. In a while loop that loops for seven days
a. In a switch that evaluates the variable day
i. If case 0
1. Output to the console Sunday we got 1 inch of rain
2. Update variable rain to equal (rain + 1)
ii. If case 1
1. Output to the console Monday we got 2 inches of rain
2. Update variable rain to equal (rain + 2)
iii. If case 2
1. Output to the console Tuesday we got 3 inches of rain
2. Update variable rain to equal (rain + 3)
iv. If case 3
1. Output to the console Wednesday we got 4 inches of rain
2. Update variable rain to equal (rain + 4)
v. If case 4
1. Output to the console Thursday we got 5 inches of rain
2. Update variable rain to equal (rain + 5)
vi. If case 5
1. Output to the console Friday we got 6 inches of rain
2. Update variable rain to equal (rain + 6)
vii. If case 6
1. Output to the console Saturday we got 7 inch of rain
2. Update variable rain to equal (rain + 7)
viii. Default case
1. Output to the console that the value is not valid
b. Increment the looping variable day by 1
Output to the console how much rain was received in the past week
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
