Advertisement
Ivelin_1936

class Person

Feb 11th, 2018
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Person {
  4.  
  5.     private String name;
  6.     private int age;
  7.     private boolean isMan;
  8.  
  9.     public Person(String name, int age, boolean isMan) {
  10.         this.setName(name);
  11.         this.setAge(age);
  12.         this.isMan = isMan;
  13.     }
  14.  
  15.     private void setName(String name) {
  16.         if (name == null || name.isEmpty()) {
  17.             throw new IllegalArgumentException("Name cannot be null.");
  18.         }
  19.         this.name = name;
  20.     }
  21.  
  22.     private void setAge(int age) {
  23.         if (age < 0) {
  24.             throw new IllegalArgumentException("Age cannot be negative number.");
  25.         }
  26.         this.age = age;
  27.     }
  28.  
  29.     public String getName() {
  30.         return name;
  31.     }
  32.  
  33.     public int getAge() {
  34.         return age;
  35.     }
  36.  
  37.     public boolean isMan() {
  38.         return isMan;
  39.     }
  40.  
  41.     public void showPersonInfo() {
  42.         System.out.println(String.format("Name: %s%n" +
  43.                 "Age: %d", this.name, this.age));
  44.         if (isMan) {
  45.             System.out.println(String.format("Sex: male%n"));
  46.         } else {
  47.             System.out.println(String.format("Sex: female%n"));
  48.         }
  49.     }
  50.  
  51.     public void  showStudentInfo() {}
  52.     public void showEmployeeInfo() {}
  53.     public double calculateOvertime(double hours) { return 0.0; }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement