Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5.     static class User {
  6.  
  7.         private String name;
  8.  
  9.         private int age;
  10.  
  11.         private int height;
  12.  
  13.         public User(String name, int age, int height) {
  14.             this.name = name;
  15.             this.age = age;
  16.             this.height = height;
  17.         }
  18.  
  19.         public boolean hasAnyName() {
  20.             return name != null;
  21.         }
  22.  
  23.         public boolean isOlderThan(int expectedAge) {
  24.             return age > expectedAge;
  25.         }
  26.  
  27.         public boolean isHeigherThan(int expectedHeight) {
  28.             return height > expectedHeight;
  29.         }
  30.     }
  31.  
  32.     public static void main(String[] args) {
  33.         User adam = new User("Adam", 19, 190);
  34.  
  35.         if (adam.hasAnyName()) {
  36.             if (adam.isOlderThan(18) && adam.isHeigherThan(170)) {
  37.                 System.out.println("1");
  38.             } else {
  39.                 System.out.println("2");
  40.             }
  41.         } else {
  42.             System.out.println("3");
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement