<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/** Write a function toString, which gives the values of the
    fields, in a format that is easy to read. */


/** An instance maintains info about a book chapter */
public class Chapter {
    private int number;   // The chapter number.
    private String title; // The chapter title;
    private Chapter prev; // The previous chapter
                          // (null if none)
    
    /** =  a representation of this chapter Ñfor the previous
           chapter, the chapter title is given. */
    public String toString() {
        return "Chapter " + number + ". " + title + ". " +
            (prev == null ? "No previous chapter"
                 : "Previous chapter title: " + prev.title);
    }

    
    
    /** Constructor: an instance with chapter number n,
                     title t, and previous chapter null */
    public Chapter(int n, String t) {
        number= n;
        title= t;
    }
    
    /** Constructor: an instance with chapter number n,
                     title t, and previous chapter c */
    public Chapter(int n, String t, Chapter c) {
        number= n;
        title= t;
        prev= c;
    }
    
    /** = the number of this chapter. */
    public int getNumber() {
        return number;
    }
    
    /** = the title of this chapter. */
    public String getTitle() {
        return title;
    }
    
    /** = the previous chapter (null if none). */
    public Chapter getPrevious() {
        return prev;
    }
    
    /** Set the number of this chapter to n. */
    public void setNumber(int n) {
        number= n;
    }
    
    /** Set the title of this chapter to t. */
    public void setTitle(String t) {
        title= t;
    }
    
    /** Set the previous chapter to p */
    public void setPrevious(Chapter p) {
        prev= p;
    }

    
    
}</pre></body></html>