Question

Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates...

Java Programming (use jGrasp if not thats fine)

Write a Two classes one class that creates a two-dimensional 2 rows by 3 columns double array. This class will have a separate method for the user to populate the array with data values. The other class that has the following methods:

  •   getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.
  •   getAverage. This method should accept a two-dimensional array as its argument and return the average of the values in the array.
  •   getRowTotal. This method should accept a two-dimensional array as its first argument and an integer as the second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row.
  •   getColumnTotal. This method should accept a two-dimensional array as its first argument and an integer as the second argument. The second argument should be the subscript of a column in the array. The method should return the total of the values in the specified column.
  • getHighestInRow. This method should accept a two-dimensional array as its first argument and an integer as the second argument. The second argument should be the subscript of a row in the array. The method should return the value in the specified row.
  • getLowestInRow. This method should accept a two-dimensional array as its first argument and an integer as the second argument. The second argument should be the subscript of a row in the array. The method should return the lowest value in the specified row.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Programming :

import java.util.Scanner;
class methods_class{
   //method to calculate sum of the array
   double getTotal(double A[][]){
       double sum = 0;
       int i,j=0;
       for(i=0;i<2;i++){
           for(j=0;j<3;j++){
               sum = sum + A[i][j];
           }
       }
       return sum;
   }
   //method to calculate average of the array
   double getAverage(double A[][]){
       double sum = getTotal(A);
       double average = sum/6.0;
       return average;
   }
   //method to calculate sum of the specific row of the array
   double getRowTotal(double A[][],int row){
       double row_sum = 0;
       int j;
       for(j=0;j<3;j++){
           row_sum = row_sum + A[row][j];
       }
       return row_sum;
   }
   //method to calculate sum of the specific column of the array
   double getColumnTotal(double A[][],int column){
       double column_sum = 0;
       int i;
       for(i=0;i<2;i++){
           column_sum = column_sum + A[i][column];
       }
       return column_sum;
   }
   //method to calculate max of the specific row of the array
   double getHighestInRow(double A[][],int row){
       double max = A[row][0];
       int j=0;
       for(j=0;j<3;j++){
           if(max < A[row][j]){
               max = A[row][j];
           }
       }
       return max;
   }
   //method to calculate min of the specific row of the array
   double getLowestInRow(double A[][],int row){
       double min = A[row][0];
       int j=0;
       for(j=0;j<3;j++){
           if(min > A[row][j]){
               min = A[row][j];
           }
       }
       return min;
   }
}
public class array{
   static double[][] A = new double[2][3];
   //method to take data to array
   public void populate(){
       int i,j=0;
       Scanner sc = new Scanner(System.in);
       for(i=0;i<2;i++){
           for(j=0;j<3;j++){
               System.out.print("Enter A["+i+"]["+j+"] : ");
               A[i][j] = sc.nextDouble();
           }  
       }
       System.out.println();
   }
   public static void main(String args[]){
       array data = new array();
       Scanner sc = new Scanner(System.in);
       int i,j=0;
       //calling the method to take data into the array
       data.populate();
       System.out.print("Entered 2D Array : \n\n\t");
       for(i=0;i<2;i++){
           for(j=0;j<3;j++){
               System.out.print(A[i][j] + " ");  
           }
           System.out.print("\n\t");
       }
       System.out.println();
      
      
       methods_class methods = new methods_class();
       //calling the method to calculate the sum of the array
       System.out.println("Total sum of the array : "+ methods.getTotal(A));  
       System.out.println("Total average of the array : "+ methods.getAverage(A));
      
       //calling the method to calculate the average of the array
       System.out.print("Enter a row_number to get the row_sum : ");
       int row = sc.nextInt();
       System.out.println("Total " + row +"row sum of the array : "+ methods.getRowTotal(A,row));
      
       //calling the method to calculate sum of the specific row of the array
       System.out.print("Enter a column_number to get the column_sum : ");
       int column = sc.nextInt();
       System.out.println("Total " + column +"column sum of the array : "+ methods.getColumnTotal(A,column));
      
       //calling the method to calculate max of the specific row of the array
       System.out.print("Enter a row_number to get max in that row: ");
       int row1 = sc.nextInt();
       System.out.println("Max in " + row1 +"row of the array : "+ methods.getHighestInRow(A,row1));
      
       //calling the method to calculate min of the specific row of the array
       System.out.print("Enter a row_number to get min in that row: ");
       int row2 = sc.nextInt();
       System.out.println("Min in " + row2 +"row of the array : "+ methods.getLowestInRow(A,row2));
      
   }
}

Output :

please upvote.if any doubts comment below.

Add a comment
Know the answer?
Add Answer to:
Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array...

    This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. .getAverage. This method should accept a two-dimensional array as its argument and return...

  • Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This...

    Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...

  • Please solve only if you know how to do it. Write the code using C++ (not...

    Please solve only if you know how to do it. Write the code using C++ (not Python or Java). Show and explain everything neatly. COMMENTS (7.5% of programming assignment grade): Your program should have at least ten (10) different detailed comments explaining the different parts of your program. Each individual comment should be, at a minimum, a sentence explaining a particular part of your code. You should make each comment as detailed as necessary to fully explain your code. You...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write...

    Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores. This program should also have the following methods:     getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.     getAverage. This method should accept a studentScore array as its argument...

  • Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the...

    Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...

  • In this homework, create two arrays – studentName and studentScore (String and Int types). Write a...

    In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores. This program should also have the following methods:     getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.     getAverage. This method should accept a studentScore array as its argument and...

  • Design and implement a Java class (name it Summer Stats. java) that tracks statistics for summer...

    Design and implement a Java class (name it Summer Stats. java) that tracks statistics for summer job salaries for a group of people over several years. The only data field you need is a 2-Dimenssional array of values representing salaries. The rows the represents the people and the columns represent the years. The constructor method takes two integers representing the number of people and the number of years, then randomly generates the annual salaries and fills the array. Other class...

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • Design and implement a Java class (name it SummerStats.java) that tracks statistics for summer job salaries...

    Design and implement a Java class (name it SummerStats.java) that tracks statistics for summer job salaries for a group of people over several years. The only data field you need is a 2-Dimenssional array of values representing salaries. The rows the represents the people and the columns represent the years. The constructor method takes two integers representing the number of people and the number of years, then randomly generates the annual salaries and fills the array. Other class methods include...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT