Java Programming. Objectives Introduce Software Engineering Concepts Introduction to Object Oriented and Java Programming Provide Context for Software.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Web Application Development Slides Credit Umair Javed LUMS.
Written by: Dr. JJ Shepherd
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
Road Map Introduction to object oriented programming. Classes
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CS 1110 Final Exam: Review Session 2 Part 1 : Inheriting classes 1. Inheritance Facts 2. Constructors in Subclasses BREAK : 10 sec. Part 2 : Working with.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Programming Languages and Paradigms Object-Oriented Programming.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Java Language and SW Dev’t
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
© A+ Computer Science - Inheritance © A+ Computer Science - Lab 20.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
The Java Programming Language
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
10-Nov-15 Java Object Oriented Programming What is it?
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
CMSC 150 CLASSES CS 150: Mon 6 Feb 2012 Images: Library of Congress.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Classes, Interfaces and Packages
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Written by: Dr. JJ Shepherd
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Information and Computer Sciences University of Hawaii, Manoa
The need for Programming Languages
Object-Oriented Design
Advanced Software Concepts
Classes and OOP.
Java Software Solutions
Software Development Java Classes and Methods
Objects First with Java A Practical Introduction using BlueJ
Introduction to the C Language
Lesson 4: Overall Review and Assessment
Object-Oriented Programming
Objects First with Java A Practical Introduction using BlueJ
Outline Anatomy of a Class Encapsulation Anatomy of a Method
COP 3330 Object-oriented Programming in C++
Session 2: Introduction to Object Oriented Programming
Object-Oriented Programming
CIS 199 Final Review.
Objects First with Java A Practical Introduction using BlueJ
Java Software Solutions
Presentation transcript:

Java Programming

Objectives Introduce Software Engineering Concepts Introduction to Object Oriented and Java Programming Provide Context for Software in FRC Robotics Provide Foundation Interacting with Programming Team

Agenda Introduction Philosophy Object Oriented Java Syntax FRC Robotics  Libraries  Tele-operated  Autonomous

Introduction Mr. Rich Vitkus  BS Computer Science at Rensselaer Polytechnic Institute  Manager of Enterprise Architect, Lowe’s Home Improvement  3 years FLL, 4 th year FTC, 6 th year FRC Evan Vitkus  VP Programming  2 years FLL, 2 nd year FTC, 2 nd year FRC

Philosophy Computers do what you tell them to do, not what you want them to do. Different results mean either the software, the system, or the data has changed Reuse ideas, libraries, and code. Test and debug systematically with as much information as possible. Programming is not art it is engineering. The standards and process are essential to success.

Object Oriented Consider an airport system in the real world. It consists of many different parts which work together to get work done  Control tower, airplane, runways, fuel trucks, security agent, … When we build a software systems, some of the software objects have corresponding names  Class ControlTower, class Airplane, class Runway, … Reduces “representation gap” between software model and solution we are building  Improves comprehension, communication, and predictability

Object Oriented – Real World Object Consider an airplane in the airport system. What is important? Real world objects have information  Airplanes have a model number, serial number, speed, altitude Real world objects also do things  Airplanes can land, take off, change speed, turn, …

Object Oriented – Software Object Have names corresponding to the real world system  Class Airplane Store information – attributes  modelNumber, serialNumber, speed, altitude Perform actions – methods  land(), takeOff(), changeSpeed(), turn()

Object Oriented – Software Object An object bundles data (attributes) and code to perform actions (methods) into one, cohesive unit Airplane speed model land() takeOff() //Java source code class airplane { private int speed; private int model; public void land() { … } public void takeOff() { … }

Object Oriented – Project Simple dice game  Each player rolls two dice ten times  The player rolling seven or more the most times is the winner

Object Oriented – Project Identify the real world objects in the game  Game  Player  Die

Object Oriented – Project Identify the attributes of each object in the game Game  dice  players Player  name  score Die  value

Object Oriented – Project Identify the methods of each object in the game Game  play Player  takeTurn  incrementScore  getScore Die  roll

Object Oriented – Class and Instance Class  Definer: A blueprint that stores the definition for instances  Creator: A factory for creating software objects of one kind Instance  Instantiated (created) by a class  Occupies space in computer memory  Retains values of attributes  Has behavior An object bundles data (attributes) and code to perform actions (methods) into one, cohesive unit Die value roll() die1:Die value=3

Java Syntax - Attributes Java is strongly typed Two basic types in Java  Primitive – int, double, boolean, char, etc  private int value;  Object – created from classes  private Die die1; Variables– attributes which can change values Constants – attributes which do not change values  private final int SIDES = 6;

Java Syntax - Methods Methods can perform actions, have parameters, and return values Public void setName(String playerName) { name = playerName; } public int roll() { value = (int)(Math.random()*SIDES) + 1; return value; }

Java Syntax – Control Structures - Conditional If statements handle boolean (true or false) conditions if (i == 3) doSomething(); if (i == 2) doSomething(); else doSomethingElse(); if (i == 3) { doSomething(); } else if (i == 2) { doSomethingElse(); } else { doSomethingDifferent(); }

Java Syntax – Control Structures - loops Loops repeat a segment of code // validate a boolean condition then execute while (i < 10) { doSomething(); } // execute then validate a boolean condition (always // run at least once do { doSomething(); } while (i < 10); // execute a specific number of times for (int i = 0; i < 10; i++) { doSomething(); }

Java Syntax – Project public class Game { private Player player1; private Player player2; private Die die1; private Die die2; private int score; public void play() { for (int i = 0; i < 10; i++) { score = die1.roll() + die2.roll(); if (score > 7) { player1.incrementScore(); } for (int i = 0; i < 10; i++) { score = die1.roll() + die2.roll(); if (score > 7) { player2.incrementScore(); } if (player1.getScore() > player2.getScore()) { System.out.print("Player 1 wins"); } else { System.out.print("Player 2 wins"); }

Agenda Introduction Philosophy Object Oriented Java Syntax FRC Robotics  Robot  Libraries  Tele-operated  Autonomous

FRC Robotics – Object Oriented Software Objects correspond to Real World Objects Reduces “representation gap” between software model and solution we are building  Improves comprehension, communication, and predictability An object bundles data (attributes) and code to perform actions (methods) into one, cohesive unit

FRC Robotics Input Process Output

Lunacy ull.wmv ull.wmv

Robot – Photo 1

Robot – Photo 2

Robot – Photo 3

FRC Robotics - Libraries FRC Javadoc   import edu.wpi.first.wpilibj.Joystick;  import edu.wpi.first.wpilibj.RobotDrive;  import edu.wpi.first.wpilibj.Victor;  import edu.wpi.first.wpilibj.Servo;  import edu.wpi.first.wpilibj.Jaguar;  import edu.wpi.first.wpilibj.Compressor;  import edu.wpi.first.wpilibj.camera.AxisCamera; Getting Started with Java for FRC

FRC Robotics – Teleoperated Human Players control the robot Software controls the robot Event Loop Input  JoySticks  Sensors  Timer  Camera Process  Calculations Output  Speed controllers  Solenoid

FRC Robotics – Teleoperated Human Driver and Human Robot  Eyes open  Eyes closed

FRC Robotics – Teleoperated Pseudo Code

FRC Robotics – Autonomous No Human Players Software controls the robot Input  Sensors  Timer  Camera Process  Calculations Output  Speed controllers  Solenoid

FRC Robotics – Autonomous Human Robot  Vision  Touch  Time

FRC Robotics – Autonomous Pseudo Code

FRC Robotics – Questions

FRC Robotics – Appendix Slides removed to reduce to 75 minutes

Java Syntax - Methods Setters and Getters  Setters are a public method to set the value of private attributes  Getters are a public method to get the value of private attributes Player Public void setName(String playerName) Public String getName() Public void setScore(int playerScore) Public int getScore()

Object Oriented – Concepts Cohesion – strongly related responsibilities of a software component Encapsulation – hide information or details  Attributes are private (only exposed to the class)  Methods are public (exposed to the world) Polymorphism – multiple methods with the same name which operate on different data  print(file)  print(integer) Inheritance – a generalization, specialization hierarchy. Extend or override functionality and data from a parent (super) class  boy is a human is a mammal

Object Oriented – Project Game PlayerDie PlaysHas Rolls

Dice Game Code - Die public class Die { private final int SIDES = 6; int value; public int getValue() { return value; } public int roll() { value = (int)(Math.random()*SIDES) + 1; return value; }

Dice Game Code - Player public class Player { private String name; private int score = 0; public void setName(String playerName) { name = playerName; } public String getName() { return name; } public int getScore() { return score; } public void takeTurn(Die die1, Die die2) { int roll; score = 0; for (int i = 0; i < 10; i++) { roll = die1.roll() + die2.roll(); if (roll > 7) { incrementScore(); } public void incrementScore() { score += 1; }

Dice Game Code - Game public class Game { private static Player player1 = new Player(); private static Player player2 = new Player(); private static Die die1 = new Die(); private static Die die2 = new Die(); public static void play() { player1.takeTurn(die1, die2); player2.takeTurn(die1, die2); if (player1.getScore() > player2.getScore()) { System.out.print("Player 1 wins " + player1.getScore() + " to " + player2.getScore()); } else if (player1.getScore() < player2.getScore()){ System.out.print("Player 2 wins " + player2.getScore() + " to " + player1.getScore()); } else { System.out.print("It's a tie " + player2.getScore() + " to " + player1.getScore()); }

Java Syntax – Control Structures - Conditional Switch statements handle multiple cases switch (ch) { case 'A': doSomething(); // Triggered if ch == 'A' break; case 'B': case 'C': doSomethingElse(); // Triggered if ch == 'B' or ch == 'C' break; default: doSomethingDifferent(); // Triggered in any other case break; }

Java Syntax – Arrays Arrays are an ordered collection  A dozen eggs  The passengers on an airplane // one dimensional array int[] numbers = new int[5]; numbers[0] = 2; numbers[1] = 5; int x = numbers[0]; // multi dimensional array int[][] numbers = new int[3][3]; number[1][2] = 2;