CS 145 Lecture 7 – Random and Naming Our Code
Agenda
- what ?s
- grading twist
- weekly outside problems
- a parameterized circle
- a random parameterized circle
- methods
- a bunch of random parameterized circles
- hungry methods
- prepping data for mail merge
TODO
- Attend the first SACM meeting. Several students will be speaking on their internship experiences from this past summer. Ask a thoughtful question of one of the speakers, and share it and its answer on an extra credit 1/4 sheet.
- Read sections 1.4 and chapter 3 through section 3.3. Turn in a 1/4 sheet with two questions/two observations.
Code
Circle.java
package lecture0917;
import java.util.Random;
public class Circle {
public static void main(String[] args) {
Random generator = new Random();
System.out.println("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">");
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
printCircle(generator);
System.out.println("</svg>");
}
public static void printCircle(Random g) {
int cx = g.nextInt(1000);
int cy = g.nextInt(600);
int r = g.nextInt(23) + 1;
int red = g.nextInt(256);
int green = g.nextInt(256);
int blue = g.nextInt(256);
System.out.printf("<circle cx=\"%d\" cy=\"%d\" r=\"%d\" stroke=\"black\" stroke-width=\"2\" fill=\"rgb(%d, %d, %d)\" />%n",
cx, cy, r, red, green, blue);
}
}
Haiku
on roboflowers.com:
Happy birthday, #NAME!
Love you forever + 1,
#CUSTOMERID
Happy birthday, #NAME!
Love you forever + 1,
#CUSTOMERID