Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.

Slides:



Advertisements
Similar presentations
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Advertisements

The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Copyright © Texas Education Agency, Computer Programming Class Basics.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
Objects. Strings String x = “abc”; String is a class, not a primitive x.charAt(2) is ‘b’ use name and ‘.’ and name.
Classes and Objects in Java
Writing a Class (defining a data-type). Create a new project : Project (uncheck the “Create Main Class”)
Saravanan.G.
UML Basics & Access Modifier
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
Creating Simple Classes. Outline of Class Account Class Account Account # Balance Holder name phone# Overdrawn (true/false) Data Members Open Credit Debit.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
A Revamping Of our skills so far. Our Tools so Far Variable - a placeholder for a value Method - a set of code which accomplishes a task Class - a mold.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
Case study Students. Array of objects Arrays can hold objects (ref to objects!) Each cell in an array of objects is null by default Sample: from student.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Introduction To Java Programming 1.0 Basic Concepts of Java Programming 2.0 Classes, Polymorphism and Inheritance 3.0 Exception handling 4.0.
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Classes - Intermediate
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
Topics Instance variables, set and get methods Encapsulation
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Problem of the Day  Why are manhole covers round?
CLASSES IN JAVA Primitive Types Example of a Class Allocating Objects of a Class Protecting Class data Constructors Static data and Static Methods.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
OOP Powerpoint slides from A+ Computer Science
Examples of Classes & Objects
USING ECLIPSE TO CREATE HELLO WORLD
HKCT Java OOP Unit 02 Object Oriented Programming in Java Unit 02 Methods, Classes, and Objects 1.
Interfaces and Constructors
Classes & Objects: Examples
More on Classes and Objects
Unit-2 Objects and Classes
Assignment 7 User Defined Classes Part 2
© A+ Computer Science - OOP © A+ Computer Science -
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Simple Classes in Java CSCI 392 Classes – Part 1.
class PrintOnetoTen { public static void main(String args[]) {
© A+ Computer Science - Classes And Objects © A+ Computer Science -
© A+ Computer Science - OOP Pieces © A+ Computer Science -
Object-Oriented Programming and class Design
Methods/Functions.
ITE “A” GROUP 2 ENCAPSULATION.
Presentation transcript:

Programming in Java Transitioning from Alice

Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes here }

Your project and classes are similar

Both functions and methods are referred to as methods in Java

void methods are methods which do not return values

Methods with “return types” are often referred to as functions – just as in Alice, they can return numbers (called int or double s), boolean s, String s, or Objects

Properties in Java are referred to as private instance variables

Simple Programs Very simple program to print a name Simple program to test a separate class and instantiated objects

Output from Play

Java from Eclipse main method

Running it Output

Bunny and UseBunny Create a Bunny class Properties : color and age Modifier methods to change those properties Accessor methods to return those properties Special method of reach class used to create the instances – called constructor

Constructor and Instance Variables class Bunny { //In Java need a constructor for every new class public Bunny() //set default properties { age = 0; color = "white"; } //private instance variables (like properties) int age; String color;

Accessor Methods -- usually functions //accessor methods public String giveColorInfo() { return color; } public int giveAgeInfo() { return age; }

Modifier Methods // modifier methods – change properties public void setColor (String newColor) { color = newColor; } public void setAge (int newAge) { age = newAge; }

UseBunny.java Revisited class UseBunny{ public static void main(String[] arg) { Bunny b = new Bunny(); //like add Object Bunny b1 = new Bunny(); b.setAge(6); b1.setColor("green"); System.out.println("The first bunny is :"); System.out.println(b.giveAgeInfo() + " and is " + b.giveColorInfo()); System.out.println("The second bunny is :"); System.out.println(b1.giveAgeInfo() + " and is " + b1.giveColorInfo()); }

Java Assignment Java Assignment 1 – Part 1:Make the Lab1 project and run the FirstOne Java program Part 2: Make the Lab1PtII project and get the UseBunny and Bunny to work