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

This is java home / study / engineering / computer science / computer science qu

ID: 3587829 • Letter: T

Question

This is java

home / study / engineering / computer science / computer science questions and answers / in this program, you are going to read in a top 50 women in business data set file, top50.txt. ...

Question: In this program, you are going to read in a top 50 women in business data set file, Top50.txt. Yo...

Edit 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

Hi,

Following program does below steps :

1. Read file top50.txt

2. Copy data into array of length 10

3. When it exceeds 10, it expands array

4. Finally, prints all the data

Source Code:

package com.women;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Arrays;

public class BusinessWoman {

Integer id,age;

String fname, lname, company;

static BusinessWoman[] arr,arr2;

static int size=0;

static int counter=0;

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public Integer getAge() {

return age;

}

public void setAge(Integer age) {

this.age = age;

}

public String getFname() {

return fname;

}

public void setFname(String fname) {

this.fname = fname;

}

public String getLname() {

return lname;

}

public void setLname(String lname) {

this.lname = lname;

}

public String getCompany() {

return company;

}

public void setCompany(String company) {

this.company = company;

}

public static void main(String[] args) throws IOException,NullPointerException {

// TODO Auto-generated method stub

arr = new BusinessWoman[10];

BufferedReader br = new BufferedReader(new FileReader("top50.txt"));

try {

String line = br.readLine();

String[] seperate;

while (line != null && size <= 50) {

//sb.append(line);

//sb.append(System.lineSeparator());

line = br.readLine();

//to split string in line seperated by commas

seperate = line.split(",(?=(?:[^"]*"[^"]*")*[^"]*$)", -1);

if(line != null)

{

BusinessWoman bw=new BusinessWoman();

bw.setId(Integer.parseInt(seperate[0]));

bw.setFname(seperate[1]);

bw.setLname(seperate[2]);

bw.setCompany(seperate[3]);

bw.setAge(Integer.parseInt(seperate[4]));

if(size <=9 && counter == 0)

add(arr,bw);

else

{

arr2 = expand(arr,bw);

arr = arr2;

}

}

}

  

for(int i=0;i<51;i++)

System.err.println(arr[i].getId()+" "+arr[i].getFname()+" "+arr[i].getLname()+" "+arr[i].getCompany()+" "+arr[i].getAge());

  

} finally {

br.close();

}

}

public static void add(BusinessWoman[] a,BusinessWoman busi)

{

a[size] = busi;

size++;

}

public static BusinessWoman[] expand(BusinessWoman[] a,BusinessWoman busi)

{

counter+=10;

BusinessWoman[] newArray = new BusinessWoman[a.length + counter];

for(int j=0;j<a.length;j++)

{

newArray[j] = a[j];

}

a = newArray;

a[size]=busi;

size++;

  

return newArray;

}

Note: Please add top50.txt into your project folder :)

}

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