//[Link] //This class calculates and prints an addition table.
//Class methods: // GetRows // Prompt the user to enter the number of rows in their addition table. // This value should be chosen from 2 to 30, and if the user enters a value // outside of this range, they should be prompted again. // GetColumns // Prompt the user to enter the number of columns in their addition table. // This value should be chosen from 2 to 12, and if the user enters a value // outside of this range, they should be prompted again. // PrintAddTable // Print out the addition table with the user-defined number of rows and // columns. Your table should have row and column headings. //Class variables: // row - The number of rows for the addition table. // column - The number of columns for the addition table. import [Link]; public class Add { private int row; // The number of rows for the addition table. private int column; // The number of columns for the addition table. private Scanner kb = new Scanner([Link]); public Add() { row = column = 0; } public void GetRows()
{ [Link]("Enter the number of rows to be shown ( 2 - 30 ) ->\t"); row = [Link](); if (!(row >= 2 && row <= 30)) { GetRows(); return; } } public void GetColumns() { [Link]("Enter the number of columns to be shown ( 2 - 12 ) ->\t"); column = [Link](); if (!(column >= 2 && column <= 12)) { GetColumns(); return; } } public void PrintAddTable() { [Link]("\nHere is your table:\n"); [Link]("\t|\t"); int curCol = 1; while (curCol <= column) { [Link]("%-8d", curCol); curCol++; } [Link](); int currDash = 1; do {
[Link]('-'); currDash++; } while (currDash <= (column + 2) * 8 - 6); [Link](); for (int r = 1; r <= row; r++) { [Link]("%-8d|\t", r); for (int c = 1; c <= column; c++) { [Link]("%-8d", c + r); } [Link](); } [Link](); } public static void main(String[] args) { Add table = new Add(); [Link](); [Link](); [Link](); } }