Description: You are to develop a program that prints out the multiplication or addition table given the users start and end range and type of table.
The program will make use of 2D arrays to calculate the table.
The program will make use of the System.out.printf() method to allow formatted output.
The program will have TWO methods with the following name and signature:
public void createTable(int begin, int finish, TableType tableType)
public void printTable()
An additional method to check on arguments passed in to main will be provided (called argumentCheck()). This method will return true if the arguments passed in are valid and will set the data members: start, end and tableType.
There is no constructor, nor any other method (including overloaded methods).
The class will contain a data member (handle) for the table (a 2D array of type float), start and end (ints) for the start and end values of the table, and tableType (TableType) an enumerated type consisting of {MULT, ADD}.
package ArithmeticTable;
public boolean argumentCheck(String[] args){
if(args.length!=3){
System.err.println("Usage: Main <type> <start> <stop>");
System.err.println("\tWhere <type> is one of +, -, \"*\", /");
System.err.println("\tand <start> is between 1 and 100");
System.err.println("\tand <stop> is between 1 and 100");
System.err.println("\tand start < stop");
return false;
}
if(args[0].charAt(0) == '+')
tableType = TableType.ADD;
else
tableType = TableType.MULT;
int sta;
int sto;
try{
sta = Integer.parseInt(args[1]);
sto = Integer.parseInt(args[2]);
}
catch(NumberFormatException ex){
System.err.println("Usage: Main <type> <start> <stop>");
System.err.println("\tWhere <type> is one of +, -, \"*\", /");
System.err.println("\tand <start> is between 1 and 100");
System.err.println("\tand <stop> is between 1 and 100");
System.err.println("\tand start < stop");
return false;
}
if((sta < 1 || sta > 100)||((sto < 1 || sto > 100))){
System.err.println("Usage: Main <type> <start> <stop>");
System.err.println("\tWhere <type> is one of +, -, \"*\", /");
System.err.println("\tand <start> is between 1 and 100");
System.err.println("\tand <stop> is between 1 and 100");
System.err.println("\tand start < stop");
return false;
}
if(sta >= sto){
System.err.println("Usage: Main <type> <start> <stop>");
System.err.println("\tWhere <type> is one of +, -, \"*\", /");
System.err.println("\tand <start> is between 1 and 100");
System.err.println("\tand <stop> is between 1 and 100");
System.err.println("\tand start < stop");
return false;
}
start = sta;
end = sto;
return true;
}
public static void main(String[] args){
ArithmeticTable table = new ArithmeticTable();
if (table.argumentCheck(args)){
table.createTable(table.start, table.end, table.tableType);
table.printTable();
}
}
}