import java.util.ArrayList;public class ArrayListTestProgram { public static void main(String args[]) { int total = 0; ArrayList numbers;
Fantastic news! We've Found the answer you've been seeking!
Question:
import java.util.ArrayList;public class ArrayListTestProgram { public static void main(String args[]) { int total = 0; ArrayList numbers; System.out.println("The ArrayList looks like this: " + numbers); System.out.println("It has " + numbers.size() + " elements in it"); System.out.println("The 5th element in it is: " + numbers.get(4)); }}
public class Customer { private String name; private int age; private float money; private int id; public Customer(String n, int a, float m) { name = n; age = a; money = m; id = -1; } public void setID(int newID){ id = newID; } public String toString() { return "Customer " + name + ": a " + age + " year old with $" + money; } public String getName() { return name; } public int getAge(){return age;} public boolean hasMoreMoneyThan(Customer c) { return money > c.money; }}
public class DVD implements Comparable { private String title; private int year; private int duration; public DVD () { this ("",0,0); } public DVD (String newTitle, int y, int minutes) { title = newTitle; year = y; duration = minutes; } public int compareTo(Object obj) { if (obj instanceof DVD) { DVD aDVD = (DVD)obj; return title.compareTo(aDVD.title); } return 0; } public String getTitle() { return title; } public int getDuration() { return duration; } public int getYear() { return year; } public void setTitle(String t) { title = t; } public void setDuration(int d) { duration = d; } public void setYear(int y) { year = y; } public String toString() { return ("DVD (" + year + "): "" + title + "" with length: " + duration + " minutes"); }}
public class Mall { public static final int MAX_STORES = 100; private String name; private Store[] stores; private int storeCount; public Mall(String n) { name = n; stores = new Store[MAX_STORES]; storeCount = 0; } public void addStore(Store s) { if (storeCount < MAX_STORES) { stores[storeCount++] = s; } } public int getUniqueCustomerCount(){ int total = 0; for (int i=0; ipublic class MallTestProgram { public static void main(String args[]) { Mall trainyards = new Mall("Trainyards"); Store walmart, dollarama, michaels, farmBoy; trainyards.addStore(walmart = new Store("Walmart")); trainyards.addStore(dollarama = new Store("Dollarama")); trainyards.addStore(michaels = new Store("Michaels")); trainyards.addStore(farmBoy = new Store("Farm Boy")); Customer c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14; Customer c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26; c1 = new Customer("Amie", 14, 100); c2 = new Customer("Brad", 15, 0); c3 = new Customer("Cory", 10, 100); c4 = new Customer("Dave", 5, 48); c5 = new Customer("Earl", 21, 500); c6 = new Customer("Flem", 18, 1); c7 = new Customer("Gary", 8, 20); c8 = new Customer("Hugh", 65, 30); c9 = new Customer("Iggy", 43, 74); c10 = new Customer("Joan", 55, 32); c11 = new Customer("Kyle", 16, 88); c12 = new Customer("Lore", 12, 1000); c13 = new Customer("Mary", 17, 6); c14 = new Customer("Nick", 13, 2); c15 = new Customer("Omar", 18, 24); c16 = new Customer("Patt", 24, 45); c17 = new Customer("Quin", 42, 355); c18 = new Customer("Ruth", 45, 119); c19 = new Customer("Snow", 74, 20); c20 = new Customer("Tamy", 88, 25); c21 = new Customer("Ulsa", 2, 75); c22 = new Customer("Vern", 9, 90); c23 = new Customer("Will", 11, 220); c24 = new Customer("Xeon", 17, 453); c25 = new Customer("Ying", 19, 76); c26 = new Customer("Zack", 22, 35); walmart.addCustomer(c1); walmart.addCustomer(c3); walmart.addCustomer(c4); walmart.addCustomer(c5); walmart.addCustomer(c8); walmart.addCustomer(c12); walmart.addCustomer(c13); walmart.addCustomer(c14); walmart.addCustomer(c17); walmart.addCustomer(c19); walmart.addCustomer(c25); dollarama.addCustomer(c2); dollarama.addCustomer(c3); dollarama.addCustomer(c5); dollarama.addCustomer(c6); dollarama.addCustomer(c13); dollarama.addCustomer(c16); dollarama.addCustomer(c18); dollarama.addCustomer(c19); dollarama.addCustomer(c20); michaels.addCustomer(c1); michaels.addCustomer(c2); michaels.addCustomer(c7); michaels.addCustomer(c9); michaels.addCustomer(c15); michaels.addCustomer(c18); michaels.addCustomer(c22); michaels.addCustomer(c23); michaels.addCustomer(c24); michaels.addCustomer(c26); farmBoy.addCustomer(c1); farmBoy.addCustomer(c2); farmBoy.addCustomer(c5); farmBoy.addCustomer(c10); farmBoy.addCustomer(c11); farmBoy.addCustomer(c19); farmBoy.addCustomer(c21); farmBoy.addCustomer(c24); farmBoy.addCustomer(c25); System.out.println("Did Amie and Xeon shop at the same store: " + trainyards.shoppedAtSameStore(c1, c24)); System.out.println("Did Brad and Nick shop at the same store: " + trainyards.shoppedAtSameStore(c2, c14)); System.out.println("The number of unique customers in the mall is: " + trainyards.getUniqueCustomerCount ()); }}import javafx.geometry.Insets;import javafx.scene.control.*;import javafx.scene.layout.GridPane;import javafx.stage.Stage;public class StatsDialog extends Dialog { public StatsDialog(Stage owner, DVDCollection c) { setTitle("DVD Statistics"); ButtonType okButtonType = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE); getDialogPane().getButtonTypes().addAll(okButtonType); GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(10, 10, 10, 10)); Label l1 = new Label("Total:"); Label l2 = new Label("Oldest:"); Label l3 = new Label("Newest:"); Label l4 = new Label("Shortest Duration:"); Label l5 = new Label("Longest Duration:"); Label l6 = new Label(""+c.getDvds().size()); Label l7 = new Label(""+c.oldestDVD()); Label l8 = new Label(""+c.newestDVD()); Label l9 = new Label(""+c.shortestDVD()); Label l10 = new Label(""+c.longestDVD()); l1.setStyle("-fx-font: 12 arial; -fx-text-fill: NAVY;"); l2.setStyle("-fx-font: 12 arial; -fx-text-fill: NAVY;"); l3.setStyle("-fx-font: 12 arial; -fx-text-fill: NAVY;"); l4.setStyle("-fx-font: 12 arial; -fx-text-fill: NAVY;"); l5.setStyle("-fx-font: 12 arial; -fx-text-fill: NAVY;"); grid.add(l1, 0, 0); grid.add(l2, 0, 1); grid.add(l3, 0, 2); grid.add(l4, 0, 3); grid.add(l5, 0, 4); grid.add(l6, 1, 0); grid.add(l7, 1, 1); grid.add(l8, 1, 2); grid.add(l9, 1, 3); grid.add(l10, 1, 4); getDialogPane().setContent(grid); }}public class Store { public static final int MAX_CUSTOMERS = 500; private static int LATEST_ID = 100000; private String name; private Customer[] customers; private int customerCount; public Store(String n) { name = n; customers = new Customer[MAX_CUSTOMERS]; customerCount = 0; } public Customer[] getCustomers() { return customers; } public int getCustomerCount() { return customerCount; } public void addCustomer(Customer c) { if (customerCount < MAX_CUSTOMERS) customers[customerCount++] = c; c .setID(LATEST_ID); LATEST_ID++; } public void listCustomers() { for (int i=0; ipublic class StoreTestProgram { public static void main(String args[]) { Customer[] result; Store walmart; walmart = new Store("Walmart off Innes"); walmart.addCustomer(new Customer("Amie", 14, 100)); walmart.addCustomer(new Customer("Brad", 15, 0)); walmart.addCustomer(new Customer("Cory", 10, 100)); walmart.addCustomer(new Customer("Dave", 5, 48)); walmart.addCustomer(new Customer("Earl", 21, 500)); walmart.addCustomer(new Customer("Flem", 18, 1)); walmart.addCustomer(new Customer("Gary", 8, 20)); walmart.addCustomer(new Customer("Hugh", 65, 30)); walmart.addCustomer(new Customer("Iggy", 43, 74)); walmart.addCustomer(new Customer("Joan", 55, 32)); walmart.addCustomer(new Customer("Kyle", 16, 88)); walmart.addCustomer(new Customer("Smaug", 12, 1000)); walmart.addCustomer(new Customer("Mary", 17, 6)); walmart.addCustomer(new Customer("Nick", 13, 2)); walmart.addCustomer(new Customer("Omar", 18, 24)); walmart.addCustomer(new Customer("Patt", 24, 45)); walmart.addCustomer(new Customer("Quin", 42, 355)); walmart.addCustomer(new Customer("Ruth", 45, 119)); walmart.addCustomer(new Customer("Snow", 74, 20)); walmart.addCustomer(new Customer("Tamy", 81, 25)); walmart.addCustomer(new Customer("Ulsa", 2, 75)); walmart.addCustomer(new Customer("Vern", 9, 90)); walmart.addCustomer(new Customer("Will", 9, 220)); walmart.addCustomer(new Customer("Xeon", 17, 453)); walmart.addCustomer(new Customer("Ying", 19, 76)); walmart.addCustomer(new Customer("Zack", 22, 35)); System.out.println("Here are the customers:"); walmart.listCustomers();System.out.println("Average age of customers: " + walmart.averageCustomerAge());System.out.println("Richest customer is: " + walmart.richestCustomer());System.out.println("Friends for 18 year old Omar:");result = walmart.friendsFor(walmart.getCustomers()[14]);for (Customer c: result) System.out.println(c);System.out.println("Friends for 14 year old Amie:");result = walmart.friendsFor(walmart.getCustomers()[0]);for (Customer c: result) System.out.println(c); }}
Related Book For
Java How To Program Early Objects
ISBN: 9780134743356
11th Edition
Authors: Paul Deitel, Harvey Deitel
Posted Date: