-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUser.java
125 lines (91 loc) · 2.18 KB
/
User.java
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
125
import java.util.ArrayList;
import java.util.List;
import java.util.*;
public class User
{
private String lN;
private String fN;
static void log(Object o)
{
System.out.print(o);
}
static void logln(Object o)
{
System.out.println(o);
}
//Setter not returning anything ∴ void
public void setFirstName(String firstName)
{
//Assigning the fName value we pass in to the field firstName
fN=firstName.toLowerCase();
//the .strip remove any whitespaces before output.
}
public String getFullName()
{
return getFirstName() + " " + lN.toUpperCase();
}
public String getLastName()
{
return lN;
}
public String output()
{
return "Hi, my name is "+ getFirstName() + " " + getLastName() + ".";
}
public String output(boolean nice)
{
if(nice)
{
return "You\re an awesome person"+ " " + getFullName() + ".";
}
return "You\'re an idiot"+ " " + getFullName() + ".";
}
public void setLastName(String lastName)
{
//Assigning the lN value we pass in to the field lastName
lN=lastName;
}
public String getFirstName()
{
return fN.toUpperCase();
}
public static void printUsers(List<User> users)
{
//I want to iterate through the users
//For each User o in users)
for(User o:users)
{
logln(o.getFullName());
}
}
public String toString()
{
return fN+lN;
}
public static void main(String [] args)
{
User myself = new User();
myself.setFirstName("Omar");
myself.setLastName("Belkady");
/* User him = new User();
/*him.setFirstName("Alan ");
him.setLastName(null);
logln(him.toString());
*/
User she = new User();
she.setFirstName("Angela ");
she.setLastName("");
//a blank string is not the same as NULL. This WILL NOT PRINT ANGELA NULL
logln(she);
//Should output Alan null;
//This will trigger a null pointer exception because we are trying to referene a null valeu
List<User> users = new ArrayList<User>();
users.add(myself);
//users.add(him);
//Pass in an entire list
User.printUsers(users);
logln(myself.output());
logln(myself.output());//nice message
logln(myself.output());//mean message
}
}