CS 145 Lecture 21 – Our own objects
Agenda command-line arguments writing an NDeckerBurger class writing a class: Figure out what it needs to do. (Methods.) Figure out what its persistent state is. (Instance variables.) Figure out how to initialize the state. (Constructor.) midterm 2 Code CommandLineArguments.java package lecture; public class CommandLineArguments { public static void main(String[] args) { // for (int i […]
CS 145 Lab 10
Reminder Show your TA or instructor your completed checkpoints from the last lab in the first 20 minutes of this lab. Object-orientation As we’ve seen in lecture, objects are the marriage of data (instance variables, declared at the class level) and methods. Up until now, our programming has been action- or procedure-oriented. We wrote methods […]
CS 145 Lecture 20 – Midterm 2 Review
Things to know The test is hand-written. You may write SOP instead of System.out.println. You need not import any classes. One page of handwritten notes is allowed. 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 […]
CS 145 Lab 9
Reminder Show your completed lab 8 checkpoints to your TA or instructor in the first 20 minutes of this lab. Checkpoint 1 One of the steps to mastery of a subject is to formulate your own questions. So, for your first checkpoint, please write three questions, one on each of the following topics: logical operators […]
CS 145 Lecture 19 – 2-D arrays
Agenda What does this do? Code Imager.java package lecture; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Random; import javax.imageio.ImageIO; public class Imager { public static void main(String[] args) throws IOException { int width = 512; int height = 256; int[][] pixels = new int[height][width]; // noisify(pixels); stripes(pixels); writeToFile(pixels); } private static void noisify(int[][] […]
CS 145 Lecture 18 – Searching arrays
Agenda linear search the truth behind objects: references stack vs. heap null Code States.java package lecture; import java.util.Scanner; public class States { private static String[] states = { “Alabama”, “Alaska”, “Arizona”, “Arkansas”, “California”, “Colorado”, “Connecticut”, “Delaware”, “Florida”, “Georgia”, “Hawaii”, “Idaho”, “Illinois”, “Indiana”, “Iowa”, “Kansas”, “Kentucky”, “Louisiana”, “Maine”, “Maryland”, “Massachusetts”, “Michigan”, “Minnesota”, “Mississippi”, “Missouri”, “Montana”, “Nebraska”, […]
CS 145 Lecture 17 – Arrays
Agenda arrays in life writing a fill method writing a raffle state/capital lookup Code Fill.java package lecture; public class Fill { public static void main(String[] args) { double[] series = fill(12, 54, 10); for (int i = 0; i < series.length; ++i) { System.out.println(series[i]); } } /** * Create a list of length items, whose […]
CS 145 Preassignment 3 – due before 11/16
See the PDF. When you download speccheck_pre3.jar, make sure the filename ends in “.jar”.
CS 145 Lab 8
Reminder Show your instructor or TA your already completed checkpoints from lab 7 in the first 20 minutes of this lab. Arrays As discussed in class and in your textbook, arrays are simply number collections of data. We can have arrays of primitives and we can have arrays of objects. Making an array looks similar […]
CS 145 Lecture 16 – Arrays
Agenda named data vs. numbered data arrays mapping month numbers to names the birthday problem Code Birthdays Birthdayarator.java package lecture; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Birthdayarator { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File(“/home/cjohnson/Desktop/bdays.txt”)); String[] names = new String[12]; names[0] = “January”; names[1] = “February”; […]