-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay26.java
More file actions
124 lines (106 loc) · 2.72 KB
/
Day26.java
File metadata and controls
124 lines (106 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// ---------------------------------------------------
// Author : Benjamin Kataliko Viranga
// Community : Stunt Business
// Community website : www.stuntbusiness.com
//
// 30 Days - Q&A Java basic
// Day 26 : User
// Day 26 | IG : https://www.instagram.com/benjivrik/
// ----------------------------------------------------
// what would be the output of this program ?
import java.time.LocalDate;
class User
{
private String firstName;
private String lastName;
private String category;
private LocalDate dateOfBirth;
private int id;
private static int userID = 0;
public User()
{
this.firstName = "";
this.lastName = "";
this.dateOfBirth = null;
this.category = "";
this.id = ++this.userID;
}
public User(String firstName, String lastName)
{
this.firstName = firstName;
this.lastName = lastName;
this.category = null;
this.dateOfBirth = null;
this.id = ++this.userID;
}
public String getFirstName()
{
return this.firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return this.lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public void setCategory(String category)
{
this.category = category;
}
public String getCategory()
{
return this.category;
}
public LocalDate getDateOfBirth()
{
return this.dateOfBirth;
}
public int getUserID()
{
return this.id;
}
/**
*
* @param year
* @param month
* @param day
*/
public void setDateOfBirth(int year, int month, int day)
{
this.dateOfBirth = LocalDate.of(year,month,day);
}
public String toString()
{
System.out.println("\n************** DISPLAYING USER INFO **************\n");
String user = "";
user +="\nUser first-name :" + this.firstName+"\n";
user +="User last-name :" + this.lastName+"\n";
user +="User category :"+ this.category+"\n";
user +="User date of birth : " + this.dateOfBirth +"\n";
user +="User ID : " + this.id +"\n";
return user;
}
}
public class Day26
{
public static void main(String[] args)
{
User user = new User();
// setting data for the user
user.setFirstName("Donald");
user.setLastName("Vrik");
user.setCategory("Teacher");
user.setDateOfBirth(1987, 04, 14);
// print your user data
System.out.println(user);
// Empty user
user = new User();
System.out.println(user);
}
}