CS 145 Lecture 15 – More colliding
Agenda meet JFrame and company collide circles collide rectangles Code CollisionUtilities.java package lecture; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class CollisionUtilities { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File(“/home/cjohnson/Desktop/lines.txt”)); while (in.hasNextDouble()) { double leftA = in.nextDouble(); double rightA = in.nextDouble(); double leftB = in.nextDouble(); double rightB = […]
CS 145 Lecture 14 – Testing and conditionals via collision detection
Agenda lab switcharoo collision detection test-driven development Collision detection Code CollisionUtilities.java package lecture; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class CollisionUtilities { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File(“/home/cjohnson/Desktop/lines.txt”)); while (in.hasNextDouble()) { double leftA = in.nextDouble(); double rightA = in.nextDouble(); double leftB = in.nextDouble(); double rightB = […]
CS 145 Lecture 13 – Loop tricks
Agenda which loop when? conditioning on sentinel values fencepost loops nested loops Code ForAWhile.java package lecture; import java.util.Scanner; public class ForAWhile { public static void main(String[] args) { // String command = “notdone”; // for (Scanner in = new Scanner(System.in); !command.equals(“done”); command = in.next()) { // } String command = “notdone”; Scanner in = new […]
CS 145 Lab 7
Reminder Show your completed lab 6 checkpoints to your instructor or TA in the first 20 minutes of this lab. All code for this lab should go in a package named lab7. Cards Each of today’s problems involves a deck of cards. Though we use card terminology, you do not need to have ever touched […]
CS 145 Exam 1
Exam 5-point summaries of individual question and overall scores.
CS 145 Lecture 12 – Conditionals and file input
Agenda generating an ordinal number if/else if reading from files (brief treatise on exceptions) test-driven development categorizing light Code Ordinals.java package lecture; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Ordinals { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File(“/home/cjohnson/Desktop/ordinals.txt”)); while (in.hasNextInt()) { int i = in.nextInt(); String expected […]
CS 145 Lecture 11 – Conditionals
Agenda how’d the exam go? what does this do? conditionals in Secret Maryo Chronicles pluralizing generating a star generating an ordinal number categorizing light — if/else if What does this do? Code Conditional.java package lecture; public class Conditional { public static void main(String[] args) { star(100); System.out.println(pluralize(“Nick”, 42)); System.out.println(pluralize(“Nick”, 1)); System.out.println(pluralize(“Nick”, -1)); System.out.println(pluralize(“Nick”, -87)); } […]
CS 145 Lab 6
Reminder Please submit your completed lab 5 checkpoints in the first 20 minutes of this lab. Logical operators In lecture we’ve explored the logical operators &&, ||, and !. These operators are as important to a programmer as a screwdriver and hammer are to a mechanic. Do whatever you can to learn their use. Like […]
CS 145 Homework 2 – due before 11/2
See the PDF. When you download speccheck_hw2.jar, make sure the filename ends in “.jar”.
CS 145 Lecture 10 – Midterm 1 review
Things to know The test is hand-written. You may write SOP instead of System.out.println. You need not import any classes. The front page of the exam will contain compact documentation for the Scanner, Random, and String classes. A strategy: on questions where you are asked to write a method, write the method signature first, not […]