Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. In the main class of your project, create the following methods. (a) Create a static void method that receives three integers and outputs them

image text in transcribedimage text in transcribedimage text in transcribed

3. In the main class of your project, create the following methods. (a) Create a static void method that receives three integers and outputs them in sorted order, largest to smallest from left to right. Tips: Compare with greater than or equal to (>=). There are six possible orderings of 3 values, so you should not need more than 5 nested if statements. (b) Create a static method that receives a question as a String, a correct answer as a String and a Scanner object that reads from the keyboard and returns a boolean value. Using the Scanner object, prompt the user to answer the question. If the user's input matches the correct answer, return true. Otherwise, return false. CMPS 260 Spring 2020 Programming Assignment #3 (2020-02-05) 2 of 4 (c) The Babylonian method of approximating a square root of n works by repeatedly performing the following calculation. nextGuess = (lastGuess + n / lastGuess) / 2 When nextGuess and lastGuess are almost the same, nextGuess is the approximate value of the square root of n. The initial value of lastGuess can be any positive value. Create a static method that receives a value for n and an initial guess* to use as the initial value of lastGuess, then uses the Babylonian method to approximate the square root of n. For this method, the approximate square root has been determined when nextGuess and lastGuess are within a difference of 0.0001. At this time, the approximated square root is the value in nextGuess, which is then returned by the method. Use a while loop to repeat the formula. * Check the initial guess and change any negative values to positive values. If the initial guess is zero, change it to 1. (d) Write a static void method that receives a positive integer and uses nested for-loops to display a right triangle made up of integers 1 to the number received. For instance, if the method receives 4, the triangle output would be as follows: 1 1 2 1 2 3 1 2 3 4 4. In the main method of your project, (a) Create a Scanner class reference variable and object that reads from the keyboard. (b) Prompt the user to input three numbers, then pass the numbers entered to the method of (3.a). (c) Call the method of (3.b) passing a question, the answer to the question and the Scanner object created in step (4.a). Call the method until the user answers with the correct answer. (d) Prompt the user to enter a number and a guess as to its square root, then pass the numbers entered to the method created in (3.c). Finally, output the approximate square root returned from the method. CMPS 260 Spring 2020 Programming Assignment #3 (2020-02-05) 3 of 4 Example Run 1 (with user input in red): Enter three integers separated by spaces: 1 2 3 3 2 1 Hard red fruit about the size of a softball. 3 2 1 Hard red fruit about the size of a softball. pear incorrect Hard red fruit about the size of a softball. apple correct Enter a number and a guess as to its square root: 6.7 2.3 approximate square root of 6.7 is 2.588498567646952 Enter a positive integer: 5 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Example Run 2 (with user input in red): Enter three integers separated by spaces: 57 28 57 57 57 28 Hard red fruit about the size of a softball. apple correct Enter a number and a guess as to its square root: 4 10 approximate square root of 4.0 is 2.00000927130158 Enter a positive integer: 3 1 2 1 2 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions