0

I'm trying to simply create a class (a bank teller in this case) which has its own unique customer (to serve), task (to fulfill), and can be busy (1) or not busy (0). I've given each teller some initial values for these fields for testing purposes but have encountered a problem when printing their respective customers and tasks. I have designed these as objects, unlike the 'busy' value which is an int, and prints fine.

From my understanding I am receiving hashcode values rather than my desired values.

I have tried doing some research and have tried to implement a toString() class but this leads to the same results.

Here is the relevant code to my Main class:

// Create 'Customers' queue
Queue2<Customer> Customers = new Queue2<Customer>();

// Initializations of customers
Customer customer1 = new Customer(912, 6, 15);

// Add customers to queue
Customers.enqueue(customer1);

// Customer at teller 'i'
Customer C1 = new Customer(908, 3, 20);

// Denotes if teller 'i' is busy with a customer OR a task
int B1 = 1;

// Create 'Tasks' stack
Stack Tasks = new Stack();

// Initializiations of tasks
Task task1 = new Task(910, 12);
Task task2 = new Task(913, 3);

// Add tasks to stack
Tasks.push(task1);
Tasks.push(task2);

// Give tellers 1 and 2 an empty task to start
Task EmptyTaskT1 = new Task(0,0);
Task EmptyTaskT2 = new Task(0,0);

// Current task being worked on by teller 3
Task TaskCurr = new Task(916, 3);

// Initializations of Tellers
Teller tell1 = new Teller(C1, EmptyTaskT1, B1);

// Print Teller info
System.out.println(tell1);

// Printing just C1
System.out.println(C1);

Here is the relevant code to my (old) Teller class:

public class Teller {

    Object Customer;
    Object Task;
    int isBusy;

    public Teller(Customer Customer, Task Task, int isBusy) {
      this.Customer = Customer;
      this.Task = Task;
      this.isBusy = isBusy;
    }

    public Object getCustomer() {
      return Customer;
    }

    public int getTask() {
      return Task;
    }

    public int isBusy() {
      return isBusy;
    }

I have since then commented out the code underneath the Teller constructor method in favor of a toString method:

@Override
public String toString() {
    return "Teller [Customer=" + Customer + ", Task=" + Task + ", 
isBusy=" + isBusy + "]";
}

I am receiving the following console output in either case:

Teller [Customer=banksimulation.Customer@15db9742, Task=banksimulation.Task@6d06d69c, isBusy=1]

When I want to receive something such as:

Customer = (912, 6, 15), Task = (910, 12), isBusy=1

Any help would be greatly appreciated! Thanks a bunch.

gdagis
  • 113
  • 1
  • 4
  • 15

0 Answers0