Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class BookTest
  4. {
  5.     public static void main(String args[])
  6.     {
  7.     //declare stuff
  8.         String data_array[][] = {{"Abraham Lincoln Vampire Hunter", "Grahame-Smith", "Wiley","978-04465 63079", "13.99"},
  9. {"Frankenstein", "Shelley", "Prescott", "978-0486282114", "7.99"},
  10. {"Life of Kennedy", "Jones", "Pearson", "758-29304566", "12.90"},
  11. {"Dracula", "Stoker", "Addison", "978-0486411095", "5.99"},
  12. {"Curse of the Wolfman", "Hageman", "Wesley", "B00381AKHG", "10.59"},
  13. {"How to Pass Java", "Willis", "Wiley", "444-395869790", "1.99"},
  14.     {"The Mummy", "Rice", "Addision", "978-0345369949", "7.99"},
  15.     {"History of Texas", "Smith", "Prescott", "123-683947687", "9.75"}};
  16.         int quantity[] = {12, 8, 3, 53, 7, 23, 14, 5};
  17.  
  18.         String msg = "";
  19.         Book [] book_array;
  20.  
  21.         book_array = buildInstances(data_array);
  22.         msg = createCharges(quantity_array, book_array);
  23.         JOptionpane.showInternalMessageDialog(null, msg);
  24.     }  
  25.  
  26.  
  27.  
  28.    
  29.  
  30.     public static Book[] buildInstances(String data_array[][])
  31.     {
  32.         Book book_array[] = new Book [data_array.length];
  33.  
  34.         for (int i = 0; i<data_array.length; i++)
  35.     {
  36.         book_array[i] = new Book (data_array[i][0], data_array[i][1],data_array[i][2],data_array[i][3] , Double.parseDouble(data_array[i][4]));
  37.     }
  38.         return book_array;
  39.     }
  40.  
  41.    
  42.     public static String createCharges(int quantity[], String book_array[])
  43.     {
  44.         double totalCharge = 0;
  45.         double gtotal = 0;
  46.         String msg = "";
  47.         for (int i = 0; i<book_array.length; i++ )
  48.         {
  49.             totalCharge = book_array[i].calculateCharges(quantity[i]);
  50.             gtotal += totalCharge;
  51.             //add string msg += like hw1
  52.             msg += String.format("%s %s $%,.2f\n", book_array[i].getTitle(), book_array[i].getIsbn(), totalCharge);
  53.             //format gtotal
  54.  
  55.         }
  56.         msg += String.format("$%.2f", gtotal);
  57.  
  58.         return msg;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement