我的编译器一直指向这一行:
arr[i] = new specialDelivery(name,name2,weight,special);
和这个 :
arr[i] = new specialDelivery(name,name2,weight,special);
错误在标题中说明
public static void main ( String args [] )
{
int size = 0,distance;
double weight = 0.0;
String strinput,method,name,name2,special;
Parcel arr[] = new Parcel[size];
strinput = JOptionPane.showInputDialog ( " Enter number of parcel : " );
size = Integer.parseInt(strinput);
for (int i = 0; i<size; i++)
{
int j = 0, k = 0;
method = JOptionPane.showInputDialog ( "Method of delivery (normal/special): " );
if (method.equals("normal"))
{
name = JOptionPane.showInputDialog ( " Enter your name : " );
name2 = JOptionPane.showInputDialog ( " Enter name of receiver : " );
strinput = JOptionPane.showInputDialog(" Enter the weight of parcel " + j + " : " );
weight = Double.parseDouble(strinput);
strinput = JOptionPane.showInputDialog(" Enter the distance of delivery " + j + " (km) : " );
distance = Integer.parseInt(strinput);
j++;
arr[i] = new normalDelivery(name,name2,weight,distance);
}
if (method.equals("special"))
{
name = JOptionPane.showInputDialog ( " Enter your name : " );
name2 = JOptionPane.showInputDialog ( " Enter name of receiver : " );
special = JOptionPane.showInputDialog(" Enter the type of delivery(airplane/ship) :" );
strinput = JOptionPane.showInputDialog(" Enter the weight of parcel " + j + " : " );
weight = Double.parseDouble(strinput);
j++;
arr[i] = new specialDelivery(name,name2,weight,special);
}
}
}
}