Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Summary Build a program that will provide spreadsheet style data processing of a

ID: 3677508 • Letter: S

Question

Summary

Build a program that will provide spreadsheet style data processing of a matrix of numbers. Your software will allow users to take the sum and average of specific rows or columns, and also calculate the sum and average of the whole spreadsheet.

Work Items

Submit only your java program (“.java” text file) via the website’s dropbox.

Pay extra attention to code formatting, style, comments, and basic programming practices learned so far.

Simulating a Numbers Spreadsheet

You are writing a program that allows the user to input data to a grid (a matrix) of N by N cells. You will define the size of your Spreadsheet in your program as a static final variable. Your software will support the following operations….

Input data; Ask the user for an x and y position in your spreadsheet, and then some (double) value z. Put the z-value in your matrix at the (x,y) position.

Row Sum : Ask the user for a row and then your software produces the sum of every element in that row.

Column Sum: Ask the user for a column and then produce the sum of the elements in that column.

Row Average: Ask the user for a row and then produce the average of this row (using the row sum function, not building from scratch)

Column Average: Ask the user for a column and then produce the average of every element in this column.

Total Sum : the sum of every element in the matrix. Build the total sum by calling the row or column sum functions, not from scratch.

Total Average: the average of every element in the matrix. Build the total average by reusing Row/Col Average or Row/Col Sum functions already completed above.

A Sample Execution of a 2x2 Spreadsheet

Below is an example execution of our spreadsheet software with N=2. In the example, we populate our array with different variables, and then we apply sum and averaging operations over our data.

|0.00||0.00|

|0.00||0.00|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

1

Enter X Y Value:

0 0 1.1

|1.10||0.00|

|0.00||0.00|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

1

Enter X Y Value:

0 1 2.2

|1.10||0.00|

|2.20||0.00|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

1

Enter X Y Value:

1 0 3.3

|1.10||3.30|

|2.20||0.00|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

1

Enter X Y Value:

1 1 4.4

|1.10||3.30|

|2.20||4.40|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

2

Enter Row:

0

Sum : 4.40

|1.10||3.30|

|2.20||4.40|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

5

Enter Column:

0

Average : 1.65

|1.10||3.30|

|2.20||4.40|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

6

Sum : 11.00

|1.10||3.30|

|2.20||4.40|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

7

Average : 2.75

|1.10||3.30|

|2.20||4.40|

