Howdy. 

How are you? 

C212/A592 Introduction to Software Systems

http://www.cs.indiana.edu/classes/c212

http://registrar.indiana.edu/browser/soc4185fac/CSCI/CSCI-C212.shtml

Adrian German dgerman 

Santiago Salmeron ssalmero 

Minute paper: 

 1. Name, username, major, minor

 2. Reasons for taking this class

 3. Have you taken this class before

 (Where? If so how did you do?)  

 4. Have you taken C211? How did you do? 

    Have you taken C200? How did you do? 

 5. Expectations for this class

 6. Fears or concerns at this time that I can try address

 7. What do you want to be able to do at the end of this that 
    you cannot do now to feel accomplished? 

 8. Anything else? 


Object-oriented programming in Java. 

Let's open the textbook. 

There are also other resources. 

You should come from C211. 

In C211 you have learned something: 

  (a) there is an IDE (DrRacket) with a definitions area and an interactions panel

http://www.drjava.org/download.shtml

DrJava, IntelliJ, Eclipse, BlueJ, command line (prompt)

You might be going to C343. In that case buckle up... 

  (b) the IDE has an interactions panel where you can practice simple expressions 

That's what we are going to do to start this class. 


To do well in this class: 

  1. Understand/Learn what we teach you 

  2. You have to teach it to others 

  3. Practice it 


Welcome to DrJava.  Working directory is C:\Users\dgerman
> 1
1
> 3.141592
3.141592
> 1 + 2
3
> Math.PI
3.141592653589793


Let's focus on numbers only. 

Operators for numbers: + * - / % and so on ... 

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 3 / 2
1
> 3 / 5
0
> 3 % 5
3
> 7 % 2
1
> 7 / 2
3


Operators are integers then result is integer. 

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 1 / 2
0
> 1.0 / 2.0
0.5
> 1.0 / 2
0.5
> 1 / 2.0 
0.5
> 1 / 2
0


Let's work with these numbers now. 

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 0.1
0.1
> 0.1 + 0.1
0.2
> 0.1 + 0.1 + 0.1
0.30000000000000004
> 0.1 + 0.1 + 0.1 + 0.1
0.4
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.5
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.6
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.7
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.7999999999999999
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.8999999999999999
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.9999999999999999


What happens?

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 4.35 * 100
434.99999999999994
> 4.53 * 100
453.0


How can you fix this? 

Welcome to DrJava.  Working directory is C:\Users\dgerman
> Math.abs(-3)
3
> Math.abs(12)
12
> Math.sqrt(2)
1.4142135623730951
> Math.sqrt(3)
1.7320508075688772
> Math.pow(2, 3)
8.0
> Math.pow(Math.sqrt(2), 2)
2.0000000000000004


Notice the notation. 

Welcome to DrJava.  Working directory is C:\Users\dgerman
> BigDecimal a = new BigDecimal("4.35");
Static Error: Undefined class 'BigDecimal'
> import java.math.BigDecimal; // auto-import
BigDecimal a = new BigDecimal("4.35");
> a
4.35
> a + 1
Static Error: Bad type in addition
> BigDecimal b = new BigDecimal("100");
> b
100
> a
4.35
> a * b
Static Error: Bad type in numeric expression
> a.multiply(b)
435.00
> b.multiply(a)
435.00
> 4.35 * 100
434.99999999999994
> a
4.35
> b
100


That's how you fix it. 

Exercise: 

Using BigDecimals calculate 

  0.1 + 0.1

  0.1 + 0.1 + 0.1

  0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1