This seems to be a very simple problem, but I am not sure that I am using these constructors correctly. If you could take a look and tell me why when I try to print this data, it displays (what I assume to be) the data location. I can't think of a way to get it to print out the name, freezing point, boiling point, and number of units. Any suggestions on making this more efficient are welcome too.
This is the first class
public class ChemicalInventory {
public static void main(String[] args) {
listInventory();
}
public static void listInventory(){
Chemical Ethanol = new Chemical("Ethanol", "-173", "172", "1575");
Chemical Oxygen = new Chemical("Oxygen", "-363", "-306", "1000");
Chemical Water = new Chemical("Water", "32", "212", "5000");
Chemical Benzene = new Chemical("Benzene", "41.9", "176.2", "2750");
Chemical EthyleneGlycol = new Chemical("Ethylene Glycol", "8.78", "378", "1900");
System.out.println("Current Chemical Inventory: ");
System.out.println(Ethanol);
System.out.println(Oxygen);
System.out.println(Water);
System.out.println(Benzene);
System.out.println(EthyleneGlycol);
}
}
This is the Second class.
public class Chemical {
private String chemName;
private String chemFreezingPoint;
private String chemBoilingPoint;
private String chemUnitNumbers;
public Chemical(String name, String freezingPoint, String boilingPoint, String unitNumbers){
chemName = name;
chemFreezingPoint = freezingPoint;
chemBoilingPoint = boilingPoint;
chemUnitNumbers = unitNumbers;
}
//String[][] chemArray = new String [5][4];
String[][] chemArray = {{"Ethanol","-173","172","1575"},{"Oxygen","-363","-306","1000"},{"Water","32","212","5000"},
{"Benzene","41.9","176.2","2750"},{"Ethylene Glycol","8.78","378","1900"}};
}
This is what I get when I run the program:
Current Chemical Inventory:
Chemical@15db9742
Chemical@6d06d69c
Chemical@7852e922
Chemical@4e25154f
Chemical@70dea4e