This is java In this program, you are going to read in a post secondary educatio
ID: 3863788 • Letter: T
Question
This is java
In this program, you are going to read in a post secondary education data set file, Post Secondary Education.txt. You are going to create a Education object which keeps track of the SchoolID, Name of the School, the State Abbreviation their Web address.
You are going to store it into an array of Education 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.
Use the Post Secondary Education.txt file in Moodle.
Specifics:
1. Read in the education file and create Education 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.
Post Secondary Education.txt file
UNITID INSTNM STABBR WEBADDR
100654 Alabama A & M University AL www.aamu.edu/
100663 University of Alabama at Birmingham AL www.uab.edu
100690 Amridge University AL www.amridgeuniversity.edu
100706 University of Alabama in Huntsville AL www.uah.edu
100724 Alabama State University AL www.alasu.edu/email/index.aspx
100733 University of Alabama System Office AL www.uasystem.ua.edu
100751 The University of Alabama AL www.ua.edu/
100760 Central Alabama Community College AL www.cacc.edu
100812 Athens State University AL www.athens.edu
100830 Auburn University at Montgomery AL www.aum.edu
100858 Auburn University AL www.auburn.edu
100937 Birmingham Southern College AL www.bsc.edu/
101028 Chattahoochee Valley Community College AL www.cv.edu
101073 Concordia College Alabama AL www.ccal.edu/
101116 South University-Montgomery AL southuniversity.edu
101143 Enterprise State Community College AL www.escc.edu
101161 James H Faulkner State Community College AL www.faulknerstate.edu
101189 Faulkner University AL www.faulkner.edu
101240 Gadsden State Community College AL www.gadsdenstate.edu
101277 New Beginning College of Cosmetology AL www.nbccosmetology.com
101286 George C Wallace State Community College-Dothan AL www.wallace.edu
101295 George C Wallace State Community College-Hanceville AL www.wallacestate.edu
101301 George C Wallace State Community College-Selma AL www.wccs.edu
101365 Herzing University-Birmingham AL www.herzing.edu/birmingham
101435 Huntingdon College AL www.huntingdon.edu
101453 Heritage Christian University AL www.hcu.edu
101462 J F Drake State Community and Technical College AL www.drakestate.edu
101471 J F Ingram State Technical College AL www.istc.edu
101480 Jacksonville State University AL www.jsu.edu/
101499 Jefferson Davis Community College AL www.jdcc.edu
101505 Jefferson State Community College AL www.jeffstateonline.com
101514 John C Calhoun State Community College AL www.calhoun.edu
101541 Judson College AL www.judson.edu
101569 Lawson State Community College-Birmingham Campus AL www.lawsonstate.edu
101587 University of West Alabama AL www.uwa.edu
101602 Lurleen B Wallace Community College AL www.lbwcc.edu
Explanation / Answer
File to print it
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package calculator;
/**
*
* @author Lenovo
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ReadTxtFile {
public static void main(String[] args) {
try {
String folderPath = "C:/Users/Lenovo/Documents/NetBeansProjects/Calculator/src/calculator/";
/*Path path = Paths.get(folderPath, "Post Secondary Education.txt"); //or any text file eg.: txt, bat, etc
Charset charset = Charset.forName("UTF-8");*/
File file = new File(folderPath+"Post Secondary Education.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
ReadArrayList arrList = new ReadArrayList();
int counter = 0;
while ((line = bufferedReader.readLine()) != null) {
if(arrList.size() == counter){
arrList.arrSizeInc();
}
arrList.add(line,counter);
counter++;
}
fileReader.close();
System.out.println("Contents of file:");
String[][] eduArr = arrList.get();
for(int i = 0; i<eduArr.length; i++){
for(int j=0; j<eduArr[i].length; j++){
System.out.print(eduArr[i][j]+" ");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------File to create arrayList
package calculator;
import java.util.Arrays;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Lenovo
*/
public class ReadArrayList {
private String educationArr[][] = null;
ReadArrayList(){
this.educationArr = new String[10][4];
}
public int size(){
if(this.educationArr == null){
return 9999;
}else {
return this.educationArr.length;
}
}
public void arrSizeInc(){
this.educationArr = Arrays.copyOf(this.educationArr, this.educationArr.length + this.educationArr.length); //Extending for one
}
public void add(String line, int counter){
String[] words=line.split(" ");
int arrLength = words.length;
this.educationArr[counter] = new String[4];
if(arrLength == 4){
this.educationArr[counter][0] = words[0];
this.educationArr[counter][1] = words[1];
this.educationArr[counter][2] = words[2];
this.educationArr[counter][3] = words[3];
}else{
this.educationArr[counter][0] = words[0];
String s = "";
for(int i=1;i<words.length-2;i++){
s+=words[i];
if(i<words.length-3){
s+=" ";
}
}
this.educationArr[counter][1] = s;
this.educationArr[counter][2] = words[words.length-2];
this.educationArr[counter][3] = words[words.length-1];
}
}
public String[][] get(){
return this.educationArr;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.