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

Thread: Array typ objekt class

  1. #1
    Junior Member
    Join Date
    Jun 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array typ objekt class

    My excample:
    First class:
    public class Customer {
    int amount;
    }


    Second class:
    public class Invoice {

    Customer [] amount_one = {};

    int amount_all() {
    int total = 0;
    for (int i = 0; i <= amount_one.length; i++) {
    total = total+amount_one[i] // Don't work!
    }
    return null; // Don't work!

    }
    }

    What is the correct code?

    Can you show me a working example?

  2. #2
    Junior Member
    Join Date
    Jun 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array typ object class

    First class:

    public class Customer {
    int amount;

    public int getAmount() {
    return amount;
    }

    public void setAmount(int amount) {
    this.amount = amount;
    }
    }

    Second class:
    public class Invoice {

    Customer [] amount_one = {};

    int amount_all() {
    int total = 0;
    for (int i = 0; i <= amount_one.length; i++) {
    total = total+amount_one[i] // Don't work!
    }
    return null; // Don't work!

    }
    }

    Can you show me a working example?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Array typ object class

    Please explain what you are asking about.
    What is the posted code supposed to do?
    If there are any error messages copy the full text and paste it here.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jun 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array typ objekt class

    The copy is a mistake. I edited the code and saved. This made the code twice. How can I delete a code?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Array typ objekt class

    What problems are you having with the code?
    Are there error messages?
    Please copy the full text of any error messages and paste it here.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jun 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array typ objekt class

    Thank you for your answer. I think, I have a solution for my Problem.

Similar Threads

  1. Replies: 2
    Last Post: January 14th, 2013, 03:22 PM
  2. [SOLVED] Storing instances of a Sub Class in it's Super Class (Which is an array)
    By Hiroto in forum Object Oriented Programming
    Replies: 5
    Last Post: November 6th, 2011, 10:36 AM
  3. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  4. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM