Below is code which defines and creates an Array, myList: int [] myList = new int [5]; //define and createThe loop below stores the values 1 to 5 in myList:for (int i = 0; i < 5; i ++) {myList [ i ] = i + 1; //store values using a loop}The loop below prints the values from first to last in myList:for (int i = 0; i < myList.length; i++) { System.out.print(myList [ i ] + " ");}The code below is used to get user from the user and calculate the sum:import java.util.*;public class WhileWithInput {public static void main(String[] args) {Scanner reader = new Scanner (System.in);int count = 1; double total = 0; while (count <= 5) {System.out.println("Enter a decimal number"); double number = reader.nextDouble();total = total + number;count = count + 1;System.out.println("The total is " + total); }System.out.println("The total is " + total); }}1CPS 2231 Chapter 7 – lab 2 Fall 2019Use the examples on page 1 to complete the lab below. Please submit a screen print of the Eclipse editor showing your code and output with answers:Write a Java class, XXX_Lab75, where XXX is your Kean email ID. The class will do the following:1) Consist of two methods: a. mainb. printHigherThanAveragepublic static void printHigherAverage(double [] numbers, double avg)The method will print all the numbers in the array, numbers, which are higher than the average.2) In the main methods, create an Array which can contain 5 elements of type double3) In a loopa. Ask the user for 5 values using a Scanner. b. Store the values in the arrayc. Sum the values4) At the end of the loop:a. Calculate the average.b. Call the method printHigherAverage and pass it the array andthe average.

Question
Asked Sep 15, 2019
135 views

Below is code which defines and creates an Array, myList: int [] myList = new int [5]; //define and create
The loop below stores the values 1 to 5 in myList:
for (int i = 0; i < 5; i ++) {
myList [ i ] = i + 1; //store values using a loop
}
The loop below prints the values from first to last in myList:
for (int i = 0; i < myList.length; i++) { System.out.print(myList [ i ] + " ");
}
The code below is used to get user from the user and calculate the sum:
import java.util.*;
public class WhileWithInput {
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
int count = 1; double total = 0; while (count <= 5) {
System.out.println("Enter a decimal number"); double number = reader.nextDouble();
total = total + number;
count = count + 1;
System.out.println("The total is " + total); }
System.out.println("The total is " + total); }
}
1
CPS 2231 Chapter 7 – lab 2 Fall 2019
Use the examples on page 1 to complete the lab below. Please submit a screen print of the Eclipse editor showing your code and output with answers:
Write a Java class, XXX_Lab75, where XXX is your Kean email ID. The class will do the following:
1) Consist of two methods: a. main
b. printHigherThanAverage
public static void printHigherAverage(double [] numbers, double avg)
The method will print all the numbers in the array, numbers, which are higher than the average.
2) In the main methods, create an Array which can contain 5 elements of type double
3) In a loop
a. Ask the user for 5 values using a Scanner. b. Store the values in the array
c. Sum the values
4) At the end of the loop:
a. Calculate the average.
b. Call the method printHigherAverage and pass it the array and
the average.

check_circle

Expert Answer

Step 1

Writing a java program with class name XXX_Lab75. This class consists of two methods:

First method is main, and second method is printHigherThanAverage. printHigherThanAverage method is declared as:

public static void printHigherAverage(double [] numbers, double avg)

This method will print all the numbers in the array, numbers which are higher than the average.

In main method, creating an array which accepts 5 elements from user by using scanner, calculating sum, average of the array elements and displaying the number which is greater than average of array elements.

Step 2

Program code:

import java.util.Scanner;

public class XXX_Lab75

{

public static void main(String args[])

   {

       //Creating an array with double datatype

       double[] array = new double[5];

       double sum = 0;

       double avg;

       //Creating object of Scanner class

       Scanner sc = new Scanner(System.in);

       //Taking input of array elements by the user

       for(int i=0; i<5; i++)

       {

           //Reading entered element

           System.out.print("\n Enter a number: ");

           array[i] = sc.nextDouble();

         

           //Adding array elements

           sum = sum + array[i];

       }

       //Calculating average of the array elements

       avg = sum / 5.0;

      System.out.println("\n Average of the array:" +avg);

       //Calling printHigherAverage method

       printHigherAverage(array, avg);

   }

   //Method that prints values which is greater than average of array elements

   publ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Show a derivation tree for the string aabbbb with the grammar S→AB|λ,A→aB,B→Sb.

A: Given:Grammar: S → AB | λ, A → aB, B → SbString: aabbbbLet us take a top-down approach,Starts with t...

question_answer

Q: compare and contrast symmetric encryption with public-key encryption, including the strengths and we...

A: DefinitionEncryptionIn cryptography, encryption is basically a concept related to keys. It is a tech...

question_answer

Q: Find a regular grammar that generates the language on Σ = {a, b} consisting of all strings with no m...

A: Regular grammar for the language Σ = {a, b} is as follows:

question_answer

Q: #include#include#includeusing namespace std;// outputHtmlTitle// parameters// This function...void o...

A: We need to print the html, head and title tag in the outputHtmlTitle() method.The outputHtmlTitle() ...

question_answer

Q: 5-18) (Display four patterns using loops) Ask the user to enter an integer toset a limit for nested ...

A: The algorithm would run into 4 sections for each pattern. For patterns A and C each line will have i...

question_answer

Q: l Sprint LTE 09:28 9 morgan.blackboard.com Bb Courses Course Material Assignment 3 1. Use the variab...

A: Hey, since there are multiple questions posted, I answer first three questions. If you want any spec...

question_answer

Q: Please trace the code and give the correct output

A: Program Instructions:After adding the necessary cstring header file and formatting the output, the p...

question_answer

Q: For this program you need to use Eclipse. Carefully read the instructions and write a program that r...

A: The program has the following algorithm: Step 1: Create object for “Scanner” class to read the user ...

question_answer

Q: Explain the following error message. $ lsabc abd abe abf abg abh$ rm abc ab*rm: cannot remove ‘abc’ ...

A: “rm” command: This command is used to removes each specified file on the command line.For example, i...