Example #1
0
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String ime, prezime, oib;
    BigDecimal stanje;

    System.out.print("Unesite ime vlasnika tekućeg računa: ");
    ime = scanner.next();
    System.out.print("Unesite prezime vlasnika tekućeg računa: ");
    prezime = scanner.next();
    System.out.print("Unesite OIB vlasnika tekućeg računa: ");
    oib = scanner.next();
    System.out.print("Unesite broj tekućeg računa: ");
    String broj = scanner.next();
    System.out.print("Unesite stanje tekućeg računa (KN): ");
    stanje = scanner.nextBigDecimal();
    TekuciRacun tekuciRacun = new TekuciRacun(new Osoba(ime, prezime, oib), stanje, broj);

    System.out.print("Unesite ime opunomoćenog korisnika tekućeg računa: ");
    ime = scanner.next();
    System.out.print("Unesite prezime opunomoćenog korisnika tekućeg računa: ");
    prezime = scanner.next();
    System.out.print("Unesite OIB opunomoćenog korisnika tekućeg računa: ");
    oib = scanner.next();
    tekuciRacun.postaviOpunomocenika(new Osoba(ime, prezime, oib));

    System.out.print("Unesite ime vlasnika deviznog računa: ");
    ime = scanner.next();
    System.out.print("Unesite prezime vlasnika deviznog računa: ");
    prezime = scanner.next();
    System.out.print("Unesite OIB vlasnika deviznog računa: ");
    oib = scanner.next();
    System.out.print("Unesite IBAN deviznog računa: ");
    String iban = scanner.next();
    System.out.print("Unesite valutu deviznog računa: ");
    String valuta = scanner.next();
    System.out.print("Unesite stanje deviznog računa: ");
    stanje = scanner.nextBigDecimal();
    DevizniRacun devizniRacun =
        new DevizniRacun(new Osoba(ime, prezime, oib), stanje, iban, valuta);

    System.out.print("Unesite iznos transakcije (u KN) s prvog na drugi račun: ");
    BigDecimal iznos = scanner.nextBigDecimal();

    Transakcija transakcija = new DeviznaTransakcija(tekuciRacun, devizniRacun, iznos);
    transakcija.provediTransakciju();

    System.out.printf(
        "Stanje tekućeg računa nakon transkacije: %.2f KN\n", tekuciRacun.getStanje());
    System.out.printf(
        "Stanje deviznog računa nakon transkacije: %.2f %s\n",
        devizniRacun.getStanje(), devizniRacun.getValuta());
  }
Example #2
0
  public static void main(String[] args) {

    Map<Integer, CalcularPolignos> poligono = new HashMap<>();

    Scanner sc = new Scanner(System.in);
    System.out.println("Digite o número de lados do poligono: ");
    BigInteger lados = sc.nextBigInteger();

    int opcao = 0;

    if (lados.intValue() < 3) {
      System.out.println("Valor negativo para número de lados do poligno, tente novamente!");
      main(args);
    } else if (lados.intValue() == 3) {
      opcao = 1;
    } else if (lados.intValue() == 4) {
      opcao = 2;
    } else if (lados.intValue() > 4) {
      opcao = 3;
    }

    System.out.println("Digite o Tamanho do Lado do Poligono: ");
    BigDecimal tamanho = sc.nextBigDecimal();

    poligono.put(1, new Triagulo(lados, tamanho));
    poligono.put(2, new Quadrilatero(lados, tamanho));
    poligono.put(3, new OutrosPoligonos(lados, tamanho));

    Controller cont = new Controller();
    cont.calcular(lados, poligono.get(opcao));
  }
Example #3
0
 private static BigDecimal readBigDecimal(String title) {
   System.out.print(title + ": ");
   try {
     return scanner.nextBigDecimal();
   } catch (NoSuchElementException e) {
     throw new InputMismatchException("Float expected!");
   } catch (IllegalStateException e) {
     throw new InputMismatchException("Float expected!");
   }
 }
Example #4
0
  /**
   * Reads item information from a file and returns a List of Item objects.
   *
   * @param theFile the name of the file to load into a List of Items
   * @return a List of Item objects created from data in an input file
   */
  public static List<Item> readItemsFromFile(final String theFile) {
    final List<Item> items = new LinkedList<>();

    try (Scanner input = new Scanner(Paths.get(theFile))) { // Java 7!
      while (input.hasNextLine()) {
        final Scanner line = new Scanner(input.nextLine());
        line.useDelimiter(";");
        final String itemName = line.next();
        final BigDecimal itemPrice = line.nextBigDecimal();
        if (line.hasNext()) {
          final int bulkQuantity = line.nextInt();
          final BigDecimal bulkPrice = line.nextBigDecimal();
          items.add(new Item(itemName, itemPrice, bulkQuantity, bulkPrice));
        } else {
          items.add(new Item(itemName, itemPrice));
        }
        line.close();
      }
    } catch (final IOException e) {
      e.printStackTrace();
    } // no finally block needed to close 'input' with the Java 7 try with resource block

    return items;
  }
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int numbersCount = scanner.nextInt();
    scanner.nextLine();

    BigDecimal[] numbersInput = new BigDecimal[numbersCount];
    for (int i = 0; i < numbersInput.length; i++) {
      numbersInput[i] = scanner.nextBigDecimal();
    }
    Arrays.sort(numbersInput);

    int count = 3;
    for (int i = numbersInput.length - 1; i >= 0 && count > 0; i--, count--) {
      System.out.println(numbersInput[i].toPlainString());
    }
  }
