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: Harry Muggle Potter
ID: 500 Tuition: 4000.0
Address: St. Louis, Georgia 30305
Undergraduate student of status: FRESHMAN
-----------------------------
Algorithm: Student Information Management System
1. Create an empty ArrayList to store student objects.
2. Create a StringBuilder to build the student information output.
3. Set the starting ID for student generation using the StudentIdGenerator Singleton.
4. Create four student objects:
a. Create an UndergraduateStudent object "Harry Potter" with the following details:
- Name: Harry Potter
- Student Classification: FRESHMAN
- Address: Atlanta, Georgia, 30305, Main St, 123, Apt 101
b. Create an UndergraduateStudent object "Diana-Wonder-Woman Prince" with the following details:
- Name: Diana-Wonder-Woman Prince
- Student Classification: JUNIOR
- Address: Washington D.C., District of Columbia, 30318, Broadway Ave, 456, Apt 202
c. Create a GraduateStudent object "John Doe" with the following details:
- Name: John Doe
- Student Classification: MASTERS
- Address: New York, New York, 10001, 5th Ave, 789, Apt 303
d. Create a GraduateStudent object "Jane Smith" with the following details:
- Name: Jane Smith
- Student Classification: DOCTORATE
- Address: Los Angeles, California, 90001, Sunset Blvd, 987, Apt 505
5. Loop through each student in the ArrayList:
a. Build student information as follows:
- Name
- ID
- Tuition
- Address (City, State, Zip, Street, Street Number, Apartment Number)
- Student Classification (Undergraduate or Graduate)
b. Print the student information.
6. End the loop.
7. End the program.
Step by stepSolved in 5 steps with 8 images
- Create a UML class diagram of the application illustrating class hierarchy, collaboration, and the content of each class. There is only one class. There is a main method that calls four methods. I am not sure if I made the UML Class diagram correct. import java.util.Random; // import Random packageimport java.util.Scanner; // import Scanner Package public class SortArray{ // class name public static void main(String[] args) { //main method Scanner scanner = new Scanner(System.in); // creates object of the Scanner classint[] array = initializeArray(scanner); System.out.print("Array of randomly generated values: ");displayArray(array); // Prints unsorted array sortDescending(array); // sort the array in descending orderSystem.out.print("Values in desending order: ");displayArray(array); // prints the sorted array, should be in descending ordersortAscending(array); // sort the array in ascending orderSystem.out.print("Values in asending order: ");displayArray(array); // prints the…arrow_forwardPlease help with the following question: In Java without using arrays, Integer.parseInt in the main class or this.keyword in the classes code the following. Make 1 project having 1 main class and 3 other classes. For each classes you need make to use the constructor to set its attributes. Your classes have to have setters and getters and their attributes should all be private. Make a class University A university name (string)A university population (int)A university budget(double) Make a class Department An ID(int)A Name(string)A DEP ID(int) Make a class Student Dep Name(string)Dep ID(int) In the main class first Create three departments.Ask the user to input the field values. In the main class create 5 students. Ask the user to input the field values. Write a function in the main class that takes two integers as input and Checks if they are equal. Use that function to check if for a department and a student their DEP ID is equal. (So you have to check if dep1.di=student1.id for…arrow_forwardfinal big report project for java. 1.Problem Description Student information management system is used to input, display student information records. The GUI interface for inputing ia designed as follows : The top part are the student imformation used to input student information,and the bottom part are four buttonns, each button meaning : (2) Total : add java score and C++ score ,and display the result; (3) Save: save student record into file named student.dat; (4) Clear : set all fields on GUI to empty string; (5) Close : close the winarrow_forward
- We already have the address and vehicle class for the system below. We will need a CarShow class with IsSanctioned() method, Owner class with IsOwner method and a main class that creates objects and implements all our existing classes. Use the class diagrams. Make sure to include respective attributes, setters, getters and constructors in your code Explain your code in a few words.arrow_forwardImplement the following in the .NET Console App. Write the Bus class. A Bus has a length, a color, and a number of wheels. a. Implement data fields using auto-implemented Properies b. Include 3 constructors: default, the one that receives the Bus length, color and a number of wheels as input (utilize the Properties) and the Constructor that takes the Bus number (an integer) as input.arrow_forwardUsing the Card.java class file, write a program to simulate a Deck of Cards. See Programming Project 8.7 (PP 8.7) from page 403 of your textbook (or view the attached image) for a description of what your program needs to do. Note that although the book description of the problem states that you should write the Card class, I do not want you to do that. You must use the Card file exactly as it is provided (NO modifications) and only write the DeckOfCards and Driver classes. public class Card{public final static int ACE = 1;public final static int TWO = 2;public final static int THREE = 3;public final static int FOUR = 4;public final static int FIVE = 5;public final static int SIX = 6;public final static int SEVEN = 7;public final static int EIGHT = 8;public final static int NINE = 9;public final static int TEN = 10;public final static int JACK = 11;public final static int QUEEN = 12;public final static int KING = 13; public final static int CLUBS = 1;public final static int DIAMONDS =…arrow_forward
- Java Question - Instructions are in the attached pictures. The picture titled "Screenshot..." are the instructions for building the specific code, while the "Final Output" picture shows what the output of the code should look like. Please make sure no errors show up in the Java compiler. Thank you.arrow_forwardHello! Need help with my Java Homework Please use Eclipse and Add a comments in each program to explain what your code is doing so I can understand it and learn. I really appreciate the help! Examine carefully the UML class diagram Attached: NOTE: Class Reptile was missing a toString() method. It has now been added. class Pet has an attribute of type java.util.Date. no specific dates are required for this attribute. compareTo(Dog) compares Dogs by weight. Create executable class TestPet as follows: create at least one Reptile pet and display it create an array of at least four Dog pets sort the array of Dogs by weight use a foreach loop to fully display all data for all dogs sorted by weight (see sample output) Sample Output Reptile name = Slinky, rock python, M Must be caged, crawls or slithers Not much sound, maybe a hiss, acquired Fri Feb 03 17:06:54 EST 2017 All dogs sorted by weight Dog name = Pedro, chihuahua, M Walks on a leash, weight 14 Barks or howls, acquired Fri…arrow_forwardUsing this link: https://docs.oracle.com/javase/tutorial/java/concepts/interface.html and https://docs.oracle.com/javase/tutorial/java/concepts/class.html Create in Java: An interface named bicycle as described in the section: What is an interface? Add a new method for the interface bicycle: ring the bell with a parameter indicating how many time. Pick a bicycle brand and create a new class of bicycles for that brand, as described in the sections What is an interface? and What is a Class? For the new method implementation, write in the console "Clang! Clang!..." for how many times the parameter indicates. Create another class, with a main method, in which you will take a trip aroound your house, changing your bicycle attributes, starting and ending from a complete stop, and ringing the bell once at start and twice at the end. Use as inspiration the method in What is a Class? Your trip must have at least 5 different parts in which you change your bicycle…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY