Colorado State University

Recitation R9 - File Input & Output
Summer 2016

CS160: Foundations in Programming

Rectangle Class

Create the following instance variables and methods inside your Rectangle class
  1. Two instance variables of type double named width and length.
  2. A constructor that takes two parameters and assigns those values to the instance variables.
  3. a private non-static method called area that has no parameters and returns a double
  4. a toString method that returns the following:
    Rectangle, (Width: #, Length: #), Area: #
Width, Length and Area should be formatted to 2 decimal places.


To make sure your Rectangle class is printing what you want it to print. Create a Rectangle object in your main method using the following code:
Rectangle shape = new Rectangle(5.3, 10);

© 2015 CS160 Colorado State University. All Rights Reserved.