/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * * @author Uwe Schmidt * * eine Klasse fuer natuerliche Zahlen ab 1 * mit den Ordnungsoperationen ==, !=, >=, >, <=, < * * die Ordnungs Klasse wird hier beerbt, * dadurch muessen nur == und >= * in dieser Klasse implementiert werden, * im Gegensatz zur Nat0 Klasse * * Unterschied: interface <--> abstract class * */ //-------------------- public class Nat1 extends AbstractOrdering { //-------------------- // die Variable fuer die Zahl protected long n; //-------------------- // die Konstruktoren public Nat1() { n = 1; } public Nat1(long n) { assert n >= 1 : "argument <= 0"; this.n = n; } public Nat1(int n) { this((long)n); } //-------------------- // die Zugriffs-Funktionen public int intValue() { return (int)n; } public long longValue() { return n; } //-------------------- // die Vergleichsfunktionen // nur == und >= // muessen implementiert werden public boolean eq(Nat1 o2) { return n == o2.n; } public boolean ge(Nat1 o2) { return n >= o2.n; } } //--------------------