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.
Ahhhh.. any help please?
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
posted
0
Perhaps you want to look at System.out.printf(...)?
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..
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> I'm stumped..
if you're stumped, sneak up on it.
your basic table is one column, one row, which would be
- plus 10x - plus -
| plus 10x spaces plus |
- plus 10x - plus -
if you can do that, you have one cell.
next move on to multiple columns/rows
note: multiple columns do not start with an opening row or column separator,
only the first column
when you have the required number of columns/rows displaying,
manipulate the '10x spaces' so that header and data appears
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
4
posted
0
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.
Leif Perry
Greenhorn
Joined: Sep 12, 2009
Posts: 3
posted
0
Hello again,
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[0], 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.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
4
posted
0
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.