follow the document to complete the java programCSE 174 Lab 9
Part1:
Consider the following sequence: 2, -3, 6, -7, 10, -11, 14, -15, 18, -19, …..
Here is how it has been created:
1. Start with count = 1.
2. If count is odd then output is: 2 * count, if count is even then output is: -(2 * count – 1)
3. Add one to count.
4. Repeat step 2-3 until it gets to a specific limit that is defined by you.
For example: If you pick a limit of 7:
1. count = 1 is odd number: 2 * 1 is 2
2. count = 2 is even number: -(2 * 2 – 1) is -3
3. count = 3 is odd number: 3 * 2 is 6
4. count = 4 is even number, -(2 * 4 – 1) is -7
5. count = 5 is odd number: 5 * 2 is 10
6. count = 6 is even number, – (2 * 6 – 1) is -11
7. count = 7 is odd number: 2 * 7 is 14
What if you choose the limit of 12? You should get the following numbers:
12: __2 -3 6 -7 10 -11 14 -15 18 -19 22 -23
The last number is: -23
Part2:
Below, you will be asked to write a program. Once that program is working, you will
modify the program to give it more functionality. Solve these in order.
Version 1: Create a class call Lab9, inside the main() method, write a code that asks the user
for a limit number, and then prints the sequence of numbers from the part1. Hint: You need a
loop and one if-else condition inside the loop to figure out whether or not count is even or odd.
It will be easier if you use for loop.
Format you code to look like this:
Version 2: Once version 1 is working correctly, add a method to your class and call it
isEven(num) that gets an int number and returns true if the number is even, and false otherwise.
Call this method inside your loop (which is inside the main method) and replace it with whatever
you had for checking whether or not count is even or odd.
Once written, test it to verify the sequences on part1. If your answers are correct, now go
ahead and do the next one.
Version 3: Once version 2 is working correctly, add a method and call it multiple3or7(num) that
gets an int number and returns true if the number is a multiple of 3 or 7.
Then, use that method inside your loop to count how many numbers are a multiple of 3 or 7.
Match the formatting below.
Version 4: Modify your code so that instead of one number, it gets two numbers; one for saying
what’s the start value of count, and one for where you want to stop your sequence. Match the
formatting below.
Now, modify your code so that it does not print the sequence, and only prints the last
line.
Version 5: Add another loop that repeats your whole code 5 times. So, your code asks you to
enter a start and end points 5 times and displays the multiple of 3 or 7, 5 times. Use the start
and end points from the following example, see if you get the same answers.
Version 6:
This time modify your code to find the maximum value between multiples of 3 and 7.
Hint: for this you don’t need to add another loop, and you need to find the max of multiples
outside the inner loop (loop from version 1-4), but inside the outer loop (loop from version 5).
Print the max value at the end. Your final output should look like this:
Submit the Version 6 code as Lab9.java file on canvas.
+1 Bonus point:
If you can also print the max value belongs to which step from 1 to 5.
If you have done the bonus part, submit this version as Lab9.java file on canvas.
Purchase answer to see full
attachment