Function toString - title= t Constructor an instance with chapter number n title t and previous chapter c public Chapter(int n String t Chapter c

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/** 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;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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; } }...
View Full Document

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).

Page1 / 2

Function toString - title= t Constructor an instance with chapter number n title t and previous chapter c public Chapter(int n String t Chapter c

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online