Play audio slide show -- Keyboard shortcut: 'x'  Lecture overview -- Keyboard shortcut: 'u'  Previous page: Klasser [Section] -- Keyboard shortcut: 'p'  Next page: Opgave: Klassen Spillekort -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home  Play sound for this slide -- Keyboard shortcut: 'y'    Objekt-orienteret programmering i Java, del 1 - slide 2 : 27

Eksempel: Klassen Konto 

class Konto {
   private double rentesats;
   private String navn;
   private double saldo;

   public Konto(String ejer) {
      rentesats = 0.02;
      navn = ejer; 
      saldo = 0;
   }

   public double balance () {
      return saldo;
   }

   public void hæv (double beløb) {
      saldo = saldo - beløb;
   }

   public void indsæt (double beløb) {
      saldo = saldo + beløb;
   }         

   public void tilskrivRente() {
      saldo = saldo + saldo * rentesats;
   }

   public String toString() {
      return navn + "'s konto indeholder "
            + saldo + " kroner";
   }
} // End Konto
 

Go to exerciseModifikationer af Konto klassen