CS 145 Lab 4 – Writing methods
Prelab Complete Self-check 3.13 on the Practice-It website before 8 AM on February 6. Introduction Last time we looked at calling methods that were available in the String, Scanner, and Random classes. This week, we write our own methods. Reminder: Be sure to get your checkpoints from lab 2 checked off in the first 20 […]
CS 145 Lecture 6 – Methods 2
Agenda what does this do? the separation between caller and callee building a snowman method chaining What does this do? Code . <h4>Area.java</h4> <pre class=”code”> package preexam1; public class Area { public static void main(String[] args) { double r1 = 5; // java.awt.Toolkit.getDefaultToolkit().beep(); double area = getArea(8); System.out.println(r1); } public static double getArea(double radius) { […]
CS 145 Lecture 5 – Methods
Agenda print vs. println Scanner oddities don’t repeat yourself methods: hide details encapsulate repeatable processes parameters and return types Code CharacterArithmetic.java package preexam1; public class CharacterArithmetic { public static void main(String[] args) { char c = ‘m’; System.out.print(c + 5); System.out.println(” <- the sum”); c = (char) (c + 5); System.out.println(c); char avgLetter = (‘a’ […]
CS 145 Lecture 4 – String problems and our first method
Agenda extracting names: “LASTNAME, FIRSTNAME MIDDLENAME …” lock the web: does a URL end in .edu? separate a comma-separated list turn “1,234,567” into 1234567 abstraction: hiding details abstracting SVG Code NameFixerUpper.java package preexam1; public class NameFixerUpper { public static void main(String[] args) { String name = “STEINMEYER, JOEL EDWARD”; // names in bad order! // […]
CS 145 Lecture 3 – Algorithms
Agenda algorithm pseudocode program this an early algorithm, a la Euclid primitives have operators objects have methods API String methods Program this You are indecisive. So are your friends. One quiet Monday night, you all decide one night to come up with a list of restaurants, each accompanied by a probability of how often you […]
CS 145 Lab 3 – Using objects
Prelab Complete Self-check 3.14 on the Practice-It website before 8 AM on February 6. Introduction Our variables aren’t just simple numbers anymore. We’ve got complex objects like String and Scanner at our disposal. Today we’ll get more practice at using objects that others have made available. Reminder: Be sure to get your checkpoints from lab […]
CS 145 Lab 2
This lab builds on your readings and lecture discussion of variables and arithmetic operators. We’ll also see two new types, Scanner and String. Before you get started: Load the workspace you made last lab. It should be H:\workspace drive — not on C:. Make a new package named lab2 in your cs145 project. Plea The […]
CS 145 Lecture 2 – More data, more instructions
Agenda what does this do? literals vs. variables a few more types (int, char, boolean) penny RAM a few more instructions (cos, pow) Javadoc String What does this do? Code Day2.java package preexam1; public class Day2 { public static void main(String[] args) { double myNum = 6.7; int brettsFavoriteNumber = 9; char debrasFavoriteLetter = ‘d’; […]