Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone guide me thru this assignment plz??? My Assignment Is Listed As Belo

ID: 3727349 • Letter: C

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 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:

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:

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:

Person class:

Employee class:

faculty class:

phonenumber class:

staff class:

student class:

database class:

And the testrun, which is the database that I created:

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!!

Explanation / Answer

package assignmentcsv;

import java.util.ArrayList;

public class Testrun {

public static void main(String[] args) {

/*ArrayList<Person> listOfPeople=new ArrayList<Person>();

Student student1=new Student();
student1.setFirstname("Stephnie");
student1.setLastname("Khan");
student1.setEmailaddress("SteKhan@mail.com");
student1.setClassStanding("freshman");
PhoneNumber ph_one=new PhoneNumber();
ph_one.setAreaCode(626);
ph_one.setType("Home");
ph_one.setPrefix(322);
ph_one.setSuffix(6532);
PhoneNumber ph_two=new PhoneNumber();
ph_two.setAreaCode(815);
ph_two.setType("Mobile");
ph_two.setPrefix(774);
ph_two.setSuffix(1212);
ArrayList<PhoneNumber> phones=new ArrayList<PhoneNumber>();
phones.add(ph_one);
phones.add(ph_two);
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<PhoneNumber> phones2=new ArrayList<PhoneNumber>();
phones2.add(ph_three);
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<PhoneNumber> sphones=new ArrayList<PhoneNumber>();
sphones.add(sph_one);
sphones.add(sph_two);
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<PhoneNumber> s2phones=new ArrayList<PhoneNumber>();
s2phones.add(s2ph_one);
s2phones.add(s2ph_two);
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<PhoneNumber> phones41=new ArrayList<PhoneNumber>();
phones41.add(ph_4);
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<PhoneNumber> phones4=new ArrayList<PhoneNumber>();
PhoneNumber ph_6 = new PhoneNumber();
ph_6.setAreaCode(728);
ph_6.setPrefix(111);
ph_6.setSuffix(112);
ph_6.setType("Home");
phones4.add(ph_5);
phones4.add(ph_6);
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"));*/

FileHelper.readFile("data.csv");
ArrayList<Person> persons=FileHelper.createObjects();
for (Person person : persons) {
   if(person!=null)
   System.out.println(person.toString()+" ");
  
}
}}

//I have commented your code in above class to test my methods, please uncomment if you need.

package assignmentcsv;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;

public class FileHelper {
   static ArrayList<String> data = new ArrayList<>();

   // Read the file
   public static void readFile(String filename) {
       try {
           data = (ArrayList<String>) Files.readAllLines(new File("./" + filename).toPath(), Charset.defaultCharset());
           System.out.println(data);
       } catch (IOException e) {
           e.printStackTrace();
       }
   }

   public static ArrayList<Person> createObjects() {
       ArrayList<Person> persons = new ArrayList<>();

       // first get the whole data
       // parse data to objects and add to list of people
       // first we need to identify object type and then create object accordingly
       int index = 0;
       do {
           String string = data.get(index);
           if (string.contains("Student")) {
               // create a student object
               // read first line and split using ,
               String arr[] = string.split(",");
               Student student = new Student();
               student.setFirstname(arr[1]);
               student.setLastname(arr[2]);

               // create address object
               Address add = new Address();
               add.setStreetNumber(Integer.parseInt(arr[3]));
               add.setOptionalApartmentNumber(arr[4]);
               add.setStreetName(arr[5]);
               add.setState(arr[6]);
               add.setCity(arr[7]);
               add.setZipCode(Integer.parseInt(arr[8]));
               student.setEmailaddress(arr[9]);
               student.setClassStanding(arr[10]);

               student.setAddress(add);

               // create phone objects
               String s = null;
               index++;
               ArrayList<PhoneNumber> numbers = new ArrayList<>();

               do {
                   s = data.get(index);
                   if ((s.contains("Staff") || s.contains("Faculty") || s.contains("Student"))) {
                       break;
                   }
                   String array[] = s.split(",");
                   PhoneNumber phone = new PhoneNumber();
                   phone.setAreaCode(Integer.parseInt(array[2]));
                   phone.setType(array[1]);
                   phone.setPrefix(Integer.parseInt(array[3]));
                   phone.setSuffix(Integer.parseInt(array[4]));
                   numbers.add(phone);
                   index++;
               } while (data.size() >index);
               student.setNumber(numbers);
               persons.add(student);
           } else if (string.contains("Faculty")) {
               // create a student object
               // read first line and split using ,
               String arr[] = string.split(",");
               Faculty faculty = new Faculty();
               faculty.setFirstname(arr[1]);
               faculty.setLastname(arr[2]);

               // create address object
               Address add = new Address();
               add.setStreetNumber(Integer.parseInt(arr[3]));
               add.setOptionalApartmentNumber(arr[4]);
               add.setStreetName(arr[5]);
               add.setState(arr[6]);
               add.setCity(arr[7]);
               add.setZipCode(Integer.parseInt(arr[8]));
               faculty.setEmailaddress(arr[9]);
               faculty.setLocation(arr[10]);
               faculty.setSalary(Double.parseDouble(arr[11]));
               faculty.setOfficeHours(arr[12]);
               faculty.setRank(arr[13]);

               faculty.setAddress(add);

               // create phone objects
               String s = null;
               index++;
               ArrayList<PhoneNumber> numbers = new ArrayList<>();

               do {
                   s = data.get(index);
                   if ((s.contains("Staff") || s.contains("Faculty") || s.contains("Student"))) {
                       break;
                   }
                   String array[] = s.split(",");
                   PhoneNumber phone = new PhoneNumber();
                   phone.setAreaCode(Integer.parseInt(array[2]));
                   phone.setType(array[1]);
                   phone.setPrefix(Integer.parseInt(array[3]));
                   phone.setSuffix(Integer.parseInt(array[4]));
                   numbers.add(phone);
                   index++;
               } while (data.size() >index);
               faculty.setNumber(numbers);
               persons.add(faculty);
           } else if (string.contains("Staff")) {
               // create a student object
               // read first line and split using ,
               String arr[] = string.split(",");
               Staff staff = new Staff();
               staff.setFirstname(arr[1]);
               staff.setLastname(arr[2]);

               // create address object
               Address add = new Address();
               add.setStreetNumber(Integer.parseInt(arr[3]));
               add.setOptionalApartmentNumber(arr[4]);
               add.setStreetName(arr[5]);
               add.setState(arr[6]);
               add.setCity(arr[7]);
               add.setZipCode(Integer.parseInt(arr[8]));
               staff.setEmailaddress(arr[9]);
               staff.setLocation(arr[10]);
               staff.setSalary(Double.parseDouble(arr[11]));
               staff.setJobTitle(arr[12]);

               staff.setAddress(add);

               // create phone objects
               String s = null;
               index++;
               ArrayList<PhoneNumber> numbers = new ArrayList<>();

               do {
                   s = data.get(index);
                   if ((s.contains("Staff") || s.contains("Faculty") || s.contains("Student"))) {
                       break;
                   }
                   String array[] = s.split(",");
                   PhoneNumber phone = new PhoneNumber();
                   phone.setAreaCode(Integer.parseInt(array[2]));
                   phone.setType(array[1]);
                   phone.setPrefix(Integer.parseInt(array[3]));
                   phone.setSuffix(Integer.parseInt(array[4]));
                   numbers.add(phone);
                   index++;
               } while (data.size() >index);
               staff.setNumber(numbers);
               persons.add(staff);
           }
       } while (data.size() >index);

       return persons;
   }
}

output

[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]
Name: Jack Smith
Address: 117 Sunshine Dr.
         -1 CA, Los Angeles, 90012
Email: jsmith@school.edu
Phone:
Cell: (555) 555 - 5555
Home: (777) 777 - 7777
Class Standing: freshman


Name: Jack Smith
Address: 117 Sunshine Dr.
         21 CA, Los Angeles, 90012
Email: jsmith@school.edu
Phone:
Cell: (555) 555 - 5555
Home: (777) 777 - 7777
Work: (888) 888 - 8888
Office Location: E&T-310
Salary: 40000.0
Office Hours: M/W 1-2 T/TH 3-4
Rank: Full Time


Name: Jack Smith
Address: 117 Sunshine Dr.
         15 CA, Los Angeles, 90012
Email: jsmith@school.edu
Phone:
Cell: (555) 555 - 5555
Office Location: E&T-310
Salary: 30000.0
Job Title: Computer Science Administrative Assistant

File :

data.csv

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