Advanced Services
JAVA-Praktikum
Prev. Excercise Next Exercise Exercise Home
Die Klasse Address (Lösung)

// ------------ Address.java  Einfache Adressklasse ------------ \\

public class Address
{
   // ----------------------- Datenteil ------------------------ \\
   private String street, hnum, city, plz ;

   // -------------- Konstruktoren --------------------- \\
   public Address()
   {
      street = hnum = city = plz = "" ; // geht nur für Strings
   }

   public Address(String str, String hn, String stadt, String plZ)
   {
      street = str; hnum = hn; city = stadt; plz = plZ;
   }

   // -------  Methoden -------
   public String getStrasse()
   {
      return street;
   }
   public void setStrasse(String str)
   {
      street = str;
   }
   public String getHnum()
   {
      return hnum;
   }
   public void setHnum(String h)
   {
      hnum = h;
   }
   public String getStadt()
   {
      return city;
   }
   public void setStadt(String st)
   {
      city = st;
   }
   public String getPLZ()
   {
      return plz;
   }
   public void setPLZ(String plZ)
   {
      plz = plZ;
   }

   public void println()
   {
      System.out.println(street + " " + hnum);
      System.out.println(plz + " " + city);
   }

   public void print()
   {
      System.out.println(street + " " + hnum);
      System.out.print(plz + " " + city);
   }

}  // end class Address

top Prev. Exercise Next Exercise Exercise Home