dawciobiel

Zad3

Apr 26th, 2020
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package com.dawciobiel;
  2.  
  3. import java.util.Scanner;
  4.  
  5. import static java.lang.System.*;
  6.  
  7. /**
  8.  * https://kobietydokodu.pl/niezbednik-juniora-dobre-praktyki-dla-poczatkujacego-programisty/
  9.  */
  10. public class Zad3 { //todo Rename to proper class name
  11.  
  12.     private final int MIN_VALUE = 10;
  13.     private final int MAX_VALUE = 99; // fixme 99 or 90?
  14.  
  15.     private final Scanner sc;
  16.  
  17.     public Zad3() {
  18.         sc = new Scanner(in);
  19.  
  20.         int number = getFirstNumberFromUser();
  21.         out.println(units(number));
  22.         out.println("Dziękujemy!");
  23.  
  24.         getSecondNumberFromUser(number);
  25.     }
  26.  
  27.     public static void main(String[] args) {
  28.         new Zad3();
  29.     }
  30.  
  31.     private int getFirstNumberFromUser() {
  32.         int number;
  33.         do {
  34.             out.println("Enter the first number between (" + MIN_VALUE + "; 90) : "); // fixme 90 or MAX_VALUE (99)?
  35.             number = sc.nextInt();
  36.         }
  37.         while (!isValueInRange(number));
  38.         return number;
  39.     }
  40.  
  41.     private void getSecondNumberFromUser(int firstNumber) {
  42.         int secondNumber;
  43.         int tensOfSecondNumber;
  44.         do {
  45.             out.println("Enter the second number between (" + MIN_VALUE + "; 90): "); // fixme 90 or MAX_VALUE (99)?
  46.             secondNumber = sc.nextInt();
  47.             tensOfSecondNumber = tens(secondNumber);
  48.             out.println("Tens of (" + secondNumber + ") is: " + tensOfSecondNumber);
  49.         }
  50.         while (!isValueInRange(secondNumber) || tensOfSecondNumber == units(firstNumber));
  51.     }
  52.  
  53.     private int units(int number) {
  54.         return number % 10;
  55.     }
  56.  
  57.     private int tens(int number) {
  58.         return (number % 100) / 10;
  59.     }
  60.  
  61.     /**
  62.      * Verify number it between (MIN_VALUE; MAX_VALUE).
  63.      *
  64.      * @param number number to verify
  65.      * @return true - if value in range
  66.      * false - otherwise.
  67.      */
  68.     private boolean isValueInRange(int number) {
  69.         return (MIN_VALUE < number && number < MAX_VALUE);
  70.     }
  71. }
Add Comment
Please, Sign In to add comment