Chegg I need your expert help once again on my week 8 assignment. I submitted my
ID: 3855682 • Letter: C
Question
Chegg I need your expert help once again on my week 8 assignment. I submitted my assignment and got the below comments from my instructor.
"You are close. I am not sure where you picked this up: Console con = System.console(); We do not use that in here. Use the proper input methods as we have been all along. Instantiate a scanner object and use the variable you declared. Also, always declare variables on separate line: String c, d = "Y"; (you will not need d and do not set c = "Y". Simply declare a string c to use for your do/while loop condition. So, implement the scanner object. Drop the use of console. Your while condition should be: while (c.equalsIgnoreCase("Y")); Make those changes and it works as it should. However, there are some spacing issues on your output that need to be addressed and you have no method headers which were covered in the week 6 modules (The last one I believe) so make sure you add those."
The book for the class is Introduction to Java Programming, Comprehensive Version Y. Daniel Liang & Prentice Hall 11th Edition / 2018. We are currently working in Chapter 10. Below is my Code
package jwabby_week8_multidemensional_arrays;
/**
* @Course: SDEV 250 ~ Java Programming I
* @Author Name: Justin Wabby
* @Assignment Name: jwabby_week8_multidemensional_arrays
* @Date: Jul 5, 2017
* @Description: Week 8 Multidemensional Arrays
*/
//Imports
import java.io.Console;
//Begin Class Jwabby_Week8_Multidemensional_Arrays
public class Jwabby_Week8_Multidemensional_Arrays {
//Begin Main Method
public static void main(String[] args) {
Console con = System.console();
int i;
String c, d = "Y";
do {
System.out.print("Enternumber of rows & columns (they will be the same)");
i = Integer.parseInt(con.readLine());
int arr[][] = new int[i][i];
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
System.out.print("Enter value for row" + (j + 1) + ",column " + (k + 1) + ": ");
arr[j][k] = Integer.parseInt(con.readLine());
}
}
System.out.println("The Matrix ******** ****************");
System.out.println("You entered the following matrix");
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
System.out.print(arr[j][k] + " ");
}
System.out.println();
}
sumofrows(arr, i);
sumofcolumns(arr, i);
productofrows(arr, i);
productofcolumns(arr, i);
max(arr, i);
min(arr, i);
System.out.print("Enter another Matrix (Y or N)");
c = con.readLine();
} while (c.equals(d));
System.out.print(" Thank you for using the program! Goodbye!");
}
public static void sumofrows(int arr[][], int i) {
int sum = 0;
System.out.println("Row Totals *****************");
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
sum = sum + arr[j][k];
}
System.out.println("sum of row " + (j + 1) + "is " + sum); sum = 0;
}
}
public static void sumofcolumns(int arr[][], int i) { int sum = 0;
System.out.println("Column Totals *****************");
for (int k = 0; k < i; k++) {
for (int j = 0; j < i; j++) {
sum = sum + arr[j][k];
}
System.out.println("sum of Column " + (k + 1) + "is " + sum); sum = 0;
}
}
public static void productofrows(int arr[][], int i) {
int product = 1;
System.out.println("Row products *****************");
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
product = product * arr[j][k];
}
System.out.println("Product of row " + (j + 1) + "is " + product);
product = 1;
}
}
public static void productofcolumns(int arr[][], int i) {
int product = 1;
System.out.println("Column products *****************");
for (int k = 0; k < i; k++) {
for (int j = 0; j < i; j++) {
product = product * arr[j][k];
}
System.out.println("sum of Column " + (k + 1) + "is " + product);
product = 1;
}
}
public static void max(int arr[][], int i) {
int max = 0;
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
if (arr[j][k] > max) {
max = arr[j][k];
}
}
}
System.out.println("The greatest value in the matrix is : " + max);
}
public static void min(int arr[][], int i) {
int min = arr[0][0];
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
if (arr[j][k] < min) {
min = arr[j][k];
}
}
}
System.out.println("The Lowest value in the matrix is : " + min);
} //End Main Method
} //End Class Jwabby_Week8_Multidemensional_Arrays
Write a program that accepts an n x n matrix. The program should also:
1. Total and display the sum of each row and each column
2. Find the product of each row and column
3. Find the highest and lowest value within the array
Constraints
The number of rows and columns should be the same
Use nested for loops and methods Requirements
Build your matrix based upon user input (e.g., ask how many rows and columns - they must be the same)
Use a method to display the matrix (use tabs between each element)
Create methods to display the following:
o Method 1: The sum of each row
o Method 2: The sum of each column
o Method 3: The product of each row
o Method 4: The product of each column
o Method 5:The highest value in the matrix
o Method 6:The lowest value in the matrix
Loop the program to run it until the user wishes to exit
In the example below, the numbers ARE NOT hard coded. Your program should ask the user for input
This program should utilize code learned from Week 1 through Week 8
Hints
Make sure you use Java coding conventions
Expected Output
The following pages show a sample run with two iterations. User input is in BOLD.
Welcome! This program that accepts an n x n matrix, totals the rows and columns & finds the product of each row and column.
Enter number of rows & columns (they will be the same): 2
Enter a value for Row 1, Column 1: 3
Enter a value for Row 1, Column 2: 8
Enter a value for Row 2, Column 1: 7
Enter a value for Row 2, Column 2: 9
The Matrix****************************************
You Entered the Following Matrix: 3, 8, 7, 9,
Row Totals****************************************
The sum of row 1 is: 11
The sum of row 2 is: 16
Column Totals*************************************
The sum of column 1 is: 10
The sum of column 2 is: 17
Row Products*************************************
The product of row 1 is: 24
The product of row 2 is: 63
Column Products*************************************
The product of column 1 is: 21
The product of column 2 is: 72
The greatest value in this matrix is: 9
The lowest value in this matrix is: 3
Enter another matrix? (Y or N) y
Enter number of rows & columns (they will be the same):
Write a program that accepts an n x n matrix. The program should also:
1. Total and display the sum of each row and each column
2. Find the product of each row and column
3. Find the highest and lowest value within the array
Constraints
The number of rows and columns should be the same
Use nested for loops and methods
Requirements
Build your matrix based upon user input (e.g., ask how many rows and columns - they must be the same)
Use a method to display the matrix (use tabs between each element)
Create methods to display the following:
o Method 1: The sum of each row
o Method 2: The sum of each column
o Method 3: The product of each row
o Method 4: The product of each column
o Method 5:Thehighestvalueinthematrix
o Method 6:Thelowestvalueinthematrix
Loop the program to run it until the user wishes to exit
In the example below, the numbers ARE NOT hard coded. Your program should ask the user for input
This program should utilize code learned from Week 1 through Week 8
Hints
Make sure you use Java coding conventions
Expected Output
The following pages show a sample run with two iterations. User input is in BOLD.
Welcome! This program that accepts an n x n matrix, totals the rows and columns & finds the product of each row and column.
Enter number of rows & columns (they will be the same): 2
Enter a value for Row 1, Column 1: 3
Enter a value for Row 1, Column 2: 8
Enter a value for Row 2, Column 1: 7
Enter a value for Row 2, Column 2: 9
The Matrix****************************************
You Entered the Following Matrix: 3, 8,
7, 9,
Row Totals****************************************
The sum of row 1 is: 11
The sum of row 2 is: 16
Column Totals*************************************
The sum of column 1 is: 10
The sum of column 2 is: 17
Row Products*************************************
The product of row 1 is: 24
The product of row 2 is: 63
Column Products*************************************
The product of column 1 is: 21
The product of column 2 is: 72
The greatest value in this matrix is: 9
The lowest value in this matrix is: 3
Enter another matrix? (Y or N) y
Enter number of rows & columns (they will be the same): 3
Enter a value for Row 1, Column 1: 7
Enter a value for Row 1, Column 2: 99
Enter a value for Row 1, Column 3: 2
Enter a value for Row 2, Column 1: 4
Enter a value for Row 2, Column 2: 55
Enter a value for Row 2, Column 3: 6
Enter a value for Row 3, Column 1: 2
Enter a value for Row 3, Column 2: 33
Enter a value for Row 3, Column 3: 7
The Matrix****************************************
You Entered the Following Matrix: 7, 99, 2,
4, 55, 6,
2, 33, 7,
Row Totals****************************************
The sum of row 1 is: 108
The sum of row 2 is: 65
The sum of row 3 is: 42
Column Totals*************************************
The sum of column 1 is: 13
The sum of column 2 is: 187
The sum of column 3 is: 15
Row Products*************************************
The product of row 1 is: 1386
The product of row 2 is: 1320
The product of row 3 is: 462
Column Products*************************************
The product of column 1 is: 56
The product of column 2 is: 179685
The product of column 3 is: 84
The greatest value in this matrix is: 99
The lowest value in this matrix is: 2
Enter another matrix? (Y or N) n
Thank you for using the program!
Goodbye!
Enter a value for Row 1, Column 1: 7
Enter a value for Row 1, Column 2: 99
Enter a value for Row 1, Column 3: 2
Enter a value for Row 2, Column 1: 4
Enter a value for Row 2, Column 2: 55
Enter a value for Row 2, Column 3: 6
Enter a value for Row 3, Column 1: 2
Enter a value for Row 3, Column 2: 33
Enter a value for Row 3, Column 3: 7
The Matrix****************************************
You Entered the Following Matrix: 7, 99, 2,
4, 55, 6,
2, 33, 7,
Row Totals****************************************
The sum of row 1 is: 108
The sum of row 2 is: 65
The sum of row 3 is: 42
Column Totals*************************************
The sum of column 1 is: 13
The sum of column 2 is: 187
The sum of column 3 is: 15
Row Products*************************************
The product of row 1 is: 1386
The product of row 2 is: 1320
The product of row 3 is: 462
Column Products*************************************
The product of column 1 is: 56
The product of column 2 is: 179685
The product of column 3 is: 84
The greatest value in this matrix is: 99
The lowest value in this matrix is: 2
Enter another matrix? (Y or N) n
Thank you for using the program!
Goodbye!
Explanation / Answer
Note: I made changes according to ur requirement.
Could u please check the code.If u need any modifications just tell me.I i will do modifications.Thank You.
_________________
Jwabby_Week8_Multidemensional_Arrays.java
package jwabby_week8_multidemensional_arrays;
/**
* @Course: SDEV 250 ~ Java Programming I
* @Author Name: Justin Wabby
* @Assignment Name: jwabby_week8_multidemensional_arrays
* @Date: Jul 5, 2017
* @Description: Week 8 Multidemensional Arrays
*/
//Imports
import java.util.Scanner;
//Begin Class Jwabby_Week8_Multidemensional_Arrays
public class Jwabby_Week8_Multidemensional_Arrays {
// Begin Main Method
public static void main(String[] args) {
//Scanner object is used to get the inputs entered by the user
Scanner con = new Scanner(System.in);
int i;
char c;
do {
System.out.print("Enter number of rows & columns (they will be the same) :");
i = con.nextInt();
int arr[][] = new int[i][i];
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
System.out.print("Enter value for row" + (j + 1) + ",column " + (k + 1) + ": ");
arr[j][k] = con.nextInt();
}
}
System.out.println("The Matrix ******** ****************");
System.out.println("You entered the following matrix");
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
System.out.print(arr[j][k] + " ");
}
System.out.println();
}
sumofrows(arr, i);
sumofcolumns(arr, i);
productofrows(arr, i);
productofcolumns(arr, i);
max(arr, i);
min(arr, i);
System.out.print("Enter another Matrix ? (Y or N) :");
c = con.next(".").charAt(0);
} while (c == 'y' || c == 'Y');
System.out.print(" Thank you for using the program! Goodbye!");
}
public static void sumofrows(int arr[][], int i) {
int sum = 0;
System.out.println("Row Totals *****************");
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
sum = sum + arr[j][k];
}
System.out.println("sum of row " + (j + 1) + "is " + sum);
sum = 0;
}
}
public static void sumofcolumns(int arr[][], int i) {
int sum = 0;
System.out.println("Column Totals *****************");
for (int k = 0; k < i; k++) {
for (int j = 0; j < i; j++) {
sum = sum + arr[j][k];
}
System.out.println("sum of Column " + (k + 1) + "is " + sum);
sum = 0;
}
}
public static void productofrows(int arr[][], int i) {
int product = 1;
System.out.println("Row products *****************");
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
product = product * arr[j][k];
}
System.out.println("Product of row " + (j + 1) + "is " + product);
product = 1;
}
}
public static void productofcolumns(int arr[][], int i) {
int product = 1;
System.out.println("Column products *****************");
for (int k = 0; k < i; k++) {
for (int j = 0; j < i; j++) {
product = product * arr[j][k];
}
System.out.println("sum of Column " + (k + 1) + "is " + product);
product = 1;
}
}
public static void max(int arr[][], int i) {
int max = 0;
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
if (arr[j][k] > max) {
max = arr[j][k];
}
}
}
System.out.println("The greatest value in the matrix is : " + max);
}
public static void min(int arr[][], int i) {
int min = arr[0][0];
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
if (arr[j][k] < min) {
min = arr[j][k];
}
}
}
System.out.println("The Lowest value in the matrix is : " + min);
} // End Main Method
} // End Class Jwabby_Week8_Multidemensional_Arrays
______________________
Output:
Enter number of rows & columns (they will be the same) :2
Enter value for row1,column 1: 3
Enter value for row1,column 2: 8
Enter value for row2,column 1: 7
Enter value for row2,column 2: 9
The Matrix ******** ****************
You entered the following matrix
3 8
7 9
Row Totals *****************
sum of row 1is 11
sum of row 2is 16
Column Totals *****************
sum of Column 1is 10
sum of Column 2is 17
Row products *****************
Product of row 1is 24
Product of row 2is 63
Column products *****************
sum of Column 1is 21
sum of Column 2is 72
The greatest value in the matrix is : 9
The Lowest value in the matrix is : 3
Enter another Matrix ? (Y or N) :y
Enter number of rows & columns (they will be the same) :3
Enter value for row1,column 1: 7
Enter value for row1,column 2: 99
Enter value for row1,column 3: 2
Enter value for row2,column 1: 4
Enter value for row2,column 2: 55
Enter value for row2,column 3: 6
Enter value for row3,column 1: 2
Enter value for row3,column 2: 33
Enter value for row3,column 3: 7
The Matrix ******** ****************
You entered the following matrix
7 99 2
4 55 6
2 33 7
Row Totals *****************
sum of row 1is 108
sum of row 2is 65
sum of row 3is 42
Column Totals *****************
sum of Column 1is 13
sum of Column 2is 187
sum of Column 3is 15
Row products *****************
Product of row 1is 1386
Product of row 2is 1320
Product of row 3is 462
Column products *****************
sum of Column 1is 56
sum of Column 2is 179685
sum of Column 3is 84
The greatest value in the matrix is : 99
The Lowest value in the matrix is : 2
Enter another Matrix ? (Y or N) :n
Thank you for using the program! Goodbye!
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.