Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class BookTest
- {
- public static void main(String args[])
- {
- //declare stuff
- String data_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};
- String msg = "";
- Book [] book_array;
- book_array = buildInstances(data_array);
- msg = createCharges(quantity_array, book_array);
- JOptionpane.showInternalMessageDialog(null, msg);
- }
- public static Book[] buildInstances(String data_array[][])
- {
- Book book_array[] = new Book [data_array.length];
- for (int i = 0; i<data_array.length; i++)
- {
- 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]));
- }
- return book_array;
- }
- public static String createCharges(int quantity[], String book_array[])
- {
- double totalCharge = 0;
- double gtotal = 0;
- String msg = "";
- for (int i = 0; i<book_array.length; i++ )
- {
- totalCharge = book_array[i].calculateCharges(quantity[i]);
- gtotal += totalCharge;
- //add string msg += like hw1
- msg += String.format("%s %s $%,.2f\n", book_array[i].getTitle(), book_array[i].getIsbn(), totalCharge);
- //format gtotal
- }
- msg += String.format("$%.2f", gtotal);
- return msg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement