Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Date.java
- ----------
- public class Date {
- int day;
- int month;
- int year;
- public Date() {
- this.day = 1;
- this.month = 1;
- this.year = 1970;
- }
- public Date(int day, int month, int year) {
- this.day = day;
- this.month = month;
- this.year = year;
- }
- public int getDay() {
- return day;
- }
- public void setDay(int day) {
- this.day = day;
- }
- public int getMonth() {
- return month;
- }
- public void setMonth(int month) {
- this.month = month;
- }
- public int getYear() {
- return year;
- }
- public void setYear(int year) {
- this.year = year;
- }
- @Override
- public String toString() {
- return day + "/" + month + "/" + year;
- }
- }
- RunDate.java
- ------------
- public class RunDate {
- public static void main(String[] args) {
- Date d1, d2;
- d1 = new Date();
- System.out.println("d1 = " + d1);
- d2 = new Date(8, 10, 2017);
- // not a good way
- // d2.setDay(8);
- // d2.setMonth(10);
- // d2.setYear(2017);
- System.out.println("d2 = " + d2);
- Date d3 = new Date(26, 5, 2001);
- System.out.println("Happy Birthday: " + d3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement