Hanoi void TowersOfHanoi(int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter.

Slides:



Advertisements
Similar presentations
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
Advertisements

Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
Unit 141 Threads What is a Thread? Multithreading Creating Threads – Subclassing java.lang.Thread Example 1 Creating Threads – Implementing java.lang.Runnable.
Albert Johnson Molly Richardson Andrew Kruth.  Threads Runnable interface sleep()  GUIs repaint() paintComponent()
Thread Control methods The thread class contains the methods for controlling threads Thread() create default thread Thread(target: runnable ) creates new.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
(c) 2006 E.S.Boese All Rights Reserved. Threads and Timers Chapter 19 - Student.
1 Review of classes and subclasses M fast through this material, since by now all have seen it in CS100 or the Java bootcamp First packages Then classes.
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
Concurrency Java Threads. Fundamentals Concurrency defines parallel activity Synchronization is necessary in order for parallel activities to share results.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
29-Jun-15 Threads and Multithreading. 2 Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three.
Java Data Types  Everything is an Object  Except Primitive Data Types  For efficiency  Platform independent  Portable  “slow”  Objects are often.
Introduction to Object- Oriented Programming Prof. Shie-Jue Lee Dept. of Electrical Engineering National Sun Yat-sen University.
Java: Animation Chris North cs3724: HCI. Animation? Changing graphics over time Examples: cartoons Clippy, agents/assistants Hour glass Save dohicky Progress.
When confronted with a new problem there are two questions you should ask: 1. Is this problem like, or a special case of, a problem that I already know.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Java Programming Robert Chatley William Lee
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Chapter 15 Multithreading F Threads Concept  Creating Threads by Extending the Thread class  Creating Threads by Implementing the Runnable Interface.
(c) 2008 E.S.Boese All Rights Reserved. Threads and Media Chapter 8 - Lecture Slides 1.
University of Sunderland Java Threading, Mutex and Synchronisation Lecture 02 COMM86 Concurrent and Distributed Software Systems.
PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia.
Lecture 5 : JAVA Thread Programming Courtesy : MIT Prof. Amarasinghe and Dr. Rabbah’s course note.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
Quiz 1 What is this? (explain the use of the reserved word “this” in a class method). Answer each question briefly. – What is a Constructor? –Under what.
Extensible Arrays: Vectors and StringBuffers Problem Set:Assignment #1 due Tuesday, Feburary 13 Wellesley College CS230 Lecture 05 Monday, February.
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.
Lecture 2 Exception handling Advanced Java Programming 1 dr inż. Wojciech Bieniecki
Threads CSCE 190 – Java Instructor: Joel Gompert Wed, Aug 3, 2004.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Chapter 5 Recursion. Basically, a method is recursive if it includes a call to itself.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
IBM TSpaces Lab 3 Transactions Event Registration.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Multithreading in JAVA
Threading and Concurrency COM379T John Murray –
Java 3: Odds & Ends Advanced Programming Techniques.
Java for C++ Programmers A Brief Tutorial. Overview Classes and Objects Simple Program Constructors Arrays Strings Inheritance and Interfaces Exceptions.
A brief introduction to doxygen. What does a compiler do?  A compiler ignores comments and processes the code.  What does doxygen do? –It ignores the.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Threads and Multithreading. Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three general approaches:
Multithreading and Garbage Collection Session 16.
TOWERS OF HANOI. : If n = 1, move disk 1 from pole 'A' to pole 'B'. else: 1.First, move n-1 disks from pole 'A' to pole 'C', using pole 'B' as.
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
Java Applets Adding Animation. Import Files You still need to include the same files: –import java.applet.*; –import java.awt.*;
Chapter 13: Multithreading The Thread class The Thread class The Runnable Interface The Runnable Interface Thread States Thread States Thread Priority.
Chapter 11: Threaded Programs Situations where the program is following multiple execution paths (how to stop one?) Thread: a line of execution Thread.
Multithreaded applets
Chapter 13: Multithreading
Exceptions, Interfaces & Generics
A brief introduction to doxygen
Threads Chate Patanothai.
Overloading and Constructors
null, true, and false are also reserved.
Introduction to Java Programming
The Building Blocks Classes: Java class library, over 1,800 classes:
Java Based Techhnology
13: Concurrency Definition:  A thread is a single sequential flow of control within a program. Some texts use the name lightweight process instead of thread.
JavaScript Reserved Words
Recitation 7 October 7, 2011.
Chapter 15 Multithreading
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
A type is a collection of values
Presentation transcript:

Hanoi void TowersOfHanoi(int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter from the stack specified by the // second parameter to the stack specified by the third // parameter. The stack specified by the fourth parameter // is avaialable for use as a spare. if (disks == 1) { // There is only one disk to be moved. Just move it. console.putln("Move a disk from stack number " + from + " to stack number " + to); } else { // Move all but one disk to the spare stack, then move the bottom disk, then put all the // other disks on top of it. TowersOfHanoi(disks-1, from, spare, to); console.putln("Move a disk from stack number " + from + " to stack number " + to); TowersOfHanoi(disks-1, spare, to, from); }

Labirinto

Inseguitore public class Utils { /** readFile */ public static String readFile(String file) { String str = new String(""); char buf[] = new char[8192]; try { FileReader fin = new FileReader(file); while(fin.read(buf) != -1) str += new String(buf); } catch(Exception e) { str = "Eccezione rilevata: " + e + " "; } return str; } /** replace */ public static String replace(String str, String source, String dest) { int index = 0, lunghSource = source.length(); while ( (index = str.indexOf(source,index)) != -1) { str = str.substring(0,index) + dest + str.substring(index+lunghSource); index += dest.length(); } return str; }

/** * getYear: from a date (source format indicated by flag) */ public static int getYear(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(0,4)); else return 0; } catch(Exception e) {} return 0; } /** * getMonth: from a date (source format indicated by flag) */ public static int getMonth(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(5,7)); else return 0; } catch (Exception e) {} return 0; } /** * getDay: from a date (source format indicated by flag) */ public static int getDay(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(8,10)); else return 0; } catch(Exception e) {} return 0; } /** * getHour: from a date * (source format indicated by flag) */ public static int getHour(String date, int flag){ try { if (flag == 0) return Integer.parseInt(date.substring(11,13)); else return 0; } catch(Exception e) {} return 0; } /** * getMinutes: from a date (source format indicated by flag) */ public static int getMinutes(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(14,16)); else return 0; } catch (Exception e) {} return 0; }

/** * formatDate */ public static String formatDate(String date, int flag) { String strHour; String strMin; int h = Utils.getHour(date,0); if (h < 10) strHour = "0"+h; else strHour = "" + h; int m = Utils.getMinutes(date,0); if (m < 10) strMin = "0"+m; else strMin = ""+m; if (flag == 0) return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0)+ " "+strHour+":"+strMin; if (flag == 1) return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0); // default return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0)+ " "+strHour+":"+strMin; }

/** * Interface for timer functions * Ignazio Locatelli - Media Illusion - (C) 2000 */ package it.MediaIllusion.Anim; public interface TimerInterface { public void tick(); }

* Timer class: calls the tick method every n milliseconds. * * Timer timer = new Timer(this,1000); // 1 second interval * timer.start(); * Ignazio Locatelli */ package it.MediaIllusion.Anim; public class Timer implements Runnable { // main thread protected Thread myThread = null; // milliseconds to wait protected long interval; // interface used TimerInterface callback;

/** * default constructor */ public Timer() { interval = 1000; } /** * constructor long millisecond number of millisecond for the interval TimerInterface callback reference to the interface */ public Timer(long milliseconds, TimerInterface callback) { interval = milliseconds; this.callback = callback; } /** * return milliseconds for an interval */ public long getInterval() { return interval; } /** * set interval long milliseconds number of milliseconds */ public void setInterval(long milliseconds) { interval = milliseconds; }

/** * starts the timer */ public void start() { myThread = new Thread(this); myThread.start(); } /** * stops the timer */ public void stop() { myThread.stop(); myThread = null; }

