I am trying to create program that shows 2 outputs to the screen.
The first one being null and the 2nd one, shows values from the input file that was stored in an array of objects.
Here is my code so far:
javax.swing.JOptionPane;
import java.util.Scanner;
import java.io.File;
public class Testing {
public static void main(String[] args) {
//error checking for commandline input
if(args.length != 1){
System.out.println("Please enter at least one input file into the argument.");
//terminates the program if more than 1 is entered
System.exit(1);
}
//make an array of bird objects
final Integer SIZE = 9;
HawaiiNativeForestBirds array[] = new HawaiiNativeForestBirds[SIZE];
//output array of Nature objects to the screen (should be "null" for all elements)
System.out.println("Hawai'i Native Forest Birds ");
System.out.println("index element ");
for (int i = 0; i < SIZE; i++) {
System.out.println(" " + i + " " + array[i] );
System.out.println();
//read from file and store data from file in your Nature array of objects
//by initializing each array element using the constructor
File file = new File(args[0]);
Scanner inputFromFile = null;
array[0] = new HawaiiNativeForestBirds("'akiapola'au"," hemignathus munroi"," yellow", 800);
array[1] = new HawaiiNativeForestBirds("akepa"," loxxops coccineus"," red", 9301);
array[2] = new HawaiiNativeForestBirds("hawai'i creeper"," oreomystis mana"," yellow green", 2501);
array[3] = new HawaiiNativeForestBirds("i'iwi"," vestiara conccinea"," red green", 2501);
array[4] = new HawaiiNativeForestBirds("apapane"," himatione sanguinea"," white red", 5001);
array[5] = new HawaiiNativeForestBirds("hawai'ian amakihi"," hemignathus virens"," yellow brown", 3001);
array[6] = new HawaiiNativeForestBirds("hawaii'an hawk"," buteo solitarius"," white gray", 1100);
array[7] = new HawaiiNativeForestBirds("puaiohi"," myadestes palmeri"," brown", 125);
array[8] = new HawaiiNativeForestBirds("anianiau"," magumma parva"," light yellow", 2000);
//use toString() to display the array again with data from input file
System.out.println("index name Scientific Name Color Population");
for(int x=0;x<SIZE;x++){
System.out.println(" " + i + " " + array[i]);
}
}//end of main() method
}// end of class LastnameFirstname08
/**
* Class HawaiianTheme stores and displays the data for each HawaiianTheme object
*
*
*/
class HawaiiNativeForestBirds {
// data fields that store each object's data
private String name;
private String scientificname;
private String color;
private Integer population;
//constructor - used to initialize the three data fields
/**
* Stores the name,scientific name, color and population of the Hawaiian Birds
* This is a Constructor, which is used to Create EAch Object & Initialize DAta Fields.
*
* @param
* @param
* @param
* @param
*/
public HawaiiNativeForestBirds(String birdName, String scientificName,String birdColor, Integer birdPopulation) {
name = birdName;
scientificname = scientificName;
color = birdColor;
population = birdPopulation;
}//end of constructor
//toString() method - returns a String with the 4 data fields
public String toString() {
String output = name +" "+ scientificname + " "+ color +" "+ population;
return output;
}//end of toString()
}//end of class HawaiianTheme
The only thing missing now is the method that reads from file and stores the array of objects by initializing the arrays.
I'm still no good at combining both of these and as you can see from the code, I don't have the method yet nor I know how the format would look like to combined both.
edit 2: I finally fixed my output . I initiliazed stuff, now how to read from file and store to the array? ;_; Output:
Hawai'i Native Forest Birds
index element
0 null
1 null
2 null
3 null
4 null
5 null
6 null
7 null
8 null
9 null
index name Scientific Name Color Population
0 'akiapola'au hemignathus munroi yellow 800
1 akepa loxxops coccineus red 9301
2 hawai'i creeper oreomystis mana yellow green 2501
3 i'iwi vestiara conccinea red green 2501
4 apapane himatione sanguinea white red 5001
5 hawai'ian amakihi hemignathus virens yellow brown 3001
6 oma'o myadester obscurus gray 17001
7 hawaii'an hawk buteo solitarius white gray 1100
8 puaiohi myadestes palmeri brown 125
9 anianiau magumma parva light yellow 2000
All I want is to show two outputs but I gotta read and store the array of objects for the 2nd output
1.Display HawaiiNativeForestBirds array array[] without initializing elements:
2.Display HawaiiNativeForestBirds array[] again but shows the array values from the file after initializing elements:
edit:
My CSV Content: