Advertisement
Guest User

data

a guest
Dec 18th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package data;
  2.  
  3. import model.Customer;
  4.  
  5. public class Data {
  6. private Customer[] customers;
  7.  
  8. public Data() {
  9. customers = new Customer[100];
  10. }
  11.  
  12. /*
  13. * Adds a new customer to the system
  14. */
  15. public Customer addCustomer(String name, int bravoId, int phone,
  16. String email, String notes) {
  17. int i = firstEmpty();
  18. Customer cust = new Customer(name, bravoId, phone, email, notes);
  19. if (i > -1) {
  20. customers[i] = cust;
  21. }
  22. return cust;
  23. }
  24.  
  25. public Customer getCustomerById(int bravoId) {
  26. Customer cust = null;
  27. for (int i = 0; i < 100; i++) {
  28. if (customers[i] != null && customers[i].getBravoId() == bravoId) {
  29. cust = customers[i];
  30. }
  31. }
  32. return cust;
  33. }
  34.  
  35.  
  36. /*
  37. * Returns the first empty cell in the array if there is one, -1 otherwise
  38. */
  39. private int firstEmpty() {
  40. int i = 0;
  41.  
  42. while (i < 100) {
  43. if (customers[i] == null)
  44. return i;
  45. i++;
  46. }
  47. return -1;
  48. }
  49.  
  50. /*
  51. * We pretend this reads from a database
  52. */
  53. public void readFromDatabase() {
  54. customers[1] = new Customer("TDC", 1, 26598654, "Tdc@tdc.dk",
  55. "TDC har mange kunder");
  56. customers[2] = new Customer("ISIS", 2, 85649632, "ISIS@ISIS.dk",
  57. "ISIS vil flyve pƄ 1. klasse alle sammen");
  58. customers[3] = new Customer("Java", 3, 85415355, "Java@Java.dk",
  59. "2 handikappede");
  60. customers[4] = new Customer("Maersk", 4, 85632598, "Maersk@Maersk.dk",
  61. "Vinterferie");
  62.  
  63. }
  64.  
  65. public void deleteAction(int i) {
  66. customers[i] = null;
  67. }
  68.  
  69. // public TextField readCustomerInfo() {
  70. // for (int i = 0; i <= 100; i++) {
  71. // customers[i].getName();
  72. // }
  73. // return
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement