1 / 6

Modula vs Java

Modula vs Java. MODULE Show; CONST PI = 3.141592653589793238; TYPE PointRc = RECORD x,y : INTEGER; speed : REAL; angle : REAL; END; VAR a,b : PointRc; BEGIN a.x := 0; a.y := 0; a.speed := 12.5; a.angle := PI/2; b.x := 100; b.y := 150; b.speed := 5.0;

quilla
Download Presentation

Modula vs Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modula vs Java MODULE Show; CONST PI = 3.141592653589793238; TYPE PointRc = RECORD x,y : INTEGER; speed : REAL; angle : REAL; END; VAR a,b : PointRc; BEGIN a.x := 0; a.y := 0; a.speed := 12.5; a.angle := PI/2; b.x := 100; b.y := 150; b.speed := 5.0; b.angle := 3*PI/4; END Show. publicclass Point { int x,y; double speed; double angle; } publicclass Show { publicstaticvoid main(String args[]) { Point a,b; a = new Point(); a.x = 0; a.y = 0; a.speed = 12.5; a.angle = Math.PI / 2; b = new Point(); b.x = 100; b.y = 150; b.speed = 5.0; b.angle = 3*Math.PI / 4; } }

  2. Public vs Private publicclass Point { publicint x,y; publicprivatedouble speed; publicdouble angle; publicvoid setSpeed(double newSpeed) { if (newSpeed > speed) { System.out.println("we gaan sneller!"); } speed = newSpeed; } publicdouble getSpeed() { return speed; } }

  3. Constructor publicclass Point { publicint x,y; publicdouble angle; privatedouble speed; public Point(int x, int y) { this(x,y,0,0); } public Point(int x, int y, int speed, int angle) { this.x = x; this.y = y; this.speed = speed; this.angle = angle; } publicvoid setSpeed(double newSpeed) { if (newSpeed > speed) { System.out.println("we gaan sneller!"); } speed = newSpeed; } } publicclass Show { publicstaticvoid main(String args[]) { Point a,b,c; a = new Point(0, 0, 12.5, 0.5*Math.PI); b = new Point(100, 150, 5.0, 0.75*Math.PI); c = new Point(200, 400); } }

  4. Inheritance Voertuig class Voertuig { privatedouble lengte; privatedouble breedte; } class Auto extends Voertuig { publicint passagiers; } class Oplegger extends Voertuig { public List goederen; } class Vrachtwagen extends Voertuig { private Oplegger oplegger; publicvoid sluitOpleggerAan(Oplegger o) { oplegger = o; } publicvoid verwijderOplegger() { oplegger = null; } } lengtebreedte Vrachtwagen Oplegger Auto oplegger inhoud passagiers Taxi kost

  5. Inheritance II class Vrachtwagen extends Voertuig { private Oplegger oplegger; publicvoid sluitOpleggerAan(Oplegger o) { oplegger = o; } publicvoid verwijderOplegger() { oplegger = null; } double lengte() { if (oplegger == null) returnsuper.lengte(); else return (super.lengte()+oplegger.lengte()); } double breedte() { if (oplegger == null) returnsuper.breedte(); else return Math.max(super.breedte(),oplegger.breedte()); } } class Voertuig { privatedouble lengte; privatedouble breedte; double lengte() { return lengte; } double breedte() { return breedte; } }

  6. class TolWachtrij { List<Voertuig> rij = new ArrayList<Voertuig>(); double breedte = 2.0; double breedtefactor = 1.2 , lengtefactor = 1.1; public boolean voegtoe(Voertuig v){ if (v.breedte() * breedtefactor > breedte) { System.out.println("deze rij is te smal voor dit voertuig!"); returnfalse; } else { rij.add(v); returntrue; } } public void verwijder(Voertuig v) { rij.remove(v); } public double lengteRij() { double len = 0; for (int i=0; i<rij.size();i++) { Voertuig v = rij.get(i); len += v.lengte() * lengtefactor; } return len; } }

More Related