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
![Graduate Student.java
public class Graduate Student extends Student {
public static final double GRAD_TUITION = 6000;
public Graduate Student(String fName, String IName, StudentClassification eStudent, Address stuAddress) {
super(fName, IName, eStudent, stuAddress);
set Tuition();
}
@Override
public void setTuition() {
tuition = GRAD_TUITION;
}
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F44e710c5-82f1-4975-896c-cdeba81321cf%2Fb10e7136-50b3-47b5-9092-c80f1c78442e%2Fsptd9hw_processed.png&w=3840&q=75)
![Undergraduate Student.java
public class Undergraduate Student extends Student {
public static final double UNDERGRAD_TUITION = 4000;
public Undergraduate Student(String fName, String IName, StudentClassification eStudent, Address stuAddress) {
super(fName, IName, eStudent, stuAddress);
set Tuition();
}
@Override
public void setTuition() {
tuition = UNDERGRAD_TUITION;
}
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F44e710c5-82f1-4975-896c-cdeba81321cf%2Fb10e7136-50b3-47b5-9092-c80f1c78442e%2F0d2mj2g_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)