Computer Science 202
Introduction to Programming
Fall 2012, The College of Saint Rose
OlderThanJava BlueJ Project
Click here to download a BlueJ project for OlderThanJava.
Download file: OlderThanJava.vls
OlderThanJava Source Code
The Java source code for OlderThanJava is below. Click on a file name to download it.
/** * Class example demonstrating the if statement * * It prompts for a birth year, prints out what age that person will * turn this year, and then an extra message only if that person is * older than the Java programming language * * Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012 * * $Id: OlderThanJava.java 1907 2012-09-19 18:47:12Z terescoj $ */ import java.util.Scanner; public class OlderThanJava { public static void main(String args[]) { // we use named constants for some of the "magic numbers" we use // later in the program. final int THIS_YEAR = 2012; final int JAVA_BIRTH_YEAR = 1995; // usual procedure: construct a Scanner for keyboard input Scanner kbd = new Scanner(System.in); // read in the user's birth year System.out.print("What year were you born? "); int birthYear = kbd.nextInt(); // message for everyone System.out.println("Hey, you turn " + (THIS_YEAR - birthYear) + " this year!"); // message only for the "old" if (birthYear < JAVA_BIRTH_YEAR) { System.out.println("You are older than Java!"); } } }