-
June 25th, 2014, 03:35 AM
#1
How to make three arrays relate to each other
Hi guys,
I have written a program which reads an input file and store the values in three arrays(a string and two double arrays).
The class who do the task is given below:
Code:
package Assignments;
import java.util.Arrays;
import java.util.Scanner;
public class Unit {
static double[] fatContent;
static double[] protienContent;
static String[] nameOfElements;
Unit(int numberOfElements){
fatContent=new double[numberOfElements];
protienContent=new double[numberOfElements];
nameOfElements=new String[numberOfElements];
}
static void start(String in,int counter){
Scanner storingElements=new Scanner(in);
double fat;
double protien;
String name;
while(!storingElements.hasNext()){
storingElements.nextLine();
}
name=storingElements.next();
fat=storingElements.nextDouble();
protien=storingElements.nextDouble();
fatContent[counter]=fat;
protienContent[counter]=protien;
nameOfElements[counter]=name;
}
}
One of the input file I am reading is:
Code:
7
25
2
Mammal fat_content(%) protein_content(%)
Bison 7.9 5.9
Guinea_pig 3.9 8.1
Dolphin 14.0 10.4
Donkey 1.4 1.7
Goat 4.1 3.4
Deer 19.7 9.2
Dog 8.3 9.5
Yak 6.7 5.3
Camel 3.4 3.5
Cat 10.9 11.1
Rabbit 13.1 7.1
Llama 3.2 3.9
Human 43.9 7.4
Mule 1.8 2.0
Elephant 5.0 4.0
Horse 1.3 2.1
Rat 12.6 12.3
Reindeer 20.3 10.4
Sheep 6.4 5.6
Pig 5.1 6.6
Fox 5.9 7.4
Whale 42.3 10.9
Polar_bear 31.0 10.2
Zebra 4.8 3.0
Seal 53.2 11.2
and when I run this class from my main program it gives me output of:
Code:
[Bison, Guinea_pig, Dolphin, Donkey, Goat, Deer, Dog, Yak, Camel, Cat, Rabbit, Llama, Human, Mule, Elephant, Horse, Rat, Reindeer, Sheep, Pig, Fox, Whale, Polar_bear, Zebra, Seal]
[7.9, 3.9, 14.0, 1.4, 4.1, 19.7, 8.3, 6.7, 3.4, 10.9, 13.1, 3.2, 43.9, 1.8, 5.0, 1.3, 12.6, 20.3, 6.4, 5.1, 5.9, 42.3, 31.0, 4.8, 53.2]
[5.9, 8.1, 10.4, 1.7, 3.4, 9.2, 9.5, 5.3, 3.5, 11.1, 7.1, 3.9, 7.4, 2.0, 4.0, 2.1, 12.3, 10.4, 5.6, 6.6, 7.4, 10.9, 10.2, 3.0, 11.2]
But my problem is that I want a connection between them like if I find the maximum value of fat array then it also gives me the corresponding value of protein and mammal name that belongs to it.
I mean how can I make them relate to each other....
like (Bison 7.9 5.9) at one place.
Thanks in advance and any ideas or help would be highly appreciated.....
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|