Created
January 31, 2014 14:40
-
-
Save timxor/8733273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lab1; | |
public class Student { | |
// Private variables | |
private final String firstName, lastName; | |
private String username; | |
private final int id; | |
private final boolean isFulltime; | |
// End private variables | |
// Default constructor | |
public Student(String firstName, String lastName, int id, boolean isFulltime) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.username = generateUsername(); | |
this.id = id; | |
this.isFulltime = isFulltime; | |
} | |
// Second constructor | |
public Student(String firstName, String lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.username = generateUsername(); | |
this.id = 0; | |
this.isFulltime = true; | |
} | |
// Getter for firstName | |
public String getFirstName() { | |
return firstName; | |
} | |
// Getter for lastName | |
public String getLastName() { | |
return lastName; | |
} | |
// Getter for id | |
public int getId() { | |
return id; | |
} | |
// Getter for isFulltime | |
public boolean getIsFulltime() { | |
return isFulltime; | |
} | |
// Getter for username | |
public String getUserName() { | |
return username; | |
} | |
// Setter for firstName | |
public void setFirstName(String fname) { | |
fname = firstName; | |
} | |
// Setter for lastName | |
public void setLastName(String lname) { | |
lname = lastName; | |
} | |
// Setter for id | |
public void setId(int sid) { | |
sid = id; | |
} | |
// Getter for isFulltime | |
public void setIsFulltime(boolean iFulltime) { | |
iFulltime = isFulltime; | |
} | |
// Setter for username | |
public void setUserName(String un) { | |
un = username; | |
} | |
public String toStirng() { | |
return "Student firstName is: " + firstName + "Student lastName is: " | |
+ lastName + "Student id is: " + id + "Student username is: " | |
+ username; | |
} | |
public static void main(String args[]) { | |
Student student0 = new Student("Tim", "Siwula", 123, true); | |
Student student1 = new Student("Frank", "Smith", 199, true); | |
Student student2 = new Student("Sarah", "Sin", 200, true); | |
Student student3 = new Student("Manny", "Parra"); | |
Student student4 = new Student("Kevin", "Golf"); | |
Student[] arr = new Student[4]; | |
arr[0] = student0; | |
arr[1] = student1; | |
arr[2] = student2; | |
arr[3] = student3; | |
arr[4] = student4; | |
for (int i = 0; i < 5; i++) { | |
System.out.println("student" + i + ".username " | |
+ arr[i].generateUsername()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment