Advertisement
abd9344

WarehouseTest

Nov 13th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class WarehouseTest
  4. {
  5.     public static void main( String args[] )
  6.     {
  7.         String dataArray[][] = {{ "2200", "10", "5", "5", "200", "First Street", "Dallas", "Texas", "76000" },
  8.                     { "5550", "12.75", "2", "3", "15", "Mitchell Drive", "Arlington", "Texas", "76019" },
  9.                     { "12000", "17.5", "6", "7", "0", "Jones Blvd", "Burleson", "Texas", "76120" },
  10.                     { "7235", "22.35", "54", "80", "30", "Smith Circle", "Keller", "Texas", "75020" }};
  11.  
  12.         Warehouse[] wArray = new Warehouse[dataArray.length];
  13.         wArray = createWarehouses( dataArray );
  14.  
  15.         JOptionPane.showMessageDialog( null, purchaseItems( wArray ));
  16.         JOptionPane.showMessageDialog( null, printWarehouses( wArray ));
  17.         JOptionPane.showMessageDialog( null, printWarehouseCharge( wArray ));
  18.     }
  19.  
  20.     public static Warehouse[] createWarehouses( String dataArray )
  21.     {
  22.         Warehouse w[] = new Warehouse[dataArray.length];
  23.  
  24.         for( int i = 0; i < w.length; i++ )
  25.         {
  26.             w[i] = new Warehouse( Double.parseDouble(dataArray[i][0]), Double.parseDouble(dataArray[i][1]),
  27.             Integer.parseInt(dataArray[i][2]), Integer.parseInt(dataArray[i][3]), Integer.parseInt(dataArray[i][4]),
  28.             new Address( dataArray[i][5], dataArray[i][6], dataArray[i][7], Integer.parseInt( dataArray[i][8] )));
  29.         }  
  30.         return w; //    <--- THIS IS PROBLEM
  31.     }
  32.  
  33.     public static String printWarehouses( Warehouse w[] )
  34.     {
  35.         String printMsg = String.format("");        
  36.  
  37.         for( int i = 1; i < w.length; i++ )
  38.         {
  39.             printMsg += String.format(
  40.             "Square Foot Size %.2f Price Per Square Foot %s Televisions %d Computers %d Tablets %d %s",
  41.             Double.parseDouble( w[i][0] ), Double.parseDouble( w[i][1] ),
  42.             Int.parseInt( w[i][2] ), Int.parseInt( w[i][3] ), Int.parseInt( w[i][4] ),
  43.             w[i][5].toString );      
  44.         }              
  45.         return printMsg;
  46.     }
  47.  
  48.     public static String printWarehouseCharge( Warehouse w[] )
  49.     {
  50.         String chgMsg = String.format("");      
  51.  
  52.         for( int i = 1; i < w.length; i++ )
  53.         {
  54.             chgMsg += String.format( "$%,.2f\n", w[i].calculateWarehouseCharge() + w[i].calculateTax() );
  55.         }
  56.         return chgMsg;
  57.     }
  58.  
  59.     public static String purchaseItems( Warehouse w[] )
  60.     {
  61.         String p[][] =
  62.                 {
  63.                     {"Dallas", "1", "2", "5"},
  64.                     {"Arlington", "0", "0", "15"},
  65.                     {"Burleson", "0", "0", "3"},
  66.                     {"Keller", "10", "25", "0"},
  67.                     {"Dallas", "5", "0", "0"},
  68.                     {"Arlington", "0", "1", "0"},
  69.                     {"Burleson", "2", "4", "0"},
  70.                     {"Keller", "0", "30", "3"}
  71.                 };
  72.  
  73.         String msg = String.format("");
  74.  
  75.         for ( int i = 0; i < w.length; i++ )
  76.         {
  77.             if ( w[i].getAddress().getCity().equals( p[i][0] ))
  78.             {
  79.                 msg += String.format("%,.2f\n", w[i].purchaseTelevision( 599, Integer.parseInt( p[i][1] ))
  80.                     + w[i].purchaseComputer( 759, w[i].Integer.parseInt( p[i][2] ))
  81.                     + w[i].purchaseTablet( 239.99, w[i].Integer.parseInt( p[i][3] )));
  82.             }  
  83.     }
  84.     return msg;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement