Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. //Kevin Chavez
  2. import javax.swing.JOptionPane;
  3. public class BookTest
  4. {
  5.         public static void main(String [] args)
  6.         {
  7.  
  8.                 String d_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.  
  17.                 int quantity[] = {12,8,3,53,7,23,14,5};
  18.                 double total_charge;
  19.                 String message = "";
  20.                 Book [] book_array = new Book[8];
  21.  
  22.                 book_array = buildInstances(d_array);
  23.  
  24.                 message = createCharges(quantity, book_array);
  25.                 JOptionPane.showMessageDialog(null, message);
  26.         }
  27.  
  28.         public static Book[] buildInstances(String d_array[][])
  29.         {
  30.                 Book book_array[] = new Book[8];
  31.                 for(int i = 0; i < d_array.length; i++)
  32.                 {
  33.                         book_array[i] = new Book(d_array[i][0], d_array[i][1], d_array[i][2], d_array[i][3], Double.parseDouble(d_array[i][4]));
  34.                 }
  35.                 return book_array;
  36.         }
  37.  
  38.         public static String createCharges(int quantity[], Book book_array[])
  39.         {
  40.                 double total_charge = 0;
  41.                 double grand_total = 0;
  42.                 String message = "";
  43.                 for(int i = 0; i < book_array.length; i++)
  44.                 {
  45.                         total_charge = book_array[i].calculate_charge(quantity[i]);
  46.                         grand_total += total_charge;
  47.                         message += String.format("%s, %s, $%,.2f\n", book_array[i].getTitle(),book_array[i].getIsbn(),total_charge);
  48.                 }
  49.  
  50.                 message += String.format("Grand Total $%.2f", grand_total);
  51.  
  52.                 return message;
  53.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement