Lecture 5, CS 302-7 and 8, February 1
i. Can update/view after creating
ii. Make sure to use your cs login/password (not wisc login)
i. Do you have to do it? No
ii. Useful and extra credit
1. Best way to learn is by doing
2. Register with wisc email and last/first name (so we know who you are)
i. Now active
ii. Use versions of eclipse and java posted
iii. If using a Mac on Leopard (or earlier) make sure to follow directions so that you have the right version of Java.
i. In general: If my door’s open, come in!
i. final int FIELD_GOAL=3;
i. All caps
ii. _ to separate words
i. Should use Constants wherever you have a ‘magic number’ in code. – like before with field goals
1. Say, we had a complicated football program, and field goal is referenced a bunch of places in it.
2. Now, say the rules change, so a field goal is worth four points.
3. If we use a constant, we just have to change the value once, when we declare the constant.
4. If we were using 3, we would have to search our program for everywhere that uses 3 like that and change it.
i. Pretty much the same reason we use descriptive variable names
i. //
ii. /* */
iii. /** */
1. For documentation tools like JavaDoc
i. When something is unclear or confusing
ii. In general, use ‘as needed’. Don’t need to comment every line, but reasons for initial variable values, complicated equations etc are good places.
iii. Will it slow down your program to use comments?
1. No, because they are not compiled into the Java Byte Code
i. You can overwrite this value
i. C++ J
i. Variable, class, method names, etc
i. Input – keyboard, mouse, etc
ii. Output – monitor, printer, etc
1.
eg
System.out.println();
i. Step 1 – import java.util.scanner;
1. Or, java.util.*;
2. This goes before any other code in your program
ii. Step 2 – declare scanner object
1. Scanner <name>=new Scanner(System.in);
2. Example: Scanner in=new Scanner(System.in);
iii. Step 3 - prompt user. Describe what they should enter
1. Use print instead of println so it’s on same line
iv. Step 4 – in.nextInt(), in.nextDouble(),in.next()
1. Store the value returned by one of the above in a variable.
2. Example: int a=in.nextInt();
3. Note – this prints a new line for us
v. Example – Birthday.java
i. Note – we’ve been doing this without really thinking about it
ii. Operand
1. things we are acting on
2. variable
3. object of operator
iii. Operator
1. +,-, etc
i. Like a remainder
ii. 7%4=3 because, if you divide 7 by 4, you have 3 left over.