Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Kevin Chavez
- import javax.swing.JOptionPane;
- public class BookTest
- {
- public static void main(String [] args)
- {
- String d_array[][] = {{"Abraham Lincoln Vampire Hunter", "Grahame-Smith", "Wiley", "978-04465 63079", "13.99"},
- {"Frankenstein", "Shelley", "Prescott", "978-0486282114", "7.99"},
- {"Life of Kennedy", "Jones", "Pearson", "758-29304566", "12.90"},
- {"Dracula", "Stoker", "Addison", "978-0486411095", "5.99"},
- {"Curse of the Wolfman", "Hageman", "Wesley", "B00381AKHG", "10.59"},
- {"How to Pass Java", "Willis", "Wiley", "444-395869790", "1.99"},
- {"The Mummy", "Rice", "Addision", "978-0345369949", "7.99"},
- {"History of Texas", "Smith", "Prescott", "123-683947687", "9.75"}};
- int quantity[] = {12,8,3,53,7,23,14,5};
- double total_charge;
- String message = "";
- Book [] book_array = new Book[8];
- book_array = buildInstances(d_array);
- message = createCharges(quantity, book_array);
- JOptionPane.showMessageDialog(null, message);
- }
- public static Book[] buildInstances(String d_array[][])
- {
- Book book_array[] = new Book[8];
- for(int i = 0; i < d_array.length; i++)
- {
- 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]));
- }
- return book_array;
- }
- public static String createCharges(int quantity[], Book book_array[])
- {
- double total_charge = 0;
- double grand_total = 0;
- String message = "";
- for(int i = 0; i < book_array.length; i++)
- {
- total_charge = book_array[i].calculate_charge(quantity[i]);
- grand_total += total_charge;
- message += String.format("%s, %s, $%,.2f\n", book_array[i].getTitle(),book_array[i].getIsbn(),total_charge);
- }
- message += String.format("Grand Total $%.2f", grand_total);
- return message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement