I have a programming project due soon, in which I must create trig tables. These tables are to be created using - separators for the rows, and the | for the columns.
Each cell is to have a width of ten characters, and I am supposed to input a formatted trig value in each cell.
The number of columns are taken as an input argument.
I have no idea how to create a table using this method, other than drawing it using println commands, and even then I'm unsure of how I'll be able to populate the cells with data.. since they won't have a reference location.
Yea, but sadly we're not allowed to.. I'm stumped.. here's an excerpt from the assignment.
The table must be formatted in the following manner:
a. The table must have a title exactly matching the examples shown at the end of these directions.
b. Each cell of the table has a fixed size of 10 characters, and the left and right borders of each cell must be drawn using the | symbol (the pipe symbol).
c. The row separator must be drawn using - (minus) symbols, and your program needs to draw the exact number of - symbols needed for row separators.
d. The computed trig values in the table must be decimal formatted using the scientific notation pattern "0.000E00" which will ensure their sizes will be at most 10 characters.
e. The cell values must be right aligned, and all cell borders must also align.
And here's an image of such a table:
Hm image isn't showing, right click and open in another tab should work..
The methods of Formatter might be useful (they are re-applied as System.out.printf, etc). But you should check that you are permitted to use Formatter at all.
Joined: Sep 12, 2009
I've solved the problem, and everything is now working correctly.
Now the only thing left to do is to use some error-handling for the input arguments..
The first argument, args, must either be the sin, cos, or tan functions. Anything else should throw an exception.
My question is what type of exception should I throw in this situation? Basically, how should I craft this error-checking block?
Thanks for all the help so far; I was able to code the main program with relative ease.
Joined: Oct 13, 2005
Well done. Please tell everybody, briefly, how you solved the problem.
How are you passing sin cos or tan? It is possible to pass a "function" to a "function" in some languages, but not in Java. The exception for incorrect arguments is usually IllegalArgumentException.