Example #6
0
 public static void main(String args[]) {
   Scanner scan = new Scanner(System.in);
   while (scan.hasNext()) {
     BigDecimal m = scan.nextBigDecimal();
     ;
     int i, n;
     n = scan.nextInt();
     m = m.pow(n);
     String ans = m.toPlainString();
     int st = 0, ed = ans.length() - 1;
     while (ans.charAt(st) == '0') st++;
     while (ans.charAt(ed) == '0') ed--;
     if (ans.charAt(ed) == '.') ed--;
     for (i = st; i <= ed; i++) System.out.print(ans.charAt(i));
     System.out.println();
   }
 }
  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    int count = Integer.parseInt(scanner.nextLine());
    BigDecimal[] numbers = new BigDecimal[count];

    for (int i = 0; i < numbers.length; i++) {
      numbers[i] = scanner.nextBigDecimal();
    }

    Arrays.sort(numbers);

    int counter = 0;
    for (int i = numbers.length - 1; i >= 0; i--) {
      System.out.println(numbers[i].toPlainString());
      counter++;
      if (counter == 3) {
        break;
      }
    }
  }
Example #8
0
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out, true);
    BigDecimal result;
    String str;

    // while there is some input to read
    while (in.hasNextFloat()) {
      result = in.nextBigDecimal();
      int n = in.nextInt();

      result = result.pow(n);
      str = result.toPlainString();

      while (str.charAt(0) == '0') {
        str = str.substring(1);
      }
      int i = str.length() - 1;
      while (str.charAt(i--) == '0') {
        str = str.substring(0, str.length() - 1);
      }
      out.println(str);
    }
  }
