• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Creating a table without jTable

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you want to look at System.out.printf(...)?

Myself, I'd use a JTable here.
 
Leif Perry
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> I'm stumped..

if you're stumped, sneak up on it.

your basic table is one column, one row, which would be

row separator
(col. sep.) + data + (col. sep.)
row separator

so can you print out

- 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
 
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I was born with webbed fish toes. This tiny ad is my only friend:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic