1 Attachment(s)
Help with using pre-created objects and Vectors **First Post :)**
Hello, I am having difficulty with a question is an assinment. I have been fine with all the others but i'm having troble with a trivial issue. We need to build an order system based on the class diagram below.
Attachment 908
As the multiplicity of Customer and Item is 0..* I am aware that we need to use a vector to store the customer and item objects. I already had a method of doing this which I thought would work but after reviewing the lecture notes and some sample code I became confused.
This is the code provided by my tutor..
CLASS OrderSystem
Code :
public class OrderSystem {
private Customer m_customer;
public OrderSystem() {
m_customer = new Customer(this);//create a customer and pass it a reference to this order system
m_customer.SendOrderSystemAMessage();//send a message to the new customer
}
public void printMessage(String msg) {
System.out.println(msg);
}
}
Class Customer
Code :
public class Customer {
private OrderSystem m_orderSystem;
public Customer() {//default constructor
// not much use as it would create a customer that has no link to the order system
}
public Customer(OrderSystem os) {//constructor with a reference to the calling object
m_orderSystem = os;//this is now a link to the object that created this customer
}
public void SendOrderSystemAMessage()
{
m_orderSystem.printMessage("message from your new customer");
}
}
I believe this code is to show us how a customer object is linked to an OrderSystem object. However when i use similar code using a vector i get errors. Can anybody help me please, i've been looking at this for hours now and I seem to be getting more confused.
Thanks a lot to everyone in advance.
MY OrderClass
Code :
public class OrderSystem {
private Vector<Customer> m_customers;
public OrderSystem() {
m_customers = new Vector<Customer>();
m_customers.SendOrderSystemAMessage();
}
public void printMessage(String msg) {
System.out.println(msg); //send a message to the new customer
}
public void addCustomer(String custID,String name,String address,int creditRating) {
}
}
Re: Help with using pre-created objects and Vectors **First Post :)**
Please copy and paste here the full text of the error messages.