Example #9
0
  public static Object parseValue(Database database, Object val, DataType type) {
    if (!(val instanceof String)) {
      return val;
    }

    int typeId = Integer.MIN_VALUE;
    if (type.getDataTypeId() != null) {
      typeId = type.getDataTypeId();
    }
    String typeName = type.getTypeName();

    LiquibaseDataType liquibaseDataType = DataTypeFactory.getInstance().from(type, database);

    String stringVal = (String) val;
    if (stringVal.isEmpty()) {
      if (liquibaseDataType instanceof CharType) {
        return "";
      } else {
        return null;
      }
    }

    if (database instanceof OracleDatabase
        && !stringVal.startsWith("'")
        && !stringVal.endsWith("'")) {
      // oracle returns functions without quotes
      Object maybeDate = null;

      if (liquibaseDataType instanceof DateType || typeId == Types.DATE) {
        if (stringVal.endsWith("'HH24:MI:SS')")) {
          maybeDate =
              DataTypeFactory.getInstance()
                  .fromDescription("time", database)
                  .sqlToObject(stringVal, database);
        } else {
          maybeDate =
              DataTypeFactory.getInstance()
                  .fromDescription("date", database)
                  .sqlToObject(stringVal, database);
        }
      } else if (liquibaseDataType instanceof DateTimeType || typeId == Types.TIMESTAMP) {
        maybeDate =
            DataTypeFactory.getInstance()
                .fromDescription("datetime", database)
                .sqlToObject(stringVal, database);
      } else {
        return new DatabaseFunction(stringVal);
      }
      if (maybeDate != null) {
        if (maybeDate instanceof java.util.Date) {
          return maybeDate;
        } else {
          return new DatabaseFunction(stringVal);
        }
      }
    }

    if (stringVal.startsWith("'") && stringVal.endsWith("'")) {
      stringVal = stringVal.substring(1, stringVal.length() - 1);
    } else if (stringVal.startsWith("((") && stringVal.endsWith("))")) {
      stringVal = stringVal.substring(2, stringVal.length() - 2);
    } else if (stringVal.startsWith("('") && stringVal.endsWith("')")) {
      stringVal = stringVal.substring(2, stringVal.length() - 2);
    } else if (stringVal.startsWith("(") && stringVal.endsWith(")")) {
      return new DatabaseFunction(stringVal.substring(1, stringVal.length() - 1));
    }

    Scanner scanner = new Scanner(stringVal.trim());
    if (typeId == Types.ARRAY) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof BigIntType || typeId == Types.BIGINT)) {
      if (scanner.hasNextBigInteger()) {
        return scanner.nextBigInteger();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.BINARY) {
      return new DatabaseFunction(stringVal.trim());
    } else if (typeId == Types.BIT) {
      if (stringVal.startsWith("b'")) { // mysql returns boolean values as b'0' and b'1'
        stringVal = stringVal.replaceFirst("b'", "").replaceFirst("'$", "");
      }
      stringVal = stringVal.trim();
      if (scanner.hasNextBoolean()) {
        return scanner.nextBoolean();
      } else {
        return new Integer(stringVal);
      }
    } else if (liquibaseDataType instanceof BlobType || typeId == Types.BLOB) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof BooleanType || typeId == Types.BOOLEAN)) {
      if (scanner.hasNextBoolean()) {
        return scanner.nextBoolean();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (liquibaseDataType instanceof CharType || typeId == Types.CHAR) {
      return stringVal;
    } else if (liquibaseDataType instanceof ClobType || typeId == Types.CLOB) {
      return stringVal;
    } else if (typeId == Types.DATALINK) {
      return new DatabaseFunction(stringVal);
    } else if (liquibaseDataType instanceof DateType || typeId == Types.DATE) {
      if (typeName.equalsIgnoreCase("year")) {
        return stringVal.trim();
      }
      return DataTypeFactory.getInstance()
          .fromDescription("date", database)
          .sqlToObject(stringVal, database);
    } else if ((liquibaseDataType instanceof DecimalType || typeId == Types.DECIMAL)) {
      if (scanner.hasNextBigDecimal()) {
        return scanner.nextBigDecimal();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.DISTINCT) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof DoubleType || typeId == Types.DOUBLE)) {
      if (scanner.hasNextDouble()) {
        return scanner.nextDouble();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if ((liquibaseDataType instanceof FloatType || typeId == Types.FLOAT)) {
      if (scanner.hasNextFloat()) {
        return scanner.nextFloat();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if ((liquibaseDataType instanceof IntType || typeId == Types.INTEGER)) {
      if (scanner.hasNextInt()) {
        return scanner.nextInt();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.JAVA_OBJECT) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.LONGNVARCHAR) {
      return stringVal;
    } else if (typeId == Types.LONGVARBINARY) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.LONGVARCHAR) {
      return stringVal;
    } else if (liquibaseDataType instanceof NCharType || typeId == Types.NCHAR) {
      return stringVal;
    } else if (typeId == Types.NCLOB) {
      return stringVal;
    } else if (typeId == Types.NULL) {
      return null;
    } else if ((liquibaseDataType instanceof NumberType || typeId == Types.NUMERIC)) {
      if (scanner.hasNextBigDecimal()) {
        return scanner.nextBigDecimal();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (liquibaseDataType instanceof NVarcharType || typeId == Types.NVARCHAR) {
      return stringVal;
    } else if (typeId == Types.OTHER) {
      if (database instanceof DB2Database && typeName.equalsIgnoreCase("DECFLOAT")) {
        return new BigDecimal(stringVal);
      }
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.REAL) {
      return new BigDecimal(stringVal.trim());
    } else if (typeId == Types.REF) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.ROWID) {
      return new DatabaseFunction(stringVal);
    } else if ((liquibaseDataType instanceof SmallIntType || typeId == Types.SMALLINT)) {
      if (scanner.hasNextInt()) {
        return scanner.nextInt();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.SQLXML) {
      return new DatabaseFunction(stringVal);
    } else if (typeId == Types.STRUCT) {
      return new DatabaseFunction(stringVal);
    } else if (liquibaseDataType instanceof TimeType || typeId == Types.TIME) {
      return DataTypeFactory.getInstance()
          .fromDescription("time", database)
          .sqlToObject(stringVal, database);
    } else if (liquibaseDataType instanceof DateTimeType
        || liquibaseDataType instanceof TimestampType
        || typeId == Types.TIMESTAMP) {
      return DataTypeFactory.getInstance()
          .fromDescription("datetime", database)
          .sqlToObject(stringVal, database);
    } else if ((liquibaseDataType instanceof TinyIntType || typeId == Types.TINYINT)) {
      if (scanner.hasNextInt()) {
        return scanner.nextInt();
      } else {
        return new DatabaseFunction(stringVal);
      }
    } else if (typeId == Types.VARBINARY) {
      return new DatabaseFunction(stringVal);
    } else if (liquibaseDataType instanceof VarcharType || typeId == Types.VARCHAR) {
      return stringVal;
    } else if (database instanceof MySQLDatabase && typeName.toLowerCase().startsWith("enum")) {
      return stringVal;
    } else {
      LogFactory.getLogger()
          .info(
              "Unknown default value: value '"
                  + stringVal
                  + "' type "
                  + typeName
                  + " ("
                  + type
                  + "), assuming it is a function");
      return new DatabaseFunction(stringVal);
    }
  }