First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).
Then create a new Java application called "AverageWithMethods" (without the quotation marks) according to the following guidelines.
The program prompts the user for five to ten numbers, all on one line, and separated by spaces. Then the user calculates the average of those numbers, and displays the numbers and their average to the user.
The program uses methods to:
The first method should take no arguments and return a String of numbers separated by spaces. [CASE 2]
The second method should take a String as its only argument and return a double (the average). [CASE 4]
The third method should take a String and a double as arguments but have no return value. [CASE 3]
For example, if the user input is... 20 40 60 80 100
...the program should give as output... The average of the numbers 20 40 60 80 100 is 60.00.
BE SURE TO INCLUDE THE OUTPUT FROM MULTIPLE PROGRAM RUNS AS A COMMENT BLOCK AT THE BOTTOM OF YOUR SOURCE CODE FILE.
Open netbeans and create a new project name "AverageWithMethods", by using the below given steps:
The below given java program will obey the following rubrics:
Program code:
//importing necessary header files
import java.util.Scanner;
//main class
public class Sample {
//defining a method with return type string
public static String readNumbers() {
//instantiating scanner class
Scanner scnr = new Scanner(System.in);
//declaring string variable for taking input
String input;
//displaying message to user to enter number
System.out.println("Enter five to ten numbers, all on one line and separated by spaces: ");
//taking input of number from user
input = scnr.nextLine();
//returning inputs
return input;
}
//defining method average
public static double avg(String input) {
//storing the numbers in string by using split function
String numbers[] = input.split(" ");
//declaring sum variable for storing sum of user entered value
double sum = 0;
//for loop
for (int i=0; i<numbers.length; i++) {
//storing result in the sum variable
sum += Double.parseDouble(numbers[i]);
}
//returning average of the ca...
Q: Within the NTDS folder, which file stores the main Active Directory database? Group of answer choice...
A: Within the NTDS folder, the “Ntds.dit”file stores the main Active Directory database .Hence, option ...
Q: Question 5, output in C++
A: C++ PROGRAM:#include<iostream>void swap(int a, int b) {int tmp = b;b = a; a = tmp;return;}void...
Q: In Python Define a function writeScores with two parameters. The first should be the name of a file,...
A: Below is the approach and python code:Approach:Define a function “writeScores” having two parameters...
Q: Write a Java program that prompts the user for the page size used in a virtual memory system; this w...
A: A Java program that accepts a valid system page size and virtual address and calculates the page num...
Q: What folder contains group policy templates, logon/logoff scripts, and DFS synchronization data? Gro...
A: “System Volume (SYSVOL)” folder contains group policy templates, logon scripts, and Distributed File...
Q: WRITE A SHORT NOTE ON THE PRIMITIVE COMPONENTS OF BITCOIN VALUE CHAIN?
A: Bitcoin Value Chain can be defined with the help of three terms BlockChain, Private Keys and third M...
Q: Write a method named sumInts that can take a variable number of int arguments and return the sum of ...
A: Below is the approach, and a java program to display the sum of integer arguments, passed in the sum...
Q: What 1s the output of the following code! { String myStr = new String("Cheggers2019") ; System.out.p...
A: There seems to be some error in the question, hence we are proceeding with a small assumption on our...
Q: In MS Access, to ensure that a grade must be either A, B, C, D or F, whichvalidation rule should be ...
A: Microsoft (MS) AccessMicrosoft access is a database management system from Microsoft that combines r...