Question
Create a program called NumberArray.java OUTPUT: What size array would you like?: 3 Printing Single Diminsion Array Values Array Value [0] = 200 Array Value
Create a program called NumberArray.java
OUTPUT: What size array would you like?: 3 Printing Single Diminsion Array Values Array Value [0] = 200 Array Value [1] = 300 Array Value [2] = 400 Sum is 900 Average is 300 Printing Single Diminsion Array Values Array Value [0] = 4 Array Value [1] = 17 Array Value [2] = 22 Array Value [3] = 8 Array Value [4] = 35 Sum is 86 Average is 17
************************************
// Program NumberArray.java
package numberarray;
import java.util.Scanner;
public class NumberArray { //declare a single diminsion array to store integers called wholeNumbers
//create an overloaded constructors with the parameter int size { this.wholeNumbers = /*initialize with an array of integers based on the size parameter */ int initzValue = 100; for (int x=0; x < this.wholeNumbers.length; x++) this.wholeNumbers[x] = initzValue+=100; } //create an overloaded constructor with the parameter int [] wholeNumbers public NumberArray( int [] wholeNumbers) { this.wholeNumbers =/* initialize with the passed in parameter */ }
//create a setter for the attribute wholeNumbers
//create a getter for the attribute wholeNumbers //created an overloaded method called showNumbers without parameters and a void return type { int total = 0; System.out.println("Printing Single Diminsion Array Values"); for(int x = 0; x < /*create a for loop based on the length of the array wholeNumbers */ ; ++x){ System.out.println("Array Value [" + x + "] = " + wholeNumbers[x]); total += wholeNumbers[x]; } System.out.println("Sum is " + total); System.out.println("Average is " + (total / wholeNumbers.length) ); } //created an overloaded method called showNumbers with a parameter of int [] arrayOfNumbers and a void return type { int tot = 0; System.out.println("Printing Single Diminsion Array Values"); for(int x = 0; x < arrayOfNumbers.length; ++x){ System.out.println("Array Value [" + x + "] = " + /*display the array element based on x */ ); tot += /*assign the array element based on x */ } System.out.println("Sum is " + tot); System.out.println("Average is " + (tot / arrayOfNumbers.length) ); } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(" What size array would you like?: "); NumberArray inputNumbers = new NumberArray(input.nextInt()); inputNumbers.showNumbers(inputNumbers.getWholeNumbers()); // create an int array called someNums and initialize it to 4, 17, 22, 8 and 35 NumberArray defaultNumbers = /*use the new operator and call the overloaded constructor NumberArray, passing the array someNums */ defaultNumbers.showNumbers(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started