Selective Data


/********************************************************

Example Written in Java
Demonstrates proper use of Selective Data and Controls

********************************************************/

import java.lancs.*;

public class example2
  {
  public static void main(String[] args)
    {
    //First Define 2 Objects of type person
    Person person1 = new Person();
    Person person2 = new Person();

    //Initialize all of the data for person1
    person1.setForename("John");
    person1.setSurname("Smith");
    person1.setAge(20);

    //Initialize all of the data for person2
    person2.setForename("Jill");
    person2.setSurname("Smith");
    person2.setAge(22);

    //If person1's age is greater than person2's age....
    if (person1.getAge() > person2.getAge())
      {
      //Output he/she is older
      System.out.print(person1.getForename() + " " + person1.getSurname());
      System.out.print(" is older than ");
      System.out.println(person2.getForename() + " " + person2.getSurname());
      }
    //Otherwise...
    else
      {
      //print out that person 2 is older
      System.out.print(person2.getForename() + " " + person2.getSurname());
      System.out.print(" is older than ");
      System.out.println(person1.getForename() + " " + person1.getSurname());
      }
   }
}

These pages were edited for style and content by Allan Caine, Laura Drever, Gorana Jankovic, Megan King, and Marie Lewis.

The original authors of these pages were Graeme Humphries, Chantal Laplante, Chris Mills, and Melvin Lenz.

Last Modified: Wednesday, June 7th 23:45:30
Copyright 2000 Department of Computer Science, University of Regina.


[CS Dept Home Page]