• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Printing a Table from a Website

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76867
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76867
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic