Question: HELP ME MODIFY MY JAVA CODE PLEASE! This is my code: import java.util.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Assignment1 { public static

HELP ME MODIFY MY JAVA CODE PLEASE!

This is my code:

import java.util.*;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class Assignment1 {

public static void main(String[] args) {

String fileName = "";

if (args.length == 0) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the file name :");

fileName = sc.nextLine();

} else {

fileName = args[0];

}

File file = new File("C:\\Users\\Windows\\Desktop\\2darray.txt");

try {

Scanner fin = new Scanner(file);

int size = fin.nextInt();

int[][] arr = new int[size][size];

for (int i = 0; i < size; i++) {

for (int j = 0; j < size; j++) {

arr[i][j] = fin.nextInt();

Scanner sc = new Scanner(file);

int noOfRows = Integer.parseInt(sc.nextLine());

int array[][] = new int[noOfRows][10];

for (int o = 0; o < noOfRows; o++) {

for (int g = 0; g < array[o].length; g++) {

array[o][g] = -1;

}

}

int index = 0;

while (sc.hasNextLine()) {

String line = sc.nextLine();

String numbers[] = line.split(" ");

for (int o = 0; o < numbers.length; o++) {

array[index][o] = Integer.parseInt(numbers[o]);

}

index++;

}

sc.close();

System.out.println("~~Array~~");

for (int o = 0; o < noOfRows; o++) {

for (int g = 0; g < array[o].length; g++) {

if (array[o][g] != -1)

System.out.print(array[o][g] + " ");

}

System.out.println();

}

}

}

System.out.println("Total: " + getTotal(arr));

System.out.println("Average: " + getAverage(arr));

System.out.println("Third Row Total: " + getRowTotal(arr, 3));

System.out.println("Second Column Total: " + getColumnTotal(arr, 2));

System.out.println("Highest in Second Row:" + highestInRow(arr, 2));

System.out.println("Lowest in Second Row:" + lowestInRow(arr, 2));

} catch (FileNotFoundException e) {

System.out.println(file.getAbsolutePath() + " is not found!");

}

}

public static int getTotal(int a[][]) {

int i, j, tot = 0;

for (i = 0; i < a.length; i++)

for (j = 0; j < a[0].length; j++)

tot += a[i][j];

return tot;

}

public static double getAverage(int a[][]) {

return (double) getTotal(a) / (a.length * a[0].length);

}

public static int highestInRow(int[][] array, int row) {

if (row < 1 || array.length < row) {

System.out.println("Invalid row entered");

return 0;

}

int highestNum = array[row - 1][0];

for (int col = 0; col < array[row].length; col++) {

if (array[row - 1][col] > highestNum)

highestNum = array[row - 1][col];

}

return highestNum;

}

public static int getColumnTotal(int array[][], int col) {

if (col < 1 || array[0].length < col) {

System.out.println("Invalid column entered");

return 0;

}

int total = 0;

for (int row = 0; row < array.length; row++) {

total += array[row][col - 1];

}

return total;

}

public static int getRowTotal(int array[][], int row) {

if (row < 1 || array.length < row) {

System.out.println("Invalid row entered");

return 0;

}

int total = 0;

for (int col = 0; col < array[row].length; col++) {

total += array[row - 1][col];

}

return total;

}

public static int lowestInRow(int[][] array, int row) {

if (row < 1 || array.length < row) {

System.out.println("Invalid row entered");

return 0;

}

int lowestNum = array[row - 1][0];

for (int col = 0; col < array[row].length; col++) {

if (array[row - 1][col] < lowestNum)

lowestNum = array[row - 1][col];

}

return lowestNum;

}

}

I have to include these modifications to my code, can somebody please show me how to?

  • A concrete class named TwoDimArray
  • Define the backing 2D array as an instance variable and use the double primitive type.
  • Declare any other instance variables required to implement the class.
  • Implement instance methods as outlined in the program specification and add the following methods: getArrayMaxValue(), getArrayMinValue(), calcStdDev(), findValue(double), replace(double), replaceAll(double) and loadArray().
  • Use JOptionPanes for all user I/O.
  • Use a JOptionPane to prompt the user for an input file name. If the file doesn't exist or is empty, display an error message using a JOptionPane and quit.
  • Use try-catch blocks to trap and handle exceptions.
  • Use the loadArray() instance method to read the data from a file where the first record (line) contains two numbers: the first represents the number of rows and the second number represents the number of columns. If there is an error reading the file or if the row/column data is invalid, display an error message using a JOptionPane and quit. Subsequent records in the file will represent the array data. If there is an error reading the file or if the data is invalid or missing, display an error message using a JOptionPane and quit. Use try-catch blocks.
  • Include Javadoc documentation at the class and method levels. When finished, run the source code through the Javadoc utility to create the HTML version of the TwoDimArray class API.
  • Develop the UML diagram for the class
  • Include a public static void main(String[]) method in the class and use it as a driver module for an instance of the class and to test the various instance methods. Use System.out.println() to display all normal program output (send it to the standard output device).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!