private int dMonth;
private int dDay;
private int dYear;
// Constructors
this(1, 1, 2000); // Default date
}
public Date(int month,
int day,
int year
) { this.dMonth = month;
this.dDay = day;
this.dYear = year;
}
// Setter
public void setDate(int month, int day, int year) {
this.dMonth = month;
this.dDay = day;
this.dYear = year;
}
// Getters
public int getMonth() { return dMonth; }
public int getDay() { return dDay; }
public int getYear() { return dYear; }
// toString method
return dMonth + "/" + dDay + "/" + dYear;
}
}
class PersonalInfo {
private Date bDay
; // Composition private int personID;
// Constructors
public PersonalInfo() {
this("Unknown", 1, 1, 2000, 0);
}
public PersonalInfo
(String name,
int month,
int day,
int year,
int personID
) { this.name = name;
this.
bDay = new Date(month, day, year
); this.personID = personID;
}
// Setter
public void setPersonalInfo
(String name,
int month,
int day,
int year,
int personID
) { this.name = name;
this.bDay.setDate(month, day, year);
this.personID = personID;
}
// toString method
return "Name: " + name + "\nBirth Date: " + bDay + "\nID: " + personID;
}
}
public class Main {
public static void main
(String[] args
) { PersonalInfo person = new PersonalInfo("Alice", 12, 25, 1998, 1001);
}
}
Y2xhc3MgRGF0ZSB7CiAgICBwcml2YXRlIGludCBkTW9udGg7CiAgICBwcml2YXRlIGludCBkRGF5OwogICAgcHJpdmF0ZSBpbnQgZFllYXI7CgogICAgLy8gQ29uc3RydWN0b3JzCiAgICBwdWJsaWMgRGF0ZSgpIHsKICAgICAgICB0aGlzKDEsIDEsIDIwMDApOyAvLyBEZWZhdWx0IGRhdGUKICAgIH0KCiAgICBwdWJsaWMgRGF0ZShpbnQgbW9udGgsIGludCBkYXksIGludCB5ZWFyKSB7CiAgICAgICAgdGhpcy5kTW9udGggPSBtb250aDsKICAgICAgICB0aGlzLmREYXkgPSBkYXk7CiAgICAgICAgdGhpcy5kWWVhciA9IHllYXI7CiAgICB9CgogICAgLy8gU2V0dGVyCiAgICBwdWJsaWMgdm9pZCBzZXREYXRlKGludCBtb250aCwgaW50IGRheSwgaW50IHllYXIpIHsKICAgICAgICB0aGlzLmRNb250aCA9IG1vbnRoOwogICAgICAgIHRoaXMuZERheSA9IGRheTsKICAgICAgICB0aGlzLmRZZWFyID0geWVhcjsKICAgIH0KCiAgICAvLyBHZXR0ZXJzCiAgICBwdWJsaWMgaW50IGdldE1vbnRoKCkgeyByZXR1cm4gZE1vbnRoOyB9CiAgICBwdWJsaWMgaW50IGdldERheSgpIHsgcmV0dXJuIGREYXk7IH0KICAgIHB1YmxpYyBpbnQgZ2V0WWVhcigpIHsgcmV0dXJuIGRZZWFyOyB9CgogICAgLy8gdG9TdHJpbmcgbWV0aG9kCiAgICBwdWJsaWMgU3RyaW5nIHRvU3RyaW5nKCkgewogICAgICAgIHJldHVybiBkTW9udGggKyAiLyIgKyBkRGF5ICsgIi8iICsgZFllYXI7CiAgICB9Cn0KY2xhc3MgUGVyc29uYWxJbmZvIHsKICAgIHByaXZhdGUgU3RyaW5nIG5hbWU7CiAgICBwcml2YXRlIERhdGUgYkRheTsgLy8gQ29tcG9zaXRpb24KICAgIHByaXZhdGUgaW50IHBlcnNvbklEOwoKICAgIC8vIENvbnN0cnVjdG9ycwogICAgcHVibGljIFBlcnNvbmFsSW5mbygpIHsKICAgICAgICB0aGlzKCJVbmtub3duIiwgMSwgMSwgMjAwMCwgMCk7CiAgICB9CgogICAgcHVibGljIFBlcnNvbmFsSW5mbyhTdHJpbmcgbmFtZSwgaW50IG1vbnRoLCBpbnQgZGF5LCBpbnQgeWVhciwgaW50IHBlcnNvbklEKSB7CiAgICAgICAgdGhpcy5uYW1lID0gbmFtZTsKICAgICAgICB0aGlzLmJEYXkgPSBuZXcgRGF0ZShtb250aCwgZGF5LCB5ZWFyKTsKICAgICAgICB0aGlzLnBlcnNvbklEID0gcGVyc29uSUQ7CiAgICB9CgogICAgLy8gU2V0dGVyCiAgICBwdWJsaWMgdm9pZCBzZXRQZXJzb25hbEluZm8oU3RyaW5nIG5hbWUsIGludCBtb250aCwgaW50IGRheSwgaW50IHllYXIsIGludCBwZXJzb25JRCkgewogICAgICAgIHRoaXMubmFtZSA9IG5hbWU7CiAgICAgICAgdGhpcy5iRGF5LnNldERhdGUobW9udGgsIGRheSwgeWVhcik7CiAgICAgICAgdGhpcy5wZXJzb25JRCA9IHBlcnNvbklEOwogICAgfQoKICAgIC8vIHRvU3RyaW5nIG1ldGhvZAogICAgcHVibGljIFN0cmluZyB0b1N0cmluZygpIHsKICAgICAgICByZXR1cm4gIk5hbWU6ICIgKyBuYW1lICsgIlxuQmlydGggRGF0ZTogIiArIGJEYXkgKyAiXG5JRDogIiArIHBlcnNvbklEOwogICAgfQp9CnB1YmxpYyBjbGFzcyBNYWluIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBQZXJzb25hbEluZm8gcGVyc29uID0gbmV3IFBlcnNvbmFsSW5mbygiQWxpY2UiLCAxMiwgMjUsIDE5OTgsIDEwMDEpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihwZXJzb24pOwogICAgfQp9Cg==