Computer Science 523
Advanced Programming
Summer 2014, The College of Saint Rose
Rectangle BlueJ Project
Click here to download a BlueJ project for Rectangle.
Rectangle Source Code
The Java source code for Rectangle is below. Click on a file name to download it.
/*
* Example Rectangle
*
* Compute the area and perimeter of a rectangle
*
* Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012
* Updated for The College of Saint Rose, CSC 523, Summer 2014
*
* $Id: Rectangle.java 2366 2014-05-20 02:33:22Z terescoj $
*/
import java.util.Scanner;
public class Rectangle {
public static void main(String[] args) {
// we need a Scanner to get our rectangle's dimensions from the keyboard
Scanner keyboard = new Scanner(System.in);
// retrieve the width and height, first issue a prompt
System.out.print("What is your rectangle's width? ");
// we want to read a number, not a String, so we use a different method
// of the Scanner to do this.
int width = keyboard.nextInt();
System.out.print("What is your rectangle's height? ");
int height = keyboard.nextInt();
// now, compute our two results and store them in two
// more local variables
int area = width * height;
int perimeter = 2 * width + 2 * height;
// report the result
System.out.println("Rectangle has area of " + area +
" and perimeter of " + perimeter + ".");
}
}