我无法利用我的实例数据创建基于插槽索引的相应数组。在这种情况下,“太阳能”或“气候”将确定要创建的阵列。 我只需要main和createWarehouses方法的帮助。 任何帮助将不胜感激。
import javax.swing.JOptionPane;
public class WarehouseTest
{
public static void main(String args[])
{
SolarWarehouse sw1 = new SolarWarehouse ( "2200", "10", "5", "5", "First Street", "Dallas", "Texas", "76000", "Solar", "25");
ClimateControlledWarehouse ccw1 = new ClimateControlled Warehouse ( "5550", "12.75", "2", "3", "Mitchell Drive", "Arlington", "Texas", "76019", "Climate", "80.5");
ClimateControlledWarehouse ccw2 = new ClimateControlled Warehouse ("12000", "17.50", "6", "7", "Jones Blvd", "Burleson", "Texas", "76120", "Climate", "77.3");
SolarWarehouse sw2 = new SolarWarehouse ("7235", "22.35", "54", "80", "Smith Circle", "Keller", "Texas", "75020", "Solar", "6");
Warehouse wArray[] = new Warehouse[4];
wArray[0] = sw1;
wArray[1] = ccw1;
wArray[2] = ccw2;
wArray[3] = sw2;
wArray = createWarehouses(dataArray);
JOptionPane.showMessageDialog(null, purchaseItems(wArray));
JOptionPane.showMessageDialog(null, printWarehouses(wArray));
JOptionPane.showMessageDialog(null, printWarehouseCharge(wArray));
}
public static Warehouse[] createWarehouses( String a[][])
{
Warehouse w[] = new Warehouse[a.length];
for( int i=0; i<a.length; i++)
{
if(a[i][8].equals("Solar"))
w[i] = new SolarWarehouse(Double.parseInt(a[i][0]),
Double.parseDouble(a[i][1],
Integer.parseInt(a[i][2]),
Integer.parseInt(a[i][3]),
new Address(a[i][4]),
(a[i][5]),
(a[i][6]),
(Integer.parseInt(a[i][7]),
(a[i][8]), Integer.parseInt(a[i][9])));
else
w[i] = new ClimateControlledWarehouse(Double.parseInt(a[i][0]),
Double.parseDouble(a[i][1],
Integer.parseInt(a[i][2]),
Integer.parseInt(a[i][3]),
new Address(a[i][4]),
(a[i][5]),
(a[i][6]),
(Integer.parseInt(a[i][7]),
(a[i][8]), Integer.parseInt(a[i][9])));
}
return w;
}
public static String purchaseItems(Warehouse w[])
{
Sring msg = "";
String data[][] = {{ "Dallas", "1", "2"},
{ "Arlington", "0", "5"},
{ "Burleson", "3", "0"},
{ "Keller", "10", "25"},
{ "Dallas", "5", "0"},
{ "Arlington", "0", "1"},
{ "Burleson", "2", "4"},
{ "Keller", "0", "30"},
};
for( int i=0; i<data.length;i++)
{
for( int j=0; j<w.length; j++)
{
if (w[j].getAddress().getCity.equals(data[i][0]))
{
String msg += String.format("$%,.2f\n", (w[j].purchaseTelevision(Integer.parseInt(data[i][1]), 599.0) + w[j].purchaseComputer(Integer.parseInt(data[i][2]), 759.0)));
}
}
}
return msg;
}
public static String printWarehouses(Warehouse w[])
{
String msg = "";
for(int i=0; i<w.length;i++)
{
msg += String.format("%s\n", w[i].toString());
}
return msg;
}
public static String printWarehouseCharge(Warehouse w[])
{
String msg = "";
for(int i=0; i<w.length; i++)
{
msg += String.format("$%,.2f\n", w[i].calculateWarehouseCharge());
}
return msg;
}
} // end class WarehouseTest