Guest
Public paste!

driverlab8

By: a guest | Mar 19th, 2010 | Syntax: Java | Size: 1.90 KB | Hits: 117 | Expires: Never
Copy text to clipboard
  1. /**
  2.  *  This is a driver class that test the proper implementaition of the Person, Student and Employee classes
  3.  */
  4. import acm.program.*;
  5. import acm.util.*;
  6.  
  7. public class Driver extends ConsoleProgram
  8. {
  9.     private Student s;
  10.     private Employee e;
  11.    
  12.     private static  final RandomGenerator rgen = RandomGenerator.getInstance();
  13.    
  14.     public void run()
  15.     {
  16.         // Testing Student Class
  17.        
  18.         // Create information needed
  19.         String sName = "John Doe";
  20.         String sGender = "Male";
  21.         String sAddress = "1000 McBryde Hall";
  22.         int sID = rgen.nextInt(1, 1000);
  23.        
  24.         // Instantiate an object of the class
  25.         s = new Student(sName, sGender);
  26.        
  27.         // Set some values of the object
  28.         s.setStudentID(sID);
  29.         s.setAddress(sAddress);
  30.         s.setCredits(44.5);
  31.         s.setPaid(true);
  32.        
  33.         // Print all the data in the object
  34.         println("This is the data in the Student object.");
  35.         println("--------------------------------------------------");
  36.         println( s.toString() );
  37.        
  38.         println();
  39.         pause(2000);
  40.        
  41.         // Testing Employee Class
  42.        
  43.         // Create information needed
  44.         String eName = "Jane Doe";
  45.         String eGender = "Female";
  46.         String eAddress = "3000 Torgersen Hall";
  47.         int eNumber = rgen.nextInt(1, 30);
  48.        
  49.          // Instantiate an object of the class
  50.         e = new Employee(eName, eGender);
  51.        
  52.          // Set some values of the object
  53.         e.setENumber(eNumber);
  54.         e.setAddress(eAddress);
  55.         e.setSalary(6000.0);
  56.         e.setActive(true);
  57.        
  58.          // Print all the data in the object
  59.          println("This is the data in the Employee object.");
  60.         println("--------------------------------------------------");
  61.         println( e.toString() );
  62.        
  63.     }
  64. }