SpreadSheet

SpreadSheet - int top = IO.readInt(); int bot =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class SpreadSheet { public static void main(String[] args) { int numrows = IO.readInt(); int numcols = IO.readInt(); double[][] spreadsheet = new double[numrows][numcols]; d for (int row = 0; row < spreasheet.length; row++) { for (int col = 0; col < spreadsheet[0].length; col++) { spreadsheet[row][col] = Double.NaN; } } while (true) { System.out.println("\n\n------------\nMenu:\n1. Enter a value\n2. Sum values in highlighted area\n3. Find a value\n4. Quit\n------------\n"); S int choice = IO.readInt(); i if (choice == 1) { int row = IO.readInt(); int col = IO.readInt(); double value = IO.readDouble(); d if (row >= 0 && row < spreadsheet.length && col >= 0 && col < spreadsheet[0].length) { spreadsheet[row][col] = value; } else { IO.reportBadInput(); } } else if (choice == 2) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int top = IO.readInt(); int bot = IO.readInt(); int left = IO.readInt(); int right = IO.readInt(); i for (int row = top; row &lt;= bot; row++) { for (int col = left; col &lt;= right; col++) { if (!Double.isNaN(spreadsheet[row][col])) { sum = sum + spreadsheet[row][col]; } } } IO.outputDoubleAnswer(sum); } else if (choice == 3) { double target = IO.readDouble(); d boolean found = false; for (int row = 0; row &lt; spreasheet.length; row++) { for (int col = 0; col &lt; spreadsheet[0].length; col++) { if (!Double.isNaN(spreadsheet[row][col])) { if (spreadsheet[row][col] == target) { IO.outputIntAnswer(row); IO.outputIntAnswer(col); found = true; break; } } } if (found) { break; } } } else if (choice == 4) { return; } } } }...
View Full Document

Page1 / 2

SpreadSheet - int top = IO.readInt(); int bot =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online