Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program in a file called NumberArrayTwo.java that will generate the appropriate output . OUTPUT: How many rows in your array ?:4 How many

Create a program in a file called NumberArrayTwo.java that will generate the appropriate output .

OUTPUT:

How many rows in your array ?:4 How many columns in your array ?:3 Printing Two Diminsional Array Values Array Value [0][0] = 50 Array Value [0][1] = 100 Array Value [0][2] = 150 Array Value [1][0] = 200 Array Value [1][1] = 250 Array Value [1][2] = 300 Array Value [2][0] = 350 Array Value [2][1] = 400 Array Value [2][2] = 450 Array Value [3][0] = 500 Array Value [3][1] = 550 Array Value [3][2] = 600 Sum is 3900 Average is 975 Printing Two Diminsional Array Values Array Value [0][0] = 2 Array Value [0][1] = 4 Array Value [0][2] = 6 Array Value [0][3] = 8 Array Value [0][4] = 10 Array Value [1][0] = 5 Array Value [1][1] = 10 Array Value [1][2] = 15 Array Value [1][3] = 20 Array Value [1][4] = 25 Sum is 105 Average is 52

**********************************

//NumberArrayTwo.java Program

package numberarraytwo;

import java.util.Scanner;

public class NumberArrayTwo { //create a two diminsional array attribute called wholeNumbers to store intergers

//create an overloaded constructor with a parameter to accept a two diminsiional array and initialize the attribute this.wholeNumbers //create an overloaded constructor with two int parameters: rows and columns { this.wholeNumbers = new int [rows][columns]; int initzValue = 0; for (int x=0; x < this.wholeNumbers.length; x++) for (int y=0; y < this.wholeNumbers[x].length; y++) this.wholeNumbers[x][y] = initzValue+=50; } //create a setter for the attribute //create a getter for the attribute

public void showNumbers() { int total = 0; System.out.println("Printing Two Diminsional Array Values"); for(int x = 0; x < wholeNumbers.length; ++x){ for(int y = 0; y < wholeNumbers[x].length; ++y){ System.out.println("Array Value [" + x + "][" + y+ "] = " + wholeNumbers[x][y]); total += wholeNumbers[x][y]; } } System.out.println("Sum is " + total); System.out.println("Average is " + (total / wholeNumbers.length) ); } // create an overloaded method called showNumbers with a int two diminsional array parameter called arrayofNumbers { int tot = 0; System.out.println("Printing Two Diminsional Array Values"); for(int x = 0; x < arrayOfNumbers.length; ++x){ for(int y = 0; y < wholeNumbers[x].length; ++y){ System.out.println("Array Value [" + x + "][" + y+ "] = " + arrayOfNumbers[x][y]); tot += arrayOfNumbers[x][y]; } } 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); int rows, columns; rows=columns=0; System.out.print(" How many rows in your array ?:"); rows = input.nextInt(); System.out.print(" How many columns in your array ?:"); columns = input.nextInt(); NumberArrayTwo inputNumbers = new NumberArrayTwo(rows, columns); inputNumbers.showNumbers(inputNumbers.getWholeNumbers()); int[][] someNums = {{2, 4, 6, 8, 10}, {5,10,15, 20, 25}}; NumberArrayTwo defaultNumbers = new NumberArrayTwo(someNums); defaultNumbers.showNumbers(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

Guidelines for Informative Speeches?

Answered: 1 week ago