Computer Science 202
Introduction to Programming
Fall 2012, The College of Saint Rose
OlderYoungerThanJava BlueJ Project
Click here to download a BlueJ project for OlderYoungerThanJava.
Download file: OlderYoungerThanJava.vls
OlderYoungerThanJava Source Code
The Java source code for OlderYoungerThanJava is below. Click on a file name to download it.
/**
* Class example demonstrating the if-else statement
*
* It prompts for a birth year, prints out what age that person will
* turn this year, and then one of two messages, depending on whether
* that person is older or younger than the Java programming language
*
* Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012
*
* $Id: OlderYoungerThanJava.java 1907 2012-09-19 18:47:12Z terescoj $
*/
import java.util.Scanner;
public class OlderYoungerThanJava
{
public static void main(String args[]) {
final int THIS_YEAR = 2012;
final int JAVA_BIRTH_YEAR = 1995;
Scanner kbd = new Scanner(System.in);
System.out.print("What year were you born? ");
int birthYear = kbd.nextInt();
System.out.println("Hey, you turn " + (THIS_YEAR - birthYear) + " this year!");
if (birthYear < JAVA_BIRTH_YEAR) {
System.out.println("You are older than Java!");
}
else {
System.out.println("You do not know a world without Java...");
}
}
}