Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Person {
- private String name;
- private int age;
- private boolean isMan;
- public Person(String name, int age, boolean isMan) {
- this.setName(name);
- this.setAge(age);
- this.isMan = isMan;
- }
- private void setName(String name) {
- if (name == null || name.isEmpty()) {
- throw new IllegalArgumentException("Name cannot be null.");
- }
- this.name = name;
- }
- private void setAge(int age) {
- if (age < 0) {
- throw new IllegalArgumentException("Age cannot be negative number.");
- }
- this.age = age;
- }
- public String getName() {
- return name;
- }
- public int getAge() {
- return age;
- }
- public boolean isMan() {
- return isMan;
- }
- public void showPersonInfo() {
- System.out.println(String.format("Name: %s%n" +
- "Age: %d", this.name, this.age));
- if (isMan) {
- System.out.println(String.format("Sex: male%n"));
- } else {
- System.out.println(String.format("Sex: female%n"));
- }
- }
- public void showStudentInfo() {}
- public void showEmployeeInfo() {}
- public double calculateOvertime(double hours) { return 0.0; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement