Data Types (Cont.)


Non-Primitive Data Types
The differences between primitive and non-primitive data types include: Examples of non-primitive types include String, Arrays, classes, etc.

Student.java (a non-primitive data type: class)

 public class Student {

   // The main method
   public static void main( String[ ] args ) {
     Student s1 = new Student( "Poke Mon", , ,  );
     Student s2 = new Student( "Digi Mon", , ,  );

     float GPA1 = s1.findGPA(  );
     float GPA2 = s2.findGPA(  );

     if ( GPA1 == GPA2 )
       System.out.println( "Tied" );
     else if ( GPA1 > GPA2 )
       System.out.println( s1.getName( ) );
     else
       System.out.println( s2.getName( ) );
   }

   // Four member variables
   private String name;
   private int    score1, score2, score3;

   // A constructor
   public Student( String n, int s1, int s2, int s3 ) {
     name   = n;
     score1 = s1;
     score2 = s2;
     score3 = s3;
   }

   // A member method to return the name
   public String getName( ) {
     return( name );
   }

   // A member method to find the GPA
   public float findGPA( float no ) {
     return( ( score1 + score2 + score3 ) /  );
   }
 }
Output:           Result:




      “Never let your sense of morals prevent you from doing what is right.”    
      ― Isaac Asimov, Foundation