// NumberTest.java
import java.util.Scanner;

/**
 * NumberTest zeigt den Umgang mit der Klasse Number.
 * Beispielprogramm zur Programmiertechnik 1, Teil 5.
 * @author H.Drachenfels
 * @version 16.12.2024
 */
public final class NumberTest {
    private NumberTest() { }

    /**
     * main ist der Startpunkt des Programms.
     * @param args Feld mit Dezimalzahlen
     */
    public static void main(String[] args) {
        for (String z : args) {
            Scanner s = new Scanner(z);
            Number n;

            if (s.hasNextByte()) {
                n = Byte.valueOf(s.nextByte());
            } else if (s.hasNextShort()) {
                n = Short.valueOf(s.nextShort());
            } else if (s.hasNextInt()) {
                n = Integer.valueOf(s.nextInt());
            } else if (s.hasNextLong()) {
                n = Long.valueOf(s.nextLong());
            } else if (s.hasNextDouble()) {
                double d = s.nextDouble();
                if (z.length() <= Float.PRECISION / 3
                    && Math.abs(d) <= Float.MAX_VALUE
                    && Math.abs(d) >= Float.MIN_VALUE) {
                    n = Float.valueOf((float) d);
                } else {
                    n = Double.valueOf(d);
                }
            } else {
                System.err.printf("Not a number: %s%n", z);
                continue;
            }

            System.out.printf("%s(%s):%n", n.getClass().getSimpleName(), n);
            System.out.println(n.byteValue());
            System.out.println(n.shortValue());
            System.out.println(n.intValue());
            System.out.println(n.longValue());
            System.out.println(n.floatValue());
            System.out.println(n.doubleValue());
        }
    }
}

