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

Thread: association help !!

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

    Default association help !!

    whats wrong with my code ???


    at book class is
    protected Company publisher;               declare as global variable
       public Company getPublisher() {
        return publisher;
      }
      public void setPublisher(Company publisher) {
        this.publisher=publisher;
      }
     
     
    at Company class is 
     
    public final class Company {
      private String street;
      private String city;
      private String state;
      private String zip;
     
      /** Create an address with street, city, state, and zip */
      public Company(String street, String city,
        String state, String zip) {
        this.street = street;
        this.city = city;
        this.state = state;
        this.zip = zip;
      }
     
      /** Return street */
      public String getStreet() {
        return street;
      }
     
      /** Return city */
      public String getCity() {
        return city;
      }
     
      /** Return state */
      public String getState() {
        return state;
      }
     
      /** Return zip */
      public String getZip() {
        return zip;
      }
     
     
      public void setStreet(String street) {
        	this.street=street;
        }
     
       public void setCity(String city) {
        	this.city=city;
        }
        public void setState(String state) {
        	this.state=state;
        }
        public void setZip(String zip) {
        	this.zip=zip;
        }
     
      /** Get full address */
      public String getFullPublisher() {
        return street + '\n' + city + ", " + state + ' ' + zip + '\n';
      }
    }
     
     
    at testing class is 
     
    System.out.print("Enter publisher address: ");
    System.out.print("street > ");
    item[i].publisher.setStreet(scan.next());
     
    System.out.print("city > ");
    item[i].publisher.setCity(scan.next());
     
    System.out.print("state > ");
    item[i].publisher.setState(scan.next());
     
    System.out.print("zip > ");
    item[i].publisher.setZip(scan.next());


    It compile show me not error but i canno prompt the input of stree from user .


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,657
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: association help !!

    whats wrong with my code
    One problem is that it is NOT wrapped in code tags making it hard to read.

    i canno prompt the input of stree from user
    Please copy and paste here the full contents of the console from when you execute the program.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.


    Add some printlns to your code to print out the values of ALL the data you read in from the user.

  3. #3
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: association help !!

    Quote Originally Posted by jove View Post
    whats wrong with my code ???
    Hard to tell, since you haven't posted it all.

    ...i canno prompt the input of stree from user .
    Where is the code that sets up the user input ?