-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUserp1
109 lines (88 loc) · 1.9 KB
/
Userp1
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
//I will override the address output
import java.util.*;
public class Userp1
{
private String fN;
public String lN;
static void log(Object o)
{
System.out.print(o);
}
static void logln(Object o)
{
System.out.println(o);
}
public String getFullName()
{
return getFirstName() + " " + lN.toUpperCase();
}
public String output()
{
return "Hi, my name is "+ getFirstName() + " " + getLastName() + ".";
}
//Now I will overload output
public String output(boolean nice)
{
if(nice)
{
return "You\'re an awesome person"+ " " + getFullName() + ".";
}
return "You\'re an idiot"+ " " + getFullName() + ".";
}
public String getFirstName()
{
return fN;
}
//Setter not returning anything ∴ void
public void setFirstName(String firstName)
{
//Assigning the fName value we pass in to the field firstName
fN=firstName.trim();
//the .strip remove any whitespaces before output.
}
public String getLastName()
{
return lN;
}
//Setter not returning anything ∴ void
public void setLastName(String lastName)
{
//Assigning the lN value we pass in to the field lastName
lN=lastName;
}
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 static int searchList(List<User> users, String fN, String lN)
{
return searchList(users, fN + " " + lN);
}
//OVERLOAD
public static int searchList(List<User> users, String fullName)
{
//iterate through the list
for(int i=0;i<users.size();i++)
{
//Use .equals instead of ==
if(users.get(i).getFullName().equals(fullName))
{
return i;
}
}
//if no match
return -1;
}
//Now I will override the ToString
@Override
public String toString()
{
//To override remember to give the method to override the same name
return " " + getFullName() + "]";
}
}