• translate can refer to the x and y of the object it was called on. • Example: getMove can return only one move at a time.getMove can't use loops to return a sequence of moves. The implicit parameter • implicit parameter:The object on which an instance method is called. ",#(7),01444'9=82. security provider architecture example programs, ON TO JAVA - . cheng-chia chen. Introduction to Programming Using Java Version 5.0, December 2006 (Version 5.0.2, with minor corrections, November 2007) David J. Eck Hobart and William Smith Colleges lecture outline. "); } else { System.out.println("Caio wins! when to use team, Building Java Programs - . console. View chapter 2_2018(1).ppt from COMPUTER CIS009 at Stratford University. University of Washington, CSE 142 course web site (CS1) University of Washington, CSE 143 course web site (CS2) (web sites for our CS1 and CS2 courses at UW that use the Building Java Programs textbook) public class PointMain { public static void main(String[] args) { // create two Point objects Point p1 = new Point(7, 2); Point p2 = new Point(4, 3); // print each point System.out.println("p1: " + p1); System.out.println("p2: " + p2); // compute/print each point's distance from the origin System.out.println("p1's distance from origin: " + p1.distanceFromOrigin()); System.out.println("p2's distance from origin: " + p1.distanceFromOrigin()); // move p1 and p2 and print them again p1.translate(11, 6); p2.translate(1, 7); System.out.println("p1: " + p1); System.out.println("p2: " + p2); // compute/print distance from p1 to p2 System.out.println("distance from p1 to p2: " + p1.distance(p2)); } }, Encapsulation reading: 8.5 - 8.6 self-check: #13-17 exercises: #5, Battle to the Death • Write a program that simulates a battle to the death • Each player has a 50% chance of attacking the other • Battle ends when either player’s isAlive() returns false • Each player should be an instantiation of the Hero class: public class Hero { int hitPoints; // life meter public Hero() { hitPoints = 100; } public int getAttack() { return 10; } public boolean isAlive() { return hitPoints > 0; } public String toString() { return "HP: " + hitPoints; } }. basic java programs programs and. Get powerful tools for managing your contents. object: An entity that combines state and behavior Java class: Program An executable program with a main method Can be run; statements execute procedurally What we’ve been writing all quarter public class BMI2 { public static void main(String[] args) { giveIntro(); Scanner console = new Scanner(System.in); double bmi1 = getBMI(console); double bmi2 = getBMI(console); … PowerPoint Lecture Slides for Building Java Programs. Create stunning presentation online in just 3 steps. Solution code, con’t. most commonly refers to run time Assume the following: Any single Java statement takes same amount of time to run. lectures correspond to and are based almost, Future Planning: - . Why the problem is hard Arrays Array declaration Array declaration, cont. HW7 due TOMORROW at 11:30 HW8 is going out TODAY, due NEXT WEDNESDAY Everyone is getting 1 extra late day to use as you see fit, Building Java Programs Chapter 8: Classes Lecture 8-2: Constructors, Encapsulation, Critters reading: 8.4 - 8.6, Announcements • HW7 due TOMORROW at 11:30 • HW8 is going out TODAY, due NEXT WEDNESDAY • Everyone is getting 1 extra late day to use as you see fit • Final is NEXT FRIDAY in lecture. Building Java Programs Objects String, Character and Scanner Strings • … This preview shows page 1 - 8 out of 26 pages. • if the animal has moved onto food, ask it if it wants to eat • Key concept: The simulator is in control, NOT your animal. • It is bad style to write objects in a way that gives direct access to fields, Encapsulation • encapsulation: Hiding implementation details of an object from its clients. 7 #5 public void translate(int dx, int dy) { x += dx; y += dy; } } • The translate method no longer has a Point p parameter. 4 #24-27 exercises: Ch. Building Java Programs Chapter 2: Primitive Data and Definite Loops These lecture notes are copyright (C) Marty Stepp and Example: DrawingPanel p = new DrawingPanel(100, 100); Graphics g = p.getGraphics(); Polygon poly = new Polygon(); poly.addPoint(10, 90); poly.addPoint(50, 10); poly.addPoint(90, 90); g.setColor(Color.GREEN); g.fillPolygon(poly); hi bye Building Java Programs Supplement 3G: Graphics Chapter outline drawing 2D graphics DrawingPanel and Graphics objects drawing and … Building Java Programs Chapter 4 Lecture 4-2: Strings reading: 3.3, 4.3 - 4.4 self-check: Ch. PowerPoint Lecture Slides for Building Java Programs. The public static void keywords mean the Java 1 virtual machine (JVM) interpreter can call the program's main method to start the program (public) without creating an instance of the class (static), and the program does not return data to the Java VM interpreter (void) when it ends.. An instance of a class is an executable copy of the class While the class describes the data and … Announcements. reading: 10.1. program execution: The act of carrying out the instructions contained in a program. Chapter 10. A solution that uses an array: String[] allWords = new String[1000]; int wordCount = 0; Scanner input = new Scanner(new File("words.txt")); while (input.hasNext()) { String word = input.next(); allWords[wordCount] = … PointMain.java (client program) public class PointMain {main(String args) {Point p1 = new Point(); p1.x = 7; p1.y = 2; Point p2 = new Point(); p2.x = 4; p2.y = 3;...}} Point.java (class of objects) public class Point {int x; int y;} x 7 y 2 x 4 y 3 part b looks at, TEAM BUILDING - . 7 #8, Ch. Words exercise Write code to read a file and display its words in reverse order. public Point(int initialX, int initialY) { x = initialX; y = initialY; } public void translate(int dx, int dy) { x = x + dx; y = y + dy; } }, Tracing a constructor call • What happens when the following call is made? View chapter 2_2018(1) - Copy.ppt from COMPUTER CIS009 at Stratford University. Logical operators • Tests can be combined using logical operators: • "Truth tables" for each, used with logical values p and q: • toString: Always returns "C". View ch04RR copy.ppt from COMPUTER CIS009 at Stratford University. Building Java Programs. *; • Create a … the software crisis. Random rand = new Random(); Hero victoria = new Hero(); Hero caio = new Hero(); // catastrophe! a deceptive problem. chapter outline. A statement ends with a semi-colon (;). WELCOME ... Building Efficiency Up to 15 points. 4 #15, 16 videos: Ch. Point p1 = new Point(7, 2); public Point(int initialX, int initialY) { x = initialX; y = initialY; } public void translate(int dx, int dy) { x = x + dx; y = y + dy; }, Client code, version 3 public class PointMain3 { public static void main(String[] args) { // create two Point objects Point p1 = new Point(5, 2); Point p2 = new Point(4, 3); // print each point System.out.println("p1: (" + p1.x + ", " + p1.y + ")"); System.out.println("p2: (" + p2.x + ", " + p2.y + ")"); // move p2 and then print it again p2.translate(2, 4); System.out.println("p2: (" + p2.x + ", " + p2.y + ")"); } } OUTPUT: p1: (5, 2) p2: (4, 3) p2: (6, 7), The toString method reading: 8.6 self-check: #18, 20-21 exercises: #9, 14, Printing objects • By default, Java doesn't know how to print objects: Point p = new Point(10, 7); System.out.println("p: " + p); // p is Point@9e8c34 • We can print a better string (but this is cumbersome): System.out.println("p: (" + p.x + ", " + p.y + ")"); • We'd like to be able to print the object itself: // desired behavior System.out.println("p: " + p); // p is (10, 7), The toString method • tells Java how to convert an object into a String • called when an object is printed/concatenated to a String: Point p1 = new Point(7, 2); System.out.println("p1 is " + p1); • If you prefer, you can write .toString() explicitly.
Business Ethics: Ethical Decision Making & Cases, 11th Edition,
Overhead Door Model 1026 Homelink,
Bud, Not Buddy Chapter 11 Characters,
Underground Railroad Map Activity,
Masks Poem Answer Key,
Noir Gallery Reviews,