1 / 4

Verteilte Software - Java - Utilities 1

Verteilte Software - Java - Utilities 1. // Aufzaehlungschnittstelle import java.util.*; public class ArbRaum { public static void main (String args[]) { AR zi104 = new AR(3); zi104.add_ak(0, "Meier"); zi104.add_ak(2, "Schulze"); System.out.println("Zimmer 104:");

gage
Download Presentation

Verteilte Software - Java - Utilities 1

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. Verteilte Software - Java - Utilities 1 // Aufzaehlungschnittstelle import java.util.*; public class ArbRaum { public static void main (String args[]) { AR zi104 = new AR(3); zi104.add_ak(0, "Meier"); zi104.add_ak(2, "Schulze"); System.out.println("Zimmer 104:"); for ( Enumeration e = zi104.elements(); e.hasMoreElements(); ) { System.out.println(' ' + ((APlatz)e.nextElement()).getPerson() ); } } } class AR { APlatz ap[]; AR (int anz) { ap = new APlatz[anz]; for (int i = 0; i<anz; i++) ap[i] = new APlatz(); } void add_ak(int index, String name) { ap[index].setPerson(name);} Enumeration elements() {return new AR_Enumerator(this);} } class APlatz { private String name; APlatz () {name = "";} void setPerson(String name){ this.name = name; } String getPerson(){ return name; } } Zimmer 104: Meier Schulze class AR_Enumerator implements Enumeration { APlatz all[]; int pos; AR_Enumerator(AR araum) { all = araum.ap; pos = 0; } public boolean hasMoreElements() { while ((pos < all.length) && (all[pos].getPerson().equals("") )) pos++; return pos < all.length; } public Object nextElement() { if (pos < all.length) return all[pos++]; else throw new NoSuchElementException("AR_Enumerator"); } } Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

  2. Verteilte Software - Java - Utilities 2 // Aufzaehlungschnittstelle - Vector import java.util.*; public class ArbRaum_v { public static void main (String args[]) { Vector zi104 = new Vector(10); APlatz_v ap; ap = new APlatz_v(); ap.setPerson("Meier"); zi104.addElement(ap); zi104.addElement(new APlatz_v("Schulze")); System.out.println("Zimmer 104:"); for ( Enumeration e = zi104.elements(); e.hasMoreElements(); ) { System.out.println(' ' + ((APlatz_v)e.nextElement()).getPerson() ); } } } class APlatz_v { private String name; APlatz_v () { this(""); } APlatz_v (String name){ this.name = name; } void setPerson(String name){ this.name = name; } String getPerson(){ return name; } } Zimmer 104: Meier Schulze Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

  3. Verteilte Software - Java - Utilities 3 class APlatz_h { private String vname; private int alter; APlatz_h () { this("", 0); } APlatz_h (String vname, int alter) { this.vname = vname; this.alter = alter; } void setPerson(String vname, int alter) { this.vname = vname; this.alter = alter; } String getVName(){ return vname; } int getAlter(){ return alter; } } // Aufzaehlungschnittstelle - Hashtable import java.util.*; public class ArbRaum_h { public static void main (String args[]) { String namen[] = new String[] {"Meier", "Schulze", "Huhn", "Mustermann"}; Hashtable zi104 = new Hashtable(); APlatz_h ap; zi104.put("Schulze", new APlatz_h("Petra", 17)); ap = new APlatz_h(); ap.setPerson("Dieter", 25); zi104.put("Meier", ap); zi104.put("Mustermann", new APlatz_h("Franz", 35)); System.out.println("Zimmer 104:"); for ( Enumeration e = zi104.elements(); e.hasMoreElements(); ) { ap = (APlatz_h)e.nextElement(); System.out.println (' ' + ap.getVName() + " ist " + ap.getAlter() + " Jahre alt"); } System.out.println("Suche:"); for (int i = 0; i < namen.length; i++) { ap = (APlatz_h)zi104.get(namen[i]); if (ap != null) System.out.println (ap.getVName() + ' ' +namen[i] + " ist " + ap.getAlter() + " Jahre alt"); else System.out.println("Nicht gefunden: "+namen[i]); } } } Zimmer 104: Dieter ist 25 Jahre alt Franz ist 35 Jahre alt Petra ist 17 Jahre alt Suche: Dieter Meier ist 25 Jahre alt Petra Schulze ist 17 Jahre alt Nicht gefunden: Huhn Franz Mustermann ist 35 Jahre alt Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

  4. Verteilte Software - Java - Utilities 4 // Zerlegung von Zeichenketten import java.util.*; public class Token { public static void main (String args[]) { String Text = "Mit\tJAVA\tkann man gut programmieren."; String Formel = "y=sin(k*x)"; StringTokenizer st; System.out.println("Text 1:"); for (Enumeration e = new StringTokenizer(Text); e.hasMoreElements(); ) { System.out.println( e.nextElement() ); } System.out.println("Text 2:"); for (st = new StringTokenizer(Text," \t."); st.hasMoreElements(); ) { System.out.println( st.nextElement() ); } System.out.println("Formel:"); st = new StringTokenizer(Formel," ()=*+-/%", true); while( st.hasMoreTokens() ) { System.out.println( st.nextToken() ); } } } Text 1: Mit JAVA kann man gut programmieren. Text 2: Mit JAVA kann man gut programmieren Formel: y = sin ( k * x ) Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

More Related