Typical program I can write: 

import java.util.Scanner; 
import java.math.BigDecimal;

public class One {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in); 
    System.out.print("How much fuel do you have: "); 
    String fuel = in.nextLine(); 
    System.out.print("Your car's efficiency: ");
    String mpg = in.nextLine();
    BigDecimal a, b; 
    a = new BigDecimal(fuel); 
    b = new BigDecimal(mpg); 
    System.out.println("Your autonomy is: " + a.multiply(b));     
  }
}

Here's how this works: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run One
How much fuel do you have: 4.35
Your car's efficiency: 100
Your autonomy is: 435.00
> 4.35 * 100
434.99999999999994


Please on your paper write the following expressions:

  1 + 2

  2 * (4 + 3)

  (2 - 3) * (4 - 5)

Create a BigDecimal for each number and write the expressions in Java. 


Example: 

  BigDecimal a, b, c, d, e; 
  a = new BigDecimal(1); 
  b = new BigDecimal(2); 
  c = new BigDecimal(3); 
  d = new BigDecimal(4); 
  e = new BigDecimal(5); 
  System.out.println(1 + 2); 
  System.out.println(a.add(b)); 
  System.out.println(2 * (4 + 3)); 
  // write the same using b, c, d

  System.out.println((2 - 3) * (4 - 5)); 
  // write the same with b, c, d, e

Then we will run them in DrJava

https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#subtract-java.math.BigDecimal-

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
>  BigDecimal a, b, c, d, e; 
  a = new BigDecimal(1); 
  b = new BigDecimal(2); 
  c = new BigDecimal(3); 
  d = new BigDecimal(4); 
  e = new BigDecimal(5); 
  System.out.println(1 + 2); 
  System.out.println(a.add(b)); 
  System.out.println(2 * (4 + 3)); 
  // write the same using b, c, d

  System.out.println((2 - 3) * (4 - 5)); 
  // write the same with b, c, d, e
Static Error: Undefined class 'BigDecimal'
> import java.math.BigDecimal; // auto-import
BigDecimal a, b, c, d, e; 
  a = new BigDecimal(1); 
  b = new BigDecimal(2); 
  c = new BigDecimal(3); 
  d = new BigDecimal(4); 
  e = new BigDecimal(5); 
  System.out.println(1 + 2); 
  System.out.println(a.add(b)); 
  System.out.println(2 * (4 + 3)); 
  // write the same using b, c, d

  System.out.println((2 - 3) * (4 - 5)); 
  // write the same with b, c, d, e
3
3
14
1
> (d.add(c)).multiply(b)
14
> d.add(c).multiply(b)
14
> b.subtract(c).multiply(d.subtract(e))
1
>

> (b.subtract(c)).multiply(d.subtract(e))
1


Now about methods:

class Robot {
  public int talk() {
    return (int) (Math.random() * 6) + 1; 
  }
  public void paint() {
    System.out.println( one() );  
  }
  public static String three() {
    return "I intend to live forever, so far so good.";  
  }
  public static void four() {
    System.out.println( three() ); 
  }
  public static void main(String[] args) {
    Robot.four(); 
    System.out.println( Robot.three() ); 
    Robot buzz = new Robot(); 
    System.out.println(buzz.talk() + 20) ; 
    // System.out.println( buzz.paint() );  // not good
    buzz.paint(); 
  }
}

Let's design Fraction: 

public class Fraction {
  int num;
  int den; 
  Fraction(int n, int d) {
    num = n;
    den = d;
  }
  public String report() {
    return num + "/" + den;  
  }
  public Fraction add(Fraction other) {
    int numerator = num * other.den + den * other.num; 
    int denominator = den * other.den; 
    return new Fraction(numerator, denominator); 
  }
}

Here's how this works:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Fraction a = new Fraction(1, 2);
> Fraction b = new Fraction(1, 2);
> Fraction c = a.add(b)
> c.report()
"4/4"


Thanks to Kirk, Chris, Jerry, Drake, Chetan and Amara for their help in class today. 

--