(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit

8

Good Bye!

     

The Spreadsheet Skeleton File

The goal of your program is to carry out the steps necessary to populate a matrix with doubles, and then apply operations (sum, average) over these doubles. To that end, I’ve prepared a (mostly empty) skeleton file as a starting point for your work. Download the starter file and read the comments to get started. When your program executes, it should look like the output above. Specifically, it should accomplish…

Using a 2D array of doubles to store your spreadsheet data

Ask the user for an operation

Input new data

Sum a Row, Column, or the whole sheet

i.Note that to get credit for the Summation over the whole sheet, you must reuse your row sum or column sum operation.

Average a Row, Column, or the whole sheet

i.Note that to get credit for the Average over the whole set, you must reuse your row sum/average or column sum/average operation.

Additional Requirements

To get maximum credit, your code must be documented with comments and a file header.

To get full credit, certain functions (such as sumTotal) require that you use other functions. Refer to the “Stepwise Approach” section for further details.

Variables and functions must be public, and names in the skeleton code must not be modified.

All decimals should be displayed with precision to two digits past the decimal point.

Hints

Don’t wait till the last minute to get started or get help!

You might need a 2D array of doubles, as in “double[][] data”…

The class is named appropriately, and the file name must match the class name…

Stepwise Approach

Software is frequently designed in an iterative (or stepwise) fashion. We “paint” a bit more of the big picture with each step we take, building pieces of our system and testing them as we progress. Simple projects can frequently be done by just directly attacking the problem, but for projects with many components (or classes in Java), a more formalized approach can help significantly. In this section, we’ll outline the steps required to complete this program, and suggest an approach that can be used to reduce the complexity of this project.

Step 1: Input Data Using Scanner

If the user chooses to input data, you should ask the user for the x, y coordinate pair where they would like to put the data, and ask the user for the actual double value as well. This might correspond to “case 1” in your switch statement inside your main.

Step 2: Sum a Row

Add to the switch/case statement so that the user may select to sum up a row. Once the user indicates this, build a function called sumRow(int targetRow) that takes a target row and sums it.

Step 3: Sum a Column

Add more to the switch/case statement so that the user may select to sum up a column. Once the user indicates this, build a function called sumCol(int targetCol) that takes a target column and sums it up.

Step 4: Average a Row

Build another case in your switch so the user can select to average a specified row. Once the user selects this option, reuse the function in step 2 to produce your average. (hint: divide by N)

Step 5: Average a Column

Build another case in your switch so the user can select to average a specified column. Once the user selects this option, reuse the function in step 3 to produce your average. (hint: divide by N)

Step 6: Sum the Whole Set

Build another case in your switch so the user can select to sum the whole matrix. Once the user selects this option, reuse the function in step 2 to produce your sum.

Step 7: Average the Whole Set

Build another case in your switch so the user can select to average the whole matrix. Once the user selects this option, reuse the functions in any of the previous steps to produce your average.

Explanation / Answer

import java.util.Scanner;

class CalculationMatrix

{

   public static void main(String args[])

   {

      float n, c, d,rowsum,cloumnsum;

      Scanner in = new Scanner(System.in);

      System.out.println("Enter the number n for n*n matrix");

      n = in.nextFloat();

     int m[][] = new m[n][n];

//reading elements in matrix

System.out.println("Enter the elements into matrix according to their indexs");

      for ( c = 0 ; c < n ; c++ )

         for ( d = 0 ; d < n ; d++ )

            m[c][d] = in.nextInt();

//printing matrix

public void printInput()

{

for ( c = 0 ; c < n ; c++ )

         for ( d = 0 ; d < n ; d++ )

System.out.print("|"+m[c][d]+"|");

}

//calculating rowsum for given row

public void sumRow()

{

System.out.print("Enter Row");

int targetRow=in.nextInt();

for(c=0;c<n;c++)

{

rowsum=rowsum+m[targetRow][c];

}

System.out.println("rowsum="+rowsum);

}

//calculating column sum for given column

public void sumCloumn()

{

System.out.print("Enter column");

int targetColumn =in.nextInt();

for(r=0;r<n;r++)

{

columnsum=cloumnsum+m[r][ targetColumn];

}

System.out.println("column sum="+cloumnsum);

}

//calculating row avg and column avg

float rowavg=rowsum/n;

float columnavg=columnsum/n;

float sum=0;

//calculating matrix sum

public void sum()

{

      for ( c = 0 ; c < n ; c++ )

         for ( d = 0 ; d < n ; d++ )

{

    sum=sum+m[c][d];

}

System.out.println(" sum="+sum);

}

//calculating matrix sum average

float avgmat=sum/(n*n);

//creating object for class for calling appropriate methods to print o/p

CalculationMatrix m1=new CalculationMatrix();

System.out.println(" Welcome to the Matrix arithmetic operation program");

System.out.println("(1) Input (2) Row Sum (3) Col Sum (4) Row Ave (5) Col Ave (6) Sum (7) Average (8) Quit");

int o=in.nextInt();

switch(o)

      {

         case '1' :m1.printInput();

                       break;

         case '2' : m1. sumRow();

                      break;

       case '3' : m1. sumCloumn();

                        break;

         case '4' :System.out.println("Row Average"+ rowavg);

            break;

         case '5' : System.out.println("column Average"+ columnavg);

       break;

         case '6' : m1.sum;

                       break;

          case '7' : System.out.println(" Average"+ avgmat);

                       break;

           case '8' : System.exit(0);

                       break;

           default :

            System.out.println("Invalid option");

      }//switch

}//main

}//class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote