The lab starts here. 

Primitive types vs. reference types.

I would like to define my reference type today. 

For example if I could go back in time and be the creator of BigDecimal. 

import java.math.BigDecimal;
  
class One {
  public static void main(String[] args) {
    BigDecimal a;
    a = new BigDecimal("4.35");
    BigDecimal b = new BigDecimal("100"); 
    System.out.println( a.multiply(b) ); 
    System.out.println( 4.35 * 100 ); 
  }
}

But I will do Fraction today.

// import java.math.BigDecimal;
  
class One {
  public static void main(String[] args) {
    Fraction a;
    a = new Fraction(1, 2); // one half
    Fraction b = new Fraction(1, 2); // another half
    Fraction answer = a.add(b); 
    System.out.print( a ); 
    System.out.print( " + " ); 
    System.out.print( b ); 
    System.out.print( " = " ); 
    System.out.println( answer ); // 1 
                                  // 1/1
                                  // 2/2
                                  // Fraction@babeface
                                  // 2/4 + 2/4 resulting in 4/4
                                  // 1.0 
                                  // ... and who knows what else 
  }
}

For this to work we need to define a class Fraction.

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> java One
Fraction@fd01b1 + Fraction@90d7a = Fraction@196cd38
>

So we finished the program. 

We still have work to do. 

// import java.math.BigDecimal;
  
class One {
  public static void main(String[] args) {
    Fraction a;
    a = new Fraction(1, 2); // one half
    Fraction b = new Fraction(1, 2); // another half
    Fraction answer = a.add(b); 
    System.out.print( a ); 
    System.out.print( " + " ); 
    System.out.print( b ); 
    System.out.print( " = " ); 
    System.out.println( answer ); // 1 
                                  // 1/1
                                  // 2/2
                                  // Fraction@babeface
                                  // 2/4 + 2/4 resulting in 4/4
                                  // 1.0 
                                  // ... and who knows what else 
    a = new Fraction( -1, 3 ); 
    b = new Fraction( 12, 7 ); 
    System.out.println( a + " + " + b + " = " + b.add(a) ); 
  }
}

class Fraction {
  int num, den; // two instance variables 
  Fraction(int a, int b) {
    this.num = a; 
    this.den = b;
  }
  public Fraction add(Fraction other) {
    return new Fraction( this.num * other.den + other.num * this.den , 
                         this.den * other.den );  
  }
  public String toString() {
    return this.num + "/" + this.den;   
  }
}

What else? 

http://www.cs.indiana.edu/classes/a201-dger/spr2003/notes/Fifteen.html

Next develop Student.java either like in the lecture:

http://www.cs.indiana.edu/classes/c212-dgerman/sum2014/lectureSeven.html

Or you can use the information here:

http://www.cs.indiana.edu/classes/a202-dger/sum2010/zo.pdf

Please turn them in both. 

--