/** * run */ public void run() { while(true) { long sTime = System.currentTimeMillis(); if (callback != null) callback.tick(); long eTime = System.currentTimeMillis(); long sleep = interval - (eTime-sTime); if (sleep <= 0) continue; try { Thread.sleep(sleep); } catch (Exception e) { System.out.println("Exception during sleep operation\n"); }

/** * Pos: class abstracting a 2D position on a grid Ignazio Locatelli - Media Illusion (C) 2000 */ public class Pos { public int x; public int y; /** * Position */ public Pos() { x = y = 0; } /** * Position */ public Pos(int x, int y) { this.x = x; this.y = y; }

public class InseguitoreConst { public static final int NUM_VITE=4; public static final int MAP_ROWS = 39; public static final int MAP_COLOUMNS = 39; public static final int MAP_CELL_DIMENSION = 8; public static final int PASSO = 4; public static final int DISTANZA_CONTATTO = 36; public static final int SPEED=18; public static final int ACCELERAZIONE=4; public static final int ATTESA=1000; public static final int OFFSET_X = 54; public static final int OFFSET_Y = 34; public static final int OFFSET_PERS_X = 50; public static final int OFFSET_PERS_Y = 30; public static final int START_X1 = 416; public static final int START_X2 = 465; public static final int START_Y1 = 323; public static final int START_Y2 = 377;

public static final int map[][][] = { //liv 1 { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },

import java.awt.image.*; import java.awt.*; import java.applet.*; public class FiltraImmagine extends RGBImageFilter { public FiltraImmagine() { canFilterIndexColorModel = true; } public Image filter(Applet a, Image in) { return a.createImage( new FilteredImageSource(in.getSource(),this) ); } public int filterRGB(int x, int y, int rgb) { int r = ((rgb >> 16) & 0xff)/4; // estra la componente rossa int g = ((rgb >> 8) & 0xff)/4; // verde int b = (rgb & 0xff)/4; // blu int k = (int)(.56*g+.33*r+.11*b); return (0xff | k << 16 | k << 8 | k); //return rgb; }

Ing. Alessandro Campi */ public class Rettangolo { int pezziVisitati=0; int totalePezzi=0; //vertici //in alto a sinistra public int x1, y1; //in basso a destra public int x2, y2; public int x1RealeNormale, y1RealeNormale; public int x1RealeScuro, y1RealeScuro; public int w, h; public int saltoNormaleX, saltoNormaleY; public int saltoNormaleDirettoX,saltoNormaleDirettoY; public int saltoScuroX, saltoScuroY; /** Creates new Rettangolo */ public Rettangolo(int ix1,int iy1,int ix2,int iy2, int xSfondoLivelloNormale,int ySfondoLivelloNormale, int xSfondoLivelloScuro,int ySfondoLivelloScuro, int xBackground,int yBackground) { x1=ix1; y1=iy1; x2=ix2; y2=iy2; x1RealeNormale=xSfondoLivelloNormale+ x1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; y1RealeNormale=ySfondoLivelloNormale+ y1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1;

x1RealeScuro=xSfondoLivelloScuro+ x1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; y1RealeScuro=ySfondoLivelloScuro+ y1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; w=(x2-x1)*InseguitoreConst.MAP_CELL_DIMENSION-1; h=(y2-y1)*InseguitoreConst.MAP_CELL_DIMENSION-1; saltoNormaleX=InseguitoreConst.OFFSET_X- xSfondoLivelloNormale+xBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleY=InseguitoreConst.OFFSET_Y- ySfondoLivelloNormale+yBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleDirettoX=InseguitoreConst.OFFSET_X- xSfondoLivelloNormale+InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleDirettoY=InseguitoreConst.OFFSET_Y- ySfondoLivelloNormale+InseguitoreConst.MAP_CELL_DIMENSION; saltoScuroX=InseguitoreConst.OFFSET_X- xSfondoLivelloScuro+xBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoScuroY=InseguitoreConst.OFFSET_Y- ySfondoLivelloScuro+yBackground+ InseguitoreConst.MAP_CELL_DIMENSION; }

public boolean isIn(int x,int y) { return (x>=x1&&x =y1&&y<=y2); } public void incrementaVisitati() { pezziVisitati++; } public void incrementaTotale() { totalePezzi++; } public boolean controllaCompleto() { return (pezziVisitati==totalePezzi); }