Computer Science 523
Advanced Programming
Summer 2014, The College of Saint Rose
OlderThanJava BlueJ Project
Click here to download a BlueJ project for OlderThanJava.
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 * Updated for The College of Saint Rose, CSC 523, Summer 2014 * * $Id: OlderThanJava.java 2366 2014-05-20 02:33:22Z 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 = 2014; 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!"); } } }