Question
Can someone guide me thru this assignment plz??? My Assignment Is Listed As Below: For this program you will be adding a new class to
Can someone guide me thru this assignment plz???
My Assignment Is Listed As Below:
For this program you will be adding a new class to previous Homework. This class will provide a way to read and write data from / to a file and populate an ArrayList of Person objects or save the data of an ArrayList of objects. Build a new class which uses Text I/O to read text from a .csv (comma separated value) file. The text file will have values in the following format:
ObjectType,first-name,last-name, . all the rest of the information Phone,type,area code,prefix,suffix
A person could have any number of phone numbers listed after their information. There are no spaces between the entries, and no spaces before or after a comma.
I am leaving this assignment fairly vague because I want you to design the class in your own way. The only requirement is that the class must be able to read a file (ask the user for the name of the file) and somehow return an ArrayList. This ArrayList can then be passed to your Database class and used with the methods there.
The I/O class must also be able to take your ArrayList of Person objects and write all of the data to a NEW output file. Example File:
Student,Jack,Smith,117,-1,Sunshine Dr.,Los Angeles,CA,90012,jsmith@school.edu,freshman Phone,Cell,555,555,5555 Phone,Home,777,777,7777 Faculty,Jack,Smith,117,21,Sunshine Dr.,Los Angeles,CA,90012,jsmith@school.edu,E&T-310,40000,M/W 1-2 T/TH 3-4,Full Time Phone,Cell,555,555,5555 Phone,Home,777,777,7777 Phone,Work,888,888,8888 Staff,Jack,Smith,117,15,Sunshine Dr.,Los Angeles,CA,90012,jsmith@school.edu,E&T-310,30000,Computer Science Administrative Assistant Phone,Cell,555,555,5555
Note the use of -1 here. In my test data -1 at that position signifies that the person does not have an apartment number. Any other positive value would be their optional apartment number.
Additional Requirements:
Add a menu system to your database program which allows the user to test all functionality from the first program, i.e. menu options for all the things you were supposed to test in Homework 05. In addition to being able to save / load information to / from a chosen input file and chosen output file. Add an option to also be able to create a new person for the database. The person could be any of the person types from the previous assignment. This new person should be added to the ArrayList of people.
For the previous homework I have the codes listed below. The code is data university database that has several classes: address, faculty, student, staff, etc... We can create the database and the code will show for example how many students are there, list of people whose salary is greater or equal to 5000, and the information of those people etc..
Heres my code for previous homework:
Address class:
public class Address { private int streetNumber; private String optionalApartmentNumber; private String streetName; private String city; private String state; private int zipCode; public int getStreetNumber() { return streetNumber; } public void setStreetNumber(int streetNumber) { this.streetNumber = streetNumber; } public String getOptionalApartmentNumber() { return optionalApartmentNumber; } public void setOptionalApartmentNumber(String string) { this.optionalApartmentNumber = string;} public String getStreetName() { return streetName; } public void setStreetName(String streetName) { this.streetName = streetName; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getState() { return state; } public void setState(String state) { this.state = state; } public int getZipCode() { return zipCode; } public void setZipCode(int zipCode) { this.zipCode = zipCode; } public String toString() { String s5=""; if(optionalApartmentNumber!=null) { s5 = "Address: " + streetNumber + " " + streetName + " "+ " " + optionalApartmentNumber + " " + city + ", " + state + ", " + zipCode; return s5; } if(optionalApartmentNumber == null) { s5 = "Address: " + streetNumber + " " + streetName + " "+ " " + city + ", " + state + ", " + zipCode; return s5; } return s5; } }
Person class:
import java.util.ArrayList; public class Person { private String firstname; private String lastname; private String emailaddress; private Address address; private ArrayListnumber; public Person() {} public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getEmailaddress() { return emailaddress; } public void setEmailaddress(String emailaddress) { this.emailaddress = emailaddress; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public ArrayList getNumber() { return number; } public void setNumber(ArrayList number) { this.number = number; } public String toString() { String s; s= "Name: " + firstname + " " +lastname + " " + address + " Email: " + emailaddress + " "+"Phone: "; for(int i = 0; i< number.size(); i++) { PhoneNumber num = number.get(i); s += num +" "; } return s; }}
Employee class:
public class Employee extends Person { private String location; private double salary; public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } @Override public String toString() { String s2 = super.toString(); s2 = s2 + "Office Location: " + location + " " + "Salary: " + salary + " "; return s2; } }
faculty class:
public class Faculty extends Employee { String officeHours; String rank; public String getOfficeHours() { return officeHours; } public void setOfficeHours(String officeHours) { this.officeHours = officeHours; } public String getRank() { return rank; } public void setRank(String rank) { this.rank = rank; } @Override public String toString() { String s3; s3 = super.toString(); s3 += "Office Hours: " + officeHours + " " + "Rank: " + rank + " "; return s3; } }
phonenumber class:
public class PhoneNumber { private String type; private int areaCode; private int prefix; private int suffix; public PhoneNumber() {} public String getType() { return type; } public void setType(String type) { this.type = type; } public int getAreaCode() { return areaCode; } public void setAreaCode(int areaCode) { this.areaCode = areaCode; } public int getPrefix() { return prefix; } public void setPrefix(int prefix) { this.prefix = prefix; } public int getSuffix() { return suffix; } public void setSuffix(int suffix) { this.suffix = suffix; } public String toString() { String s1; s1 = "" + type + ": " + " (" + areaCode + ") " + prefix + " - " + suffix; return s1; } }
staff class:
public class Staff extends Employee{ String jobTitle; public String getJobTitle() { return jobTitle; } public void setJobTitle(String jobTitle) { this.jobTitle = jobTitle; } @Override public String toString() { String s4; s4 = super.toString(); s4+= "Job Title: " + jobTitle + " "; return s4; } }
student class:
public class Student extends Person { String classStanding; public String getClassStanding() { return classStanding; } public void setClassStanding(String classStanding) { this.classStanding = classStanding; } @Override public String toString() { String string = super.toString(); string += "Class Standing: " + classStanding + " "; return string; } }
database class:
import java.util.ArrayList; public class Database { private static ArrayListper = new ArrayList<>(); public Database(ArrayList per) { this.per = per; } public static void printDatabase(){ for(int i =0; i salary) { System.out.println(person); } } } } public static void displayEmployeesEqualToSalary(double salary) { for(int i =0; i getPer() { return per; } public void setPer(ArrayList per) { this.per = per; } }
And the testrun, which is the database that I created:
import java.util.ArrayList; public class Testrun { public static void main(String[] args) { ArrayListlistOfPeople=new ArrayList (); Student student1=new Student(); student1.setFirstname("Stephnie"); student1.setLastname("Khan"); student1.setEmailaddress("SteKhan@mail.com"); student1.setClassStanding("freshman"); PhoneNumber ph_1=new PhoneNumber(); ph_one.setAreaCode(626); ph_one.setType("Home"); ph_one.setPrefix(322); ph_one.setSuffix(6532); PhoneNumber ph_2=new PhoneNumber(); ph_two.setAreaCode(815); ph_two.setType("Mobile"); ph_two.setPrefix(774); ph_two.setSuffix(1212); ArrayList phones=new ArrayList (); phones.add(ph_1); phones.add(ph_2); student1.setNumber(phones); Student student2=new Student(); student2.setFirstname("Ken"); student2.setLastname("Chen"); student2.setEmailaddress("kman@mail.com"); student2.setClassStanding("junior"); PhoneNumber ph_three=new PhoneNumber(); ph_three.setAreaCode(626); ph_three.setType("Mobile"); ph_three.setPrefix(789); ph_three.setSuffix(2345); ArrayList phones2=new ArrayList (); phones2.add(ph_3); student2.setNumber(phones2); Staff staff1=new Staff(); staff1.setFirstname("Jennifer"); staff1.setLastname("Mach"); staff1.setEmailaddress("jennychinchin@mail.com"); staff1.setSalary(5000); staff1.setJobTitle("Vice President"); PhoneNumber sph_one=new PhoneNumber(); sph_one.setAreaCode(626); sph_one.setType("Mobile"); sph_one.setPrefix(757); sph_one.setSuffix(2223); PhoneNumber sph_two=new PhoneNumber(); sph_two.setAreaCode(626); sph_two.setType("Mobile"); sph_two.setPrefix(663); sph_two.setSuffix(3222); ArrayList sphones=new ArrayList (); sphones.add(ph_4); sphones.add(ph_5); staff1.setNumber(sphones); Staff staff2=new Staff(); staff2.setFirstname("Loren"); staff2.setLastname("Chen"); staff2.setEmailaddress("Lchen@mail.com"); staff2.setSalary(6000); staff2.setJobTitle("Administrator"); PhoneNumber s2ph_one=new PhoneNumber(); s2ph_one.setAreaCode(583); s2ph_one.setType("Home"); s2ph_one.setPrefix(202); s2ph_one.setSuffix(314); PhoneNumber s2ph_two=new PhoneNumber(); s2ph_two.setAreaCode(111); s2ph_two.setType("Mobile"); s2ph_two.setPrefix(334); s2ph_two.setSuffix(334); ArrayList s2phones=new ArrayList (); s2phones.add(ph_6); s2phones.add(ph_7); staff2.setNumber(s2phones); Faculty faculty = new Faculty(); faculty.setFirstname("Zac"); faculty.setLastname("You"); faculty.setEmailaddress("zac1@csula.com"); faculty.setSalary(4000); faculty.setRank("#11"); faculty.setOfficeHours("M,W,F, 1:50PM-3:05PM"); faculty.setLocation("CSULA"); PhoneNumber ph_4=new PhoneNumber(); ph_4.setAreaCode(345); ph_4.setType("Mobile"); ph_4.setPrefix(111); ph_4.setSuffix(111); ArrayList phones41=new ArrayList (); phones41.add(ph_8); faculty.setNumber(phones41); Employee emp = new Employee(); emp.setFirstname("Keenan"); emp.setLastname("Wang"); emp.setEmailaddress("Knnena@gamil.com"); emp.setSalary(3000.0); emp.setLocation("UCLA"); PhoneNumber ph_5=new PhoneNumber(); ph_5.setAreaCode(626); ph_5.setType("Mobile"); ph_5.setPrefix(123); ph_5.setSuffix(111); ArrayList phones4=new ArrayList (); PhoneNumber ph_6 = new PhoneNumber(); ph_6.setAreaCode(728); ph_6.setPrefix(111); ph_6.setSuffix(112); ph_6.setType("Home"); phones4.add(ph_9); phones4.add(ph_10); emp.setNumber(phones4); Address ad1=new Address(); ad1.setStreetNumber(112); ad1.setCity("Las Vegas"); ad1.setState("NV"); ad1.setOptionalApartmentNumber("A1333"); ad1.setStreetName("Washington Ave"); ad1.setZipCode(644443); Address ad2=new Address(); ad2.setStreetNumber(999); ad2.setCity("Los Angeles"); ad2.setState("CA"); ad2.setOptionalApartmentNumber("777"); ad2.setStreetName("Peck Road"); ad2.setZipCode(91755); Address ad3=new Address(); ad3.setStreetNumber(555); ad3.setCity("Monterey Park"); ad3.setState("CA"); ad3.setOptionalApartmentNumber("D"); ad3.setStreetName("Alhambra Ave"); ad3.setZipCode(91755); Address ad4=new Address(); ad4.setStreetNumber(673); ad4.setCity("Hollywood"); ad4.setState("CA"); ad4.setOptionalApartmentNumber("AP-12"); ad4.setStreetName("Hollywood Dr."); ad4.setZipCode(90076); Address ad5 = new Address(); ad5.setStreetNumber(14209); ad5.setCity("Baldwin Park"); ad5.setStreetName("Riverside St."); ad5.setZipCode(91706); ad5.setState("CA"); student1.setAddress(ad1); student2.setAddress(ad2); staff1.setAddress(ad3); staff2.setAddress(ad4); faculty.setAddress(ad5); emp.setAddress(ad5); listOfPeople.add(student1); listOfPeople.add(student2); listOfPeople.add(staff1); listOfPeople.add(staff2); listOfPeople.add(faculty); listOfPeople.add(emp); Database database=new Database(listOfPeople); System.out.println("Displaying all the people: "); database.printDatabase(); System.out.println(" Displaying all the staff members: "); database.printDatabase("staff"); System.out.println(" Displaying all the students: "); database.printDatabase("student"); System.out.println(" Displaying all the facultys: "); database.printDatabase("faculty"); System.out.println(" Displaying all the employees: "); database.printDatabase("employee"); System.out.println(" Displaying all members with salary equal to 4000: "); database.displayEmployeesEqualToSalary(4000); System.out.println(" Displaying all members with salary less than 4000: "); database.displayEmployeesLessThanSalary(4000); System.out.println(" Displaying all members with salary greater than 4000: "); database.displayEmployeesGreaterThanSalary(4000); System.out.println(" "); System.out.println("Total number of people: " + database.getNumberOfPeople()); System.out.println("Number of employees: "+database.getNumberOfEmployees()); System.out.println("Numbetr of faculty: "+database.getNumberOfFaculty()); System.out.println("Number of staff: "+database.getNumberOfStaff()); System.out.println("Number of students: "+database.getNumberOfStudents()); System.out.println("Number of freshman: "+database.getNumberOfStudentsByClassStanding("freshman")); System.out.println("Number of Sophmore: "+database.getNumberOfStudentsByClassStanding("sophmore")); System.out.println("Number of Junior: "+database.getNumberOfStudentsByClassStanding("Junior")); System.out.println("Number of Senior: "+database.getNumberOfStudentsByClassStanding("senior")); }}
I dont quite get this assignment, I hope you can explain what we are requied to do and guide me thru it as detailed as possible, thank you so much for your help!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started