Question

CSSSKL 142 Lab 3 (Part 2) In this exercise you will write a method that takes...

CSSSKL 142 Lab 3 (Part 2)

In this exercise you will write a method that takes a "Scanner" object from main and uses it to ask the user to input tow integers using the keyboard, sums their square roots, and prints a statement based on what bucket the result is in. The possible buckets are "Less than 10", "Between 10 and 20", "Between 20 and 30", and "Great than 30." Negative integers should be rejected with the appropriate message printed to the user. The method is named "sqrtSumBucketer", and it should work as follows:

If user enters 23 16, then:

sqrtSumBucketer ( input ); //Should print " Less than 10"

If user enters 2 999, then

sqrtSumBucketer ( input ); //Should print " Greater than 30."

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

import java.util.Scanner;

public class CSSS142Lab3_2{

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter two integers: ");

int n1 = in.nextInt();

int n2 = in.nextInt();

sqrtSumBucketer(n1, n2);

}

public static void sqrtSumBucketer(int n1, int n2){

int sum = n1+n2;

double sqrtValue = Math.sqrt(sum);

if(sqrtValue<10)

System.out.println("Less than 10");

else if(sqrtValue>=10 && sqrtValue<=20)

System.out.println("Between 10 and 20");

else if(sqrtValue>20 && sqrtValue<=30)

System.out.println("Between 20 and 30");

else{

System.out.println("Greater than 30");

}

}

}

Add a comment
Know the answer?
Add Answer to:
CSSSKL 142 Lab 3 (Part 2) In this exercise you will write a method that takes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes...

    Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes as argument an integer corresponding to a number of seconds, computes the exact time in hours, minutes and seconds, then prints the following message to the screen: <inputseconds> seconds corresponds to: <hour> hours, <minute> minutes and <second> seconds Write another method called in Seconds that takes as arguments three integers: hours, minutes and seconds, computes the exact time in seconds, then returns the total...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount,...

    Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount, an integer specifying the number of “buckets” to return and numberLs, a list of numbers ) buckets should split the range of values in numberLs into bucketCount sub-ranges. Specifically buckets should return a list-of-lists of length bucketCount. Each list in the returned list-of-lists represents a “bucket”. Each bucket should contain the numbers from numberLs whose values are greater than or equal to min(numberLs) +...

  • In this lab, you will create one class named ArrayFun.java which will contain a main method...

    In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...

  • . Write a program that takes integers from the user one at a time. Assume the...

    . Write a program that takes integers from the user one at a time. Assume the input is some number of positive integers. The user will type in 0 to end the input and the 0 should not be counted as input. Your program should find how many times the user enters a multiple of 5 and then print it to the screen. If the input is 6 10 30 5 0, the output is 3 because 10, 30, and...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You...

    Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You should implement the following functions to print a rectangle shape. • print_rectangle(length, width, fillChar, hollow). This function will use draw_shape_line() function to print a rectangle shape with the given length and width, If the hollow is true, the shape will be hollow rectangle, otherwise a filled rectangle. This function must not interact with the user. For example, the call print_rectangle(5, 10, '*', False) should...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • LAB5 #1. Method and loop Write a method integerPower(base, exponent) that returns the value of baseexponent...

    LAB5 #1. Method and loop Write a method integerPower(base, exponent) that returns the value of baseexponent (2 pts). For example, integerPower(3, 4) returns 81. Assume thatexponent is a positive nonzero integer, and base is an integer. Method integer should use for or while loop to control the calculation. Do not use any Math library methods. Incorporate this method into a program class and invoke this method with different combinations of input values at least 4 times. Please use printf() method...

  • In Java, Using arrays. You are going to write a program that will play a solitaire...

    In Java, Using arrays. You are going to write a program that will play a solitaire (one-player) game of Mancala (Links to an external site.) (Links to an external site.). The game of mancala consists of stones that are moved through various buckets towards a goal. In this version of mancala, the user will be able to choose a number of buckets and a number of stones with which to set up the game. The buckets will be created by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT