import javax.swing.JOptionPane;
public class ComputerTest
{
public void main(String args[])
{
String message = "";
Computer computerArray[] = new Computer[5];
String dataArray[][] = {{"Laptop", "Sony", "Detroit", "599.99", "3", "15"},
{"Desktop", "Dell", "Houston", "1150.00", "5", "Inspiron"},
{"Desktop", "HP", "Los Angeles", "925.00", "2", "Pavilion"},
{"Laptop", "HP", "Los Angeles", "699.99", "12", "17"},
{"Laptop", "Apple", "Cupertino", "1399.00", "7", "13"}};
for(int i = 0; i < computerArray.length; i++)
{
if(dataArray[i][0].equals("Laptop"))
computerArray[i] = new Laptop(new Brand(dataArray[i][1], dataArray[i][2]),
Double.parseDouble(dataArray[i]
[3]),Integer.parseInt(dataArray[i][4]), Integer.parseInt(dataArray[i]
[5]));
else if(dataArray[i][0].equals("Desktop"))
computerArray[i] = new Desktop(new Brand(dataArray[i][1], dataArray[i][2]),
Double.parseDouble(dataArray[i]
[3]),Integer.parseInt(dataArray[i][4]), dataArray[i][5]);
}
for(int i = 0; i < computerArray.length; i++)
{
if (computerArray != null)
computerArray[i].calculateCharge(computerArray[i].getQuantity());
if (computerArray[i].getClass().getName().equals("Laptop"))
message += String.format("Laptop %s %.2f %s inches \n",
computerArray[i].getBrand(), computerArray[i].getTotalCharge(),
computerArray[i].Laptop.getSize());
else if (computerArray[i].getClass().getName().equals("Desktop"))
message += String.format("Desktop %s %.2f %s \n",
computerArray[i].getBrand(), computerArray[i].getTotalCharge(),
computerArray[i].getCategory());
}
JOptionPane.showMessageDialog(null, message);
}
}