/** * File: PetRock.java * Author: Mr. Instructor * Programming: LCCC - CIS 210 * Last Modified: January 2011 * Description: This application creates, prints, and computes * the area of a pet rock (a rectangle with a name) */ public class PetRock { private int length; // length of rectangular rock private int width; // width of rectangular rock private String name; // name of rock /** * The PetRock() method constructs the pet rock with a given * length and width and name. */ public PetRock() { name = "Mr. Instructor's Pet Rock"; length = 30; width = 70; } // PetRock constructor /** * The calculateArea() method calculates and returns * the area of the (rectangular) rock. */ public double calculateArea() { double area; area = length * width; return area; } // calculateArea() /** * The drawRock() method prints out the rock's length & width as well * as the name of the rock then computes and prints the area * of the rock using the calculateArea() method. */ public void drawRock () { System.out.println("Hello to the Pet Rock Program"); System.out.println(""); System.out.println("The name of my rock is "+name); System.out.println("The width of my rock is "+width); System.out.println("The length of my rock is "+length); System.out.println("The area of my rock is "+calculateArea()); } // drawRock() /** * The main() method starts everything */ public static void main(String argv[]) { PetRock myPetRock; // declare an empty PetRock variable called "myPetRock" myPetRock = new PetRock(); // create (instantiate) the new PetRock. myPetRock.drawRock(); // prints out the rock's information on the screen } // main() } // PetRock()