Lecture overview
Keyboard shortcut: 'u'    Next page
Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide
Keyboard shortcut: 't'  Alphabetic index  Course home  Slide 1 : 4
Example using StringInput and StringOutput

We show how StringInput and StringOutput can be used together. Let us emphasize that the example is though as an illustration in relation to Java interfaces. The example has not been carried through entirely, and it is not thought to be a of any practical use

class IoKonto extends Konto implements StringInputOutput{

  private void init(double saldo, String navn){
    this.saldo = saldo; this.navn = navn;
  }

  public IoKonto(String navn){
    super(navn);
  }
 
  public String toStringRepresentation(){
    return("Konto[" + navn + "|" + saldo + "]");
  }

  public void fromStringRepresentation(String s){
   // only for demo purposes
   String nameComponent = 
     s.substring(s.indexOf('[')+1, s.indexOf('|'));
   String saldoComponent =
      s.substring(s.indexOf('|')+1, s.indexOf(']'));
   init(Double.valueOf(saldoComponent).doubleValue(),
        nameComponent);
  }
} // end IoKonto

A class IoKonto which implements the interface StringInputOuput. The methods in the interface must be defined in IoKonto.

Navigate to programAn example of a client of IoKonto

An example of a client of IoKonto