Advertisement
wingman007

2018_Java_Person

Oct 27th, 2018
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package com.coolcsn;
  2.  
  3. public class Person implements Introducable{
  4.     protected String name;
  5.     protected int age;
  6.     private static int counter = 0;
  7.  
  8.     public void setName(String name) {
  9.         this.name = name;
  10.     }
  11.  
  12.     public String getName() {
  13.         return name;
  14.     }
  15.  
  16.     public void setAge(int age) {
  17.         if (age <= 120) {
  18.             this.age = age;
  19.         }
  20.     }
  21.  
  22.     public int getAge() {
  23.         return age;
  24.     }
  25.  
  26.     public double getBalance() {
  27.         return age * 42.5;
  28.     }
  29.  
  30.     public static int getCounter() {
  31.         return counter;
  32.     }
  33.  
  34.     // Overloading
  35.     // Working horse
  36.     public Person(String name, int age) {
  37.         this.name = name;
  38.         this.age = age;
  39.         counter++;
  40.     }
  41.  
  42.     public Person(){
  43.         this("Default", 0);
  44.         // name = "Deafult";
  45.         // age = 0;
  46.     }
  47.  
  48.     public Person(int age, String name) {
  49.         this(name, age);
  50.         // this.name = name;
  51.         // this.age = age;
  52.     }
  53.  
  54.     public void introduceYourSelf() {
  55.         System.out.printf("My name is %1$s. I am %2$d years old! And my balnce is %3$f \n", name, age, getBalance());
  56.     }
  57.  
  58.     public static double getNationalIncome()
  59.     {
  60.         return counter * 10000;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement