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

In this program, you are going to read in a top 50 women in business data set fi

ID: 3587564 • Letter: I

Question

In this program, you are going to read in a top 50 women in business data set file, Top50.txt. You are going to create a BusinessWoman object which keeps track of the ID, FirstName, LastName, CompanyName, and Age.


You are going to store it into an array of BusinessWoman objects. The default starting size is 10. You are going mimic an ArrayList, and when you add items you will use an add method that you create. If you run out of space, you need to expand the array (double its size) and copy all the previous items into the new array when you run out of space.
Finally, you should print out each of the objects by using a get method that you create. Specifics:

1. Read in the Top50 file and create BusinessWoman objects. 2. Store each object into the array you created. 3. Initialize the array size to 10. Please do not use an actual ArrayList. 4. Create an expand method when the number of items read in exceeds the size of the array. 5. Create a size method to keep track of how large your "ArrayList. " 6. Create an add method to add items to your "ArrayList. " 7. Create a get method to get items out of your "ArrayList.” 8. Print out all the students in your "ArrayList" at the end.

Top50.txt.

ID,FirstName,LastName,Company,Age,
1,Mary,Barra,General Motors,55,
2,Indra,Nooyi,PepsiCo,61,
3,Marillyn,Hewson,Lockheed Martin,63,
4,Abigail,Johnson,Fidelity Investments,55,
5,Sheryl,Sandberg,Facebook,48,
6,Ginni,Rometty,IBM,60,
7,Meg,Whitman,Hewlett Packard Enterprise,61,
8,Safra,Catz,Oracle,55,
9,Phebe,Novakovic,General Dynamics,59,
10,Ruth,Porat,"Google, Alphabet",59,
11,Lynn,Good,Duke Energy,58,
12,Helena,Foulkes,CVS Health,53,
13,Angela,Ahrendts,Apple,57,
14,Susan,Wojcicki,"Google, Alphabet",49,
15,Tricia,Griffith,Progressive,52,
16,Cathy,Engelbert,Deloitte,52,
17,Pam,Nicholson,Enterprise Holdings,57,
18,Ann,Marie Campbell,Home Depot,52,
19,Geisha,Williams,PG&E Corporation,56,
20,Debra,Reed,Sempra Energy,61,
21,Karen,Lynch,Aetna,54,
22,Sandra,Peterson,Johnson & Johnson,58,
23,Heather,Bresch,Mylan,48,
24,Marianne,Lake,JPMorgan Chase,48,
25,Margaret,Keane,Synchrony Financial,58,
26,Amy,Hood,Microsoft,45,
27,Mary,Callahan Erdoes,JPMorgan Chase,50,
28,Judith,McKenna,"Walmart U.S., Walmart",51,
29,Barbara,Rentler,Ross Stores,60,
30,Leanne,Caret,Boeing,50,
31,Denise,Morrison,Campbell Soup,63,
32,Vicki,Hollub,Occidental Petroleum,57,
33,Shari,Ballard,Best Buy,51,
34,Debra,Crew,"Reynolds American, British American Tobacco",46,
35,Kathleen,Murphy,Fidelity Investments,54,
36,Lynne,Doughtie,KPMG U.S.,54,
37,Mary,Mack,Wells Fargo,54,
38,Julie,Sweet,Accenture,49,
39,Carolyn,Tastad,Procter & Gamble,56,
40,Bridget,Van Kralingen,IBM,54,
41,Crystal,Hanlon,Home Depot,52,
42,Shira,Goodman,Staples,56,
43,Jennifer,Taubert,Johnson & Johnson,54,
44,Anna,Manning,Reinsurance Group of America,59,
45,Michele,Buck,Hershey,56,
46,Deanna,Mulligan,Guardian Life Insurance,54,
47,Bonnie,Hammer,Comcast,67,
48,Mary,Dillon,Ulta Beauty,56,
49,Margo,Georgiadis,Mattel,53,
50,Anne,Finucane,Bank of America,65,
51,Reese,Witherspoon,,41,

Explanation / Answer

Please go through the below solutions. If you face any issue then raise a query. :)

package com.businesswomen;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.Arrays;

public class Top50Women {

public static void main(String[] args) {

BufferedReader bufferReader= null;

try {

int count = 1;

//Reading the file placed under source folder

InputStream ins = Top50Women.class.getClassLoader().getResourceAsStream("./Top50.txt");

bufferReader = new BufferedReader(new InputStreamReader(ins));

//creating object Class BusinessWoman and ArrayList

BusinessWoman businessWoman = null;

CustomArrayList myArrayList = new CustomArrayList();

String line;

//Traversing through file line by line and adding 50 businessWoman object to the custom array list.

while(null!=(line=bufferReader.readLine()) && count <=50){

count++;

String substring = line.substring(0, line.length()-1);

String [] splitArray = substring.split(",");

//setting BusinessWoman object

businessWoman = new BusinessWoman();

businessWoman.setId(splitArray[0]);

businessWoman.setFirstName(splitArray[1]);

businessWoman.setLastName(splitArray[2]);

businessWoman.setCompany(splitArray[3]);

businessWoman.setAge(splitArray[4]);

myArrayList.add(businessWoman);

}

for(int i =0; i<myArrayList.size();i++){

System.out.println(myArrayList.get(i));

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

/**

* This class is containing all the fields needed for BusinessWoman as mentioned in question.

*

*/

class BusinessWoman{

private String id;

private String firstName;

private String lastName;

private String company;

private String age;

/**

* @return the id

*/

public String getId() {

return id;

}

/**

* @param id the id to set

*/

public void setId(String id) {

this.id = id;

}

/**

* @return the firstName

*/

public String getFirstName() {

return firstName;

}

/**

* @param firstName the firstName to set

*/

public void setFirstName(String firstName) {

this.firstName = firstName;

}

/**

* @return the lastName

*/

public String getLastName() {

return lastName;

}

/**

* @param lastName the lastName to set

*/

public void setLastName(String lastName) {

this.lastName = lastName;

}

/**

* @return the company

*/

public String getCompany() {

return company;

}

/**

* @param company the company to set

*/

public void setCompany(String company) {

this.company = company;

}

/**

* @return the age

*/

public String getAge() {

return age;

}

/**

* @param age the age to set

*/

public void setAge(String age) {

this.age = age;

}

public String toString(){

return id+","+firstName+","+lastName+","+company+","+age;

}

}

/**

* This class is mimicking as an ArrayList. I have added all the methods(add, get, size) as mentioned in question.

*

*/

class CustomArrayList{

private static final int INITIAL_DEFAULT_CAPACITY = 10;

private int size = 0;

private Object objectElements[];

public CustomArrayList(){

objectElements = new Object[INITIAL_DEFAULT_CAPACITY];

}

/**

* This method is adding the object to the ArrayList and if the size exceeds its calling expand method internally to increase its size limit.

* @param object

*/

public void add(Object object){

if(size == objectElements.length){

expand();

}

objectElements[size++] = object;

}

/**

* This method is doubling the size of ArrayList and Copying all the elements in the new sized Array.

*/

private void expand() {

int newLength = objectElements.length*2;

objectElements = Arrays.copyOf(objectElements, newLength);

}

/**

* This method returns the current size of ArrayList

* @return

*/

public int size(){

return size;

}

/**

* This Method is used to get the element located at the passed index.

* @param index

* @return

*/

public Object get(int index){

if(index>=0 && index < size){

return objectElements[index];

}

else{

throw new ArrayIndexOutOfBoundsException();

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote