Question: Solve it using the code below: package edu.njit.cs 1 1 4 ; import java.util.Arrays; / * * * Author: * Date created: * / public
Solve it using the code below:
package edu.njit.cs;
import java.util.Arrays;
Author:
Date created:
public class ArrayStudy
public static double manipulatedouble a double fraction
Perform step a
double a extracta fraction;
System.out.printlnContent of array after step a for fraction fraction :;
printArraya;
Perform stp b
double a replacea;
System.out.printlnContent of array after step b for fraction fraction :;
printArraya;
return a;
prints D array
private static void printArraydouble a
for int i; i alength; i
for int j; j ailength;j
System.out.printStringformatfaij;
System.out.println;
private static double extract double a double fraction
if alength
return a;
int fractionNumCols ;
int noOfNegativesInRow ;
int noOfRowsRemoved ;
boolean removeRow new booleanalength;
Loop through each row of a to check if number of negatives is at least halfCol
for int i ; i alength; i
fractionNumCols int Math.ceilailength fraction;
noOfNegativesInRow ;
To be completed
Loop through each column of the ith row to update noOfNegativesInRow
If noOfNegativesInRow is at least fractionNumCols, set removeRowi to true
and also update noOfRowsRemoved
allocate a new array
double b new doublealengthnoOfRowsRemoved;
int validRowIndex ;
To be completed
Loop through each row i of a and if removeRowi is false, add it to b
using Arrays.copyOf function
return b;
private static double replacedouble b
double columnSum ; Column sum
double columnAverage ;Column average
int numNonNegatives ; number of positives in the column
Loop through each column j to replace negative with average of positives in the same column
for int j; j blength; j
columnSum ;
numNonNegatives ;
To be completed
First find columnSum and numNonNegatives using nonnegative values of
the jth column of b
This is done by looping through each row of the same column
columnAverage numNonNegatives columnSumnumNonNegatives : ;
To be completed
Now replace all negative numbers of jth column of b with the column average
return b;
public static void main String args
double a ; A x Dimension;
System.out.printlnPrinting input array...";
printArraya;
double b manipulatea;
b manipulatea;
System.out.printlnPrinting original array...";
printArraya;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
