• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing a Table from a Website  RSS feed

 
Amy Christine
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone. I'm semi-new to java and I am having trouble completing this program. We are instructed to create a program to print out a table from this website: http://aa.usno.navy.mil/cgi-bin/aa_moonphases.pl?year=NNNN (Where NNNN is the year). The program is to prompt the user to enter a date and when the date is entered, it should bring up the table with the specified year.

For example: If the user inputted 2011, it would print:





Here is the code for the program I have so far:

I honestly have no clue if I am doing this right. I'm confused as to how I am supposed to find the </table> tag and stop printing as well as how to find if it is inside the table... If I could get any assistance, tips, etc. that would be greatly appreciated.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't know; I have forgotten all about how to read things from the net. I am not happy however about putting everything into the main method. One thing I do know is that your loop won't work. I don't believe you can ever get null from Scanner.next, so your loop will never stop. What you want is
while (myScanner.hasNext()) ...
You use ctrl‑D (*nix) or ctrl‑Z (Windows) to terminate the input.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amy hagger wrote:. . .
. . .
Either use a buffered reader or a Scanner. I don't think you want both. You appear not to be using the buffered reader at all.

Create a DatePhase class which encapsulates the phase and the date (or date and time). Collect those objects in some sort of collection or other and then you can use them again and again to your heart's content.
 
Amy Christine
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Either use a buffered reader or a Scanner. I don't think you want both. You appear not to be using the buffered reader at all.

Create a DatePhase class which encapsulates the phase and the date (or date and time). Collect those objects in some sort of collection or other and then you can use them again and again to your heart's content.


Thanks for the help & welcoming! (: I changed the while loop to as you suggested and I think I am required to have another scanner so I will take out the buffered reader since it seems it is unnecessary. As for the class, can I just do this by using the if's in the while loop or is another class absolutely necessary?
 
Amy Christine
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit: Okay, I got it to print the table but it is printing the ENTIRE code, not the portion I want. Do you have any suggestions on how to clean this up?
Edit: Okay, I am not finding the <table> tags right.



Here is my output:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!