-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentBuild.java
More file actions
220 lines (190 loc) · 4.51 KB
/
StudentBuild.java
File metadata and controls
220 lines (190 loc) · 4.51 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
public class StudentBuild // user class
{
public static void main(String[] args)
{
// set static fields
Student.setClassName("Texts and Contexts");
Student.setClassNumber("R06");
Student.setInstructor("Prof. Franz");
// large constructor
Student s1 = new Student("Claire", "Yustat", "316 Arthur Ave", "Bronx", "NY", "cyustat@fordham.edu");
Student s2 = new Student("Polina", "Bolberova", "111 E Fordham Rd", "Bronx", "NY", "pbolberov@fordham.edu");
Student s3 = new Student("Emily", "Ruegger", "18 Patriots Rd", "Bronx", "NY", "eruegger@fordham.edu");
// small constructor
Student s4 = new Student("Grace", "Cook");
Student s5 = new Student("Grace", "McLees");
// output students
System.out.println(s1.toString());
System.out.println();
System.out.println(s2.toString());
System.out.println();
System.out.println(s3.toString());
System.out.println();
System.out.println(s4.toString());
System.out.println();
System.out.println(s5.toString());
System.out.println();
// use some getters & setters
Student.setClassName("Java Programming");
s4.setAddress("5 Martin Ln");
s4.setCity("Manhattan");
s4.setState("NY");
s4.setEmail("gcook@fordham.edu");
s5.setAddress("50 Cent Ave");
s5.setCity("Bronx");
s5.setState("NY");
s5.setEmail("gmclees@fordham.edu");
String firstName2 = s2.getFirstName();
String lastName2 = s2.getLastName();
System.out.println(firstName2 + " " + lastName2);
System.out.println();
String address3 = s3.getAddress();
System.out.println(address3);
System.out.println();
s1.setAddress(address3);
// output students again
System.out.println(s1.toString());
System.out.println();
System.out.println(s2.toString());
System.out.println();
System.out.println(s3.toString());
System.out.println();
System.out.println(s4.toString());
System.out.println();
System.out.println(s5.toString());
}
}
class Student // service class
{
// static fields
private static String classNumber;
private static String className;
private static String instructor;
static int studentCount = 1000; // counter used for studentId
// instance fields
private int studentId;
private String firstName;
private String lastName;
private String address;
private String city;
private String state;
private String email;
// constructor #1
Student(String first, String last)
{
firstName = first;
lastName = last;
studentId = studentCount;
studentCount++; // increment count
}
// constructor #2
Student(String first, String last, String address, String city, String state, String email)
{
this(first, last);
this. address = address;
this.city = city;
this.state = state;
this.email = email;
}
// STATIC getter/setter methods
// classNumber
static String getClassNumber() // getter
{
return(classNumber);
}
static void setClassNumber(String classNum) // setter
{
classNumber = classNum;
}
// className
static String getClassName() // getter
{
return(className);
}
static void setClassName(String classNa) // setter
{
className = classNa;
}
//instructor
static String getInstructor() // getter
{
return(instructor);
}
static void setInstructor(String in)
{
instructor = in;
}
// INSTANCE getter/setter methods
// studentId
int getStudentId() //getter
{
return(studentId);
}
// no studentId setter needed, generated by constructors
// firstName
String getFirstName() // getter
{
return(firstName);
}
void setFirstName(String fName) // setter
{
firstName = fName;
}
// lastName
String getLastName() // getter
{
return(lastName);
}
void getLastname(String lName) // setter
{
lastName = lName;
}
// address
String getAddress() // getter
{
return(address);
}
void setAddress(String a) // setter
{
address = a;
}
// city
String getCity() // getter
{
return(city);
}
void setCity(String c) // setter
{
city = c;
}
// state
String getState() // getter
{
return(state);
}
void setState(String s) // setter
{
state = s;
}
// email
String getEmail() // getter
{
return(email);
}
void setEmail(String e) // setter
{
email = e;
}
// toString() method
public String toString()
{
String data = "Student Name: " + firstName + " " + lastName + "\n" +
"Student I.D.: " + studentId + "\n" +
"Class Name: " + className + "\n" +
"Instructor Name: " + instructor + "\n" +
"Class Number: " + classNumber + "\n" +
"Student Address: " + address + ", " + city + ", " + state + "\n" +
"Student Email Address: " + email;
return(data);
}
}