a public class Address { private String _city; private String _state; private String _streetName; // New private int _streetNumber; //
the following code is centered around data collection, filtering, and using the Singleton pattern in Java, which is all part of a mockup "student
Address.java
public class Address {
private String _city;
private String _state;
private String _streetName; // New
private int _streetNumber; // New
private int _apartmentNumber; // New
public Address(String city, String state, int zip, String streetName, int streetNumber, int apartmentNumber) {
setCity(city);
setState(state);
setZip(zip);
setStreetName(streetName);
setStreetNumber(streetNumber);
setApartmentNumber(apartmentNumber);
}
public String getCity() {
return _city;
}
public void setCity(String city) {
_city = city;
}
public String getState() {
return _state;
}
public void setState(String state) {
_state = state;
}
public int getZip() {
return _zip;
}
public void setZip(int zip) {
_zip = zip;
}
public String getStreetName() {
return _streetName;
}
public void setStreetName(String streetName) {
_streetName = streetName;
}
public int getStreetNumber() {
return _streetNumber;
}
public void setStreetNumber(int streetNumber) {
_streetNumber = streetNumber;
}
public int getApartmentNumber() {
return _apartmentNumber;
}
public void setApartmentNumber(int apartmentNumber) {
_apartmentNumber = apartmentNumber;
}
}
Student.java
public abstract class Student {
private long Id;
private String _lastName, _firstName;
protected Address _stuAddress;
protected double tuition;
protected StudentClassification eStudentClass;
public Student(String firstName, String lastName, StudentClassification eStudent, Address stuAddress) {
setId();
if ((!firstName.equals("")) && (firstName.matches("^[-a-zA-Z\\s]*$"))) {
setFirstName(firstName);
} else {
setFirstName("INVALID FIRST NAME");
}
setLastName(lastName);
setClassification(eStudent);
_stuAddress = stuAddress;
}
private void setId() {
Id = StudentIdGenerator.getNextId();
}
public long getId() {
return Id;
}
public String getLastName() {
return _lastName;
}
public void setLastName(String pName) {
_lastName = pName;
}
public String getFirstName() {
return _firstName;
}
public void setFirstName(String pName) {
_firstName = pName;
}
public double getTuition() {
return tuition;
}
public StudentClassification getClassification() {
return eStudentClass;
}
public abstract void setTuition();
@Override
public String toString() {
StringBuilder studentInfo = new StringBuilder("Name: " + getFirstName() + " " + getLastName() + "\n");
studentInfo.append("ID: " + getId() + " Tuition: " + getTuition() + "\n");
studentInfo.append("Address: " + _stuAddress.getCity() + ", " + _stuAddress.getState());
studentInfo.append(" " + _stuAddress.getZip());
studentInfo.append(" " + _stuAddress.getStreetName() + ", " + _stuAddress.getStreetNumber());
studentInfo.append(", Apt " + _stuAddress.getApartmentNumber());
return studentInfo.toString();
}
}
StudentDemo3.java
import java.util.ArrayList;
public class StudentDemo3 {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
StringBuilder studentOutput = new StringBuilder("");
// Use the setStartingID() method in 'StudentIdGenerator' Singleton class to start at 500
StudentIdGenerator.setStartingID(500);
students.add(new UndergraduateStudent("Harry Muggle", "Potter", StudentClassification.FRESHMAN,
new Address("Atlanta", "Georgia", 30305, "Main St", 123, 101)));
students.add(new UndergraduateStudent("Diana-Wonder-Woman", "Prince", StudentClassification.JUNIOR,
new Address("Washington D.C.", "District of Columbia", 30318, "Broadway Ave", 456, 202)));
// Add two GraduateStudent objects to the 'students' collection (ArrayList)
students.add(new GraduateStudent("John", "Doe", StudentClassification.MASTERS,
new Address("New York", "New York", 10001, "5th Ave", 789, 303)));
students.add(new GraduateStudent("Jane", "Smith", StudentClassification.DOCTORATE,
new Address("Los Angeles", "California", 90001, "Sunset Blvd", 987, 505)));
// Loop to print student information
for (Student s : students) {
studentOutput.append("\n-----------------------------\n").append(s.toString());
if (s instanceof UndergraduateStudent) {
studentOutput.append("\nUndergraduate student of status: ").append(s.getClassification().toString());
} else if (s instanceof GraduateStudent) {
studentOutput.append("\nGraduate student of status: ").append(s.getClassification().toString());
}
System.out.println(studentOutput.toString() + "\n");
studentOutput.setLength(0);
}
}
}
please run the code such that it has the appropriate expected outcome of
-----------------------------
Name: Diana-Wonder-Woman Prince
ID: 501 Tuition: 4000.0
Address: Washington D.C., District of Columbia 30318
Undergraduate student of status: JUNIOR
The code you provided is for a mock "student information management system" that deals with the creation and representation of student information. There are classes that represent the attributes and behaviors of students, their addresses, and the respective tuitions for undergraduate and graduate students. We'll be organizing this code into a cohesive project, setting it up in a way that facilitates its execution.
Step by step
Solved in 3 steps