CS 145 Lecture 12 – File I/O
Agenda program this nested loops printf reverse engineering reading from a file with Scanner writing to a file with PrintWriter TODO Read chapter 5. Reverse Engineering Code Bored.java package preexam2; public class Bored { public static void main(String[] args) { for (int r = 1; r <= 8; ++r) { for (int c = 1; […]
CS 145 Exam 1
Exam See the PDF. Results
CS 145 Lab 6 – Logical operators and conditionals
Prelab Complete Self-check 5.14 on the Practice-It website before 8 AM on March 12. 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. Suppose you have […]
CS 145 Lecture 11 – Finalizing the big three
Agenda nesting printf Mr. Right leap exam TODO Read sections 4.2 and 4.3. Reverse Engineering Code MrRight.java public class MrRight { public static boolean getTrue() { System.out.println(“true”); return true; } public static boolean getFalse() { System.out.println(“false”); return false; } public static void main(String[] args) { // boolean b = getTrue() && getFalse(); // boolean b […]
CS 145 Lecture 10 – Logical operators and if
Agenda logical operators: && || if statements interval checking clamping a value getting someone’s title Code IntervalCheck.java package preexam1; public class IntervalCheck { public static boolean isInInterval(int lo, int hi, int givenPointX) { return lo <= givenPointX && givenPointX <= hi; } public static void main(String[] args) { System.out.println(false == isInInterval(0, 10, -5)); System.out.println(true == […]
CS 145 Lecture 9 – Loops: for and while
Agenda exam coming up! for loop problems digitizing a circle spreadsheet fill for (INIT; TEST; UPDATE) { ACTION } INIT while (TEST) { ACTION UPDATE } while loop problems summing an indefinite number of numbers checking for repeated words decomposing a comma-separated list prompting for an actual file TODO Read chapter 3 (mostly discussed already) […]
CS 145 Lab 5 – Testing and loops
Prelab Complete Exercise 3.1 on the Practice-It website before 8 AM on February 20. Testing Once you’ve wrapped some code up inside a method, it becomes a candidate for quality assurance. You must poke it and prod it to make sure it does what its specification says it does. But here’s the kicker: you should […]
CS 145 Lecture 8 – Loops
Agenda for loops acrostic spelunking display approximating a circle Code ForFun.java package preexam1; public class ForFun { public static void main(String[] args) { for (int i = 0; i < 3; i = i + 1) { System.out.println(“Bye, Patrick!”); } int sum = 0; for (int i = 1; i <= 100; i = i […]
CS 145 Lecture 7 – Careful coding
Agenda relational operators software disaster careful coding pseudocode build in small pieces test pieces in isolation document some problems to test area of ring Code Utilities.java package preexam1; public class Utilities { // i = get area of inside // o = get area of outside // area = o – i public static double […]