Need help creating a java program that prints a table of contents from a book
<p>I'm supposed to write a java program, which prints a table of contents, using the following data structure:</p>

<pre><code>public class TocEntry 
{ 
    // Specify the needed methods 
    private String chapter; 
    private int page; 
} 
</code></pre>

<p>And the following defined in my driver class:</p>

<pre><code>public final int TOCSIZE = 100; 
TocEntry toc[] = new TocEntry[TOCSIZE]; 
int toc_curlen = 0; //The toc_curlen is intended to keep track of the number of chapters entered by the user and it can be used as an index into the array of TocEntry objects.  
</code></pre>

<p>Next, I'm supposed to develop the necessary code, in my TocEntry class, to read in a chapter name and page number until “<code>**</code>” is entered.  From this, my output should look like this: </p>

<blockquote>
  <p>My Story Starts.......................1 </p>
  
  <p>Growing up...........................35 </p>
  
  <p>Conquering the World........103 </p>
</blockquote>

<p>This is supposed to be my sample run using a driver called useTocEntry </p>

<blockquote>
  <p>Enter chapter title: Camelot </p>
  
  <p>Enter starting page number: 1 </p>
  
  <p>Enter chapter title: King Arthur's Court </p>
  
  <p>Enter starting page number: 3 </p>
  
  <p>Enter chapter title: Knights of the Table Round </p>
  
  <p>Enter starting page number: 8 </p>
  
  <p>Enter chapter title: Sir Dinadan the Humorist </p>
  
  <p>Enter starting page number: 12 </p>
  
  <p>Enter chapter title: An Inspiration </p>
  
  <p>Enter starting page number: 14 </p>
  
  <p>Enter chapter title: The Eclipse </p>
  
  <p>Enter starting page number: 23 </p>
  
  <p>Enter chapter title: A Postscript by Clarence </p>
  
  <p>Enter starting page number: 274 </p>
  
  <p>Enter chapter title: <code>**</code> </p>
  
  <p>Camelot..........................................1</p>
  
  <p>King Arthur's Court.........................3 </p>
  
  <p>Knights of the Table Round............8 </p>
  
  <p>Sir Dinadan the Humorist..............12 </p>
  
  <p>An Inspiration................................14 </p>
  
  <p>The Eclipse...................................23 </p>
  
  <p>A Postscript by Clarence.............274 </p>
</blockquote>

<p>This is the code I have so far:</p>

<pre><code>import java.util.*;

public class TocEntry {
    public TocEntry() { // Default Constructor
        chapter = "";
        page = 0;
    }

    public TocEntry(String c, int p) { // 2 Argument Constructor
        chapter = c;
        page = p;
    }

    public String getChapter() { //getChapter() and getPage() are accessor methods
        return chapter;
    }

    public int getPage() {
        return page;
    }

    public void setChapter(String title) { ////setChapter() and setPage() are mutator methods
        chapter = title;
    }

    public void setPage(int numPage) {
        page = numPage;
    }

    private String chapter; 
    private int page;

    public String toString() { // toString method to print out contents
        return  chapter + "**" + page;
    }
}// End of class TocEntry
</code></pre>

<p>And this is my driver class:</p>

<pre><code>import java.util.Scanner;
public class useToEntry {

    public static void main(String[] args) { 
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the number of contents you would like to display:   ");
        int TOC_NUM = input.nextInt();
        final int TOCSIZE = 100;
        TocEntry toc[] = new TocEntry[TOCSIZE]; 
        int toc_curlen = 0; // The toc_curlen is intended to keep track of the number 
                        // of chapters entered by the user and it can be used as an
                        // index into the array of TocEntry objects. 
        for(int i = 0; i &lt; TOC_NUM; i++) {
            System.out.print("Enter chapter title: ");
            String ch = input.next();     
            System.out.print("Enter starting page number: ");
            int y = input.nextInt();
        }// End of for loop
    } // End of main method

}// End of class useTocEntry
</code></pre>

<p>I need help, especially to create a method that aligns the <code>**</code> with the chapter title and the page number. Any help or advice on my code would be appreciated.</p>
