Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help with using pre-created objects and Vectors **First Post :)**

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    class.jpg

    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
    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
    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

    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) {
     
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with using pre-created objects and Vectors **First Post :)**

    i get errors
    Please copy and paste here the full text of the error messages.

Similar Threads

  1. Replies: 3
    Last Post: November 25th, 2011, 02:02 PM
  2. Vectors and objects
    By Matty Alan in forum Java Theory & Questions
    Replies: 3
    Last Post: May 10th, 2011, 11:44 AM
  3. Autoboxing and unboxing for user created objects
    By tcstcs in forum Java Theory & Questions
    Replies: 3
    Last Post: March 22nd, 2011, 07:54 AM
  4. Vectors - accessing an unknown amount of objects
    By fox in forum Loops & Control Statements
    Replies: 1
    Last Post: May 7th, 2010, 03:54 PM
  5. Vectors
    By mgutierrez19 in forum Collections and Generics
    Replies: 4
    Last Post: March 3rd, 2010, 11:46 AM