Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package data;
- import model.Customer;
- public class Data {
- private Customer[] customers;
- public Data() {
- customers = new Customer[100];
- }
- /*
- * Adds a new customer to the system
- */
- public Customer addCustomer(String name, int bravoId, int phone,
- String email, String notes) {
- int i = firstEmpty();
- Customer cust = new Customer(name, bravoId, phone, email, notes);
- if (i > -1) {
- customers[i] = cust;
- }
- return cust;
- }
- public Customer getCustomerById(int bravoId) {
- Customer cust = null;
- for (int i = 0; i < 100; i++) {
- if (customers[i] != null && customers[i].getBravoId() == bravoId) {
- cust = customers[i];
- }
- }
- return cust;
- }
- /*
- * Returns the first empty cell in the array if there is one, -1 otherwise
- */
- private int firstEmpty() {
- int i = 0;
- while (i < 100) {
- if (customers[i] == null)
- return i;
- i++;
- }
- return -1;
- }
- /*
- * We pretend this reads from a database
- */
- public void readFromDatabase() {
- customers[1] = new Customer("TDC", 1, 26598654, "Tdc@tdc.dk",
- "TDC har mange kunder");
- customers[2] = new Customer("ISIS", 2, 85649632, "ISIS@ISIS.dk",
- "ISIS vil flyve pƄ 1. klasse alle sammen");
- customers[3] = new Customer("Java", 3, 85415355, "Java@Java.dk",
- "2 handikappede");
- customers[4] = new Customer("Maersk", 4, 85632598, "Maersk@Maersk.dk",
- "Vinterferie");
- }
- public void deleteAction(int i) {
- customers[i] = null;
- }
- // public TextField readCustomerInfo() {
- // for (int i = 0; i <= 100; i++) {
- // customers[i].getName();
- // }
- // return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement