Question

I need to answer this question in two parts. Create an application containing an array that...

I need to answer this question in two parts. Create an application containing an array that stores 5 integers. The application should call five methods from Array2 class that in turn (1) display all the integers, (2) display all the integers in reverse order, (3) display the sum of the integers, (4) display all values less than a limiting argument, and (5) display all values that are higher than the calculated average value. Save the file as ArrayTest.java. Array2 needs to be a seperate class, with ArrayTest using an object to call the Array2 class.

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

Program :

import java.util.Scanner;
public class ArrayTest
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int i,n;
   int arr[] = new int[5];
   System.out.println("Enter 5 integers:");
   for(i=0;i<5;i++)
   arr[i]=sc.nextInt();
   Array2 obj =new Array2();
   obj.display(arr);
   obj.displayReverse(arr);
   obj.sumOfIntegers(arr);
   System.out.print("Enter a number to limiting:\n");
   n=sc.nextInt();
   obj.displaylimiting(arr,n);
   obj.higherThenavg(arr);
  
   }
}
class Array2
{
void display(int arr[])
{
int i;
System.out.println("All integers:");
for(i=0;i<arr.length;i++)
System.out.print(arr[i]+ " ");
}
  
void displayReverse(int arr[])
{
int i;
System.out.println("\nAll integers reverse order:");
for(i=arr.length-1;i>=0;i--)
System.out.print(arr[i]+ " ");
}

void sumOfIntegers(int arr[])
{
int i,sum=0;
for(i=0;i<arr.length;i++)
sum=sum+arr[i];
System.out.println("\nSum of all integers is: "+sum);
}
  
void displaylimiting(int arr[],int n)
{
int i;
System.out.println("The values are less then "+n);
for(i=0;i<arr.length;i++)
{
if(arr[i]<n)
System.out.print(arr[i]+ " ");
}
}
void higherThenavg(int arr[])
{
int i,sum=0,avg;
System.out.println("\nAll values that are higher than average:");
for(i=0;i<arr.length;i++)
sum=sum+arr[i];
avg=sum/arr.length;
  
for(i=0;i<arr.length;i++)
{
if(arr[i]>avg)
System.out.print(arr[i]+ " ");
}
}
  
}

Screenshot of the output:

Add a comment
Know the answer?
Add Answer to:
I need to answer this question in two parts. Create an application containing an array that...
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
  • java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array...

    java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array of 1000 integers. Name the array: x 2. Assign 95 to the ninth element, 25 to the twentieth element of array x. 3. Assign the sum of the ninth and the twentieth element to the sixtieth element of array x. 4. Display the sixtieth element of the array. 5. Use the for statement to generate all indexes to read and display all elements in...

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • ( Java Programming ) Write an application to simulate the rolling of two dice. The application...

    ( Java Programming ) Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12...

  • Create a class named Program10. Your program should have the following 4 methods (other helper methods...

    Create a class named Program10. Your program should have the following 4 methods (other helper methods are allowed, but these four methods must be implemented as specified). You need to define a global scanner object and only use it inside the main method and the getValues method, since other methods do not get any values from the input. getValues: This method does not have any input parameter and returns an array of integers. This method prompts the user with a...

  • Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1...

    Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1 - 100) and returns the maximum number, minimum number, average of all numbers, and prints a Bar Chart to show the number distribution (1-9, 10-19,20-29, …80-89, 90-100). Note; maximum number, minimum number, average number, and the Bar Chart must use implemented as separate methods in a separate class. Method call should pass an array as an argument. Methods should accept an array as an...

  • Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define...

    Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define a variable xVar (type: char, value: 65), and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In SubClass, define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass, as well as an additional method printAll, in which...

  • Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can...

    Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can i contact you? -------------------------- Program 1 - WRITE ALL THE CODE in ONE FILE...   MyArrayPtrArith1.cpp Step 1 - Define the class Write a class, myArrayClass, that creates an integer array. * Add an 'arraySize' variable, initialize to zero ( default constructor function ) * Create int * ptrArray ( default constructor set to NULL ) * Add a default constructor ( see above for...

  • For this assignment your job is to create a two class application that examines the concept...

    For this assignment your job is to create a two class application that examines the concept of a numerical palindrome. A numerical palindrome is a non-negative whole number that is the same forwards and backwards, e.g. 2332, 12321, etc. Here's the catch: suppose you do the following. Start with any positive whole number. If it's a palindrome, you're done; if it isn't, reverse the number, add the reversal to the original value, and test this new result. It it's a...

  • C++ Program 1. Create a class named BaseballGame that has fields for two team names and...

    C++ Program 1. Create a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Your application declares an array of 12 BaseballGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or “Tie” if the score is a tie. (main.cpp,...

  • Here's an assignment that'll give you some practice with pointers. All you have to do is...

    Here's an assignment that'll give you some practice with pointers. All you have to do is write a program that allows the user to populate an array of doubles (5 values) by calling the function InitArray. After the user has entered all the values, then call the function DispRevArray to display the array in reverse. Main will create and allocate space for an array of type double for 5 elements. Then you will create and allocate a pointer that will...

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