Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dawciobiel;
- import java.util.Scanner;
- import static java.lang.System.*;
- /**
- * https://kobietydokodu.pl/niezbednik-juniora-dobre-praktyki-dla-poczatkujacego-programisty/
- */
- public class Zad3 { //todo Rename to proper class name
- private final int MIN_VALUE = 10;
- private final int MAX_VALUE = 99; // fixme 99 or 90?
- private final Scanner sc;
- public Zad3() {
- sc = new Scanner(in);
- int number = getFirstNumberFromUser();
- out.println(units(number));
- out.println("Dziękujemy!");
- getSecondNumberFromUser(number);
- }
- public static void main(String[] args) {
- new Zad3();
- }
- private int getFirstNumberFromUser() {
- int number;
- do {
- out.println("Enter the first number between (" + MIN_VALUE + "; 90) : "); // fixme 90 or MAX_VALUE (99)?
- number = sc.nextInt();
- }
- while (!isValueInRange(number));
- return number;
- }
- private void getSecondNumberFromUser(int firstNumber) {
- int secondNumber;
- int tensOfSecondNumber;
- do {
- out.println("Enter the second number between (" + MIN_VALUE + "; 90): "); // fixme 90 or MAX_VALUE (99)?
- secondNumber = sc.nextInt();
- tensOfSecondNumber = tens(secondNumber);
- out.println("Tens of (" + secondNumber + ") is: " + tensOfSecondNumber);
- }
- while (!isValueInRange(secondNumber) || tensOfSecondNumber == units(firstNumber));
- }
- private int units(int number) {
- return number % 10;
- }
- private int tens(int number) {
- return (number % 100) / 10;
- }
- /**
- * Verify number it between (MIN_VALUE; MAX_VALUE).
- *
- * @param number number to verify
- * @return true - if value in range
- * false - otherwise.
- */
- private boolean isValueInRange(int number) {
- return (MIN_VALUE < number && number < MAX_VALUE);
- }
- }
Add Comment
Please, Sign In to add comment