/** * A simple class from a simple song * Created: Sep 2020, * * @author gtowell */ public class Inchworm { /** * The current measurement status of the inchworm */ private int measurement; /** * Create a default inchworm. It starts measuring at 1. */ public Inchworm() { this.measurement = 1; } /** * Create an inchworm starting at something other than 1. * * @param startingMeasurement the starting measurement */ public Inchworm(int startingMeasurement) { this.measurement = startingMeasurement; } /** * A “copy” constructor. It copies the state of an existing inchworm * * @param iw the inchworm to be copied */ public Inchworm(Inchworm iw) { this.measurement = iw.getMeasurement(); } /** * Get accessor for measurement. Get accessors need NOT be commented * * @return the measurement */ public int getMeasurement() { return this.measurement; } /** * Change the measurement by doubling. It is all inchworms can do. */ public void doubleM() { this.measurement *= 2; } /** * The toString function. Normally this does not need a comment. * * @Override indicates that function is defined in ancestor */ @Override public String toString() { return "The marigold measures " + this.measurement + " inches"; } /** * Put the inchworm back in its base state */ public void reset() { this.measurement = 1; } /** * Function to be executed at start. * * @param args NOT used. */ public static void main(String[] args) { Inchworm inchworm = new Inchworm(); inchworm.doubleM(); System.out.println(inchworm); Inchworm inchworm2 = new Inchworm(inchworm); inchworm2.doubleM(); System.out.println(inchworm2 + " " + inchworm); } }