Page 1 of 2 12 LastLast
Results 1 to 20 of 34
  1. #1
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Post how to storing arbitrary collection of variables

    im suppose to define a class that can store these variables and print them out. but the variables are in 3 different extended classes of a class, so i dont really know where to put this new class. thanks for your time :) oh and i am suppose to store in an array of course.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    Have you tried following the advice you gave someone else on another thread?
    Quote Originally Posted by HelpingIsCaring View Post
    u should google it, or yahoo it, or bing it, internet explorer it, or firefox it, or opera it.
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by DarrylBurke View Post
    Have you tried following the advice you gave someone else on another thread?

    db
    lol bro, calm down, i was kidding. really? did u have to serach me up and posts this? lol xD sorry bout that. seems like this sites got a lot of moderator police. come on as a morderator, calling people db isnt nice. if db stands for dumb bitch?
    Last edited by HelpingIsCaring; 07-23-2013 at 05:46 AM.

  4. #4
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    if i offended anyone, i apologize. if theres anything i can do to fix it, i will. plzz allow people to read/post stuff on this thread again! :)

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: how to storing arbitrary collection of variables

    If your program has an "arbitrary collection of variables", then you skipped the first step of writing an object oriented program, which is modeling. A proper model will allow you to access the fields of each subclass in a way that is appropriate to that subclass, using their common interface.
    Get in the habit of using standard Java naming conventions!

  6. #6
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    wow. pros are pros. this is actually the second part of a program that i am suppose to do. (how did u know!) i already have a class and 3 subclasses that extends the class. all four classes are in separated files, but they are in the same package. i probably need to put this new method by the the base class, using 1d array, and for loops. but i have never tried to put variables into arrays before. (cause i am a noob ^^ LIKE REALLY. NOT BEING POLITE OR ANYTHING) no idea how. if anyone could give me an example of how this works, it would be extremely helpful.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by HelpingIsCaring View Post
    lol bro, calm down, i was kidding. really? did u have to serach me up and posts this? lol xD sorry bout that. seems like this sites got a lot of moderator police. come on as a morderator, calling people db isnt nice. if db stands for dumb bitch?
    'db' stands for 'Darryl Burke'; that's his name; I'm very sure he didn't try to offend you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,686
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    This thread makes me cry. What will it take to open your eyes? A person who's nick is DarrylBurke has 'db' in his signature and you automatically assume that the guy is calling you a dumb bitch - really? Well then there can be only one possible truth: you believe with all your heart that you are one since to you there can be no possible alternative to the meaning behind those two simple letters, and so from now on you must be one.
    Last edited by gimbal2; 07-23-2013 at 10:11 AM. Reason: typo
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    I, for one, won't be able to read one of Darryl's posts in quite the same way anymore...

    As for the question, the use of the phrase "arbitrary collection of variables" implies you haven't modelled something correctly (as kjkrum says). And since we don't have a clue what your code is supposed to do, what it looks like, or anything of the sort, then that's as far as anyone can go for a decent answer.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by gimbal2 View Post
    This thread makes me cry. What will it take to open your eyes? A person who's nick is DarrylBurke has 'db' in his signature and you automatically assume that the guy is calling you a dumb bitch - really? Well then there can be only one possible truth: you believe with all your heart that you are one since to you there can be no possible alternative to the meaning behind those two simple letters, and so from now on you must be one.
    well, im sorry. at first glance, i didnt think it was his name, so i searched on urban dictionary what it was and it said was dumb bitch. lol the funny part is ur like literally calling me a dumb bitch right now. kinda ironic -_-

  11. #11
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    sorry bout the misunderstanding, should have known that. xD

  12. #12
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    THIS IS THE CODE I HAVE SO FAR FROM STEP ONE. It might look long, but its really easy bc i wrote it and i am a noob :)
    Java Code:
    public abstract class Shape {
    
        protected Point postion;
    
        //public void Move(int x, int y) {
            //postion.x = x;
            //postion.y = y;
        //}
        
        public void Show() {
            System.out.println("this is abstract shape");
        }
        
        public static void main(String[] args) {
            // TODO code application logic here
            Point pointA = new Point(5, 6);
            Point pointB = new Point(8, 10);
            Point center = new Point(0, 0);
            double radius = 8.0;
    
            Rectangle rectangle = new Rectangle();
            rectangle.Show();
            rectangle.SetA(pointA);
            rectangle.SetB(pointB);
            System.out.println(rectangle.toString());
    
    
            Circle circle = new Circle();
            circle.Show();
            circle.SetCenter(center);
            circle.SetRadius(radius);
            System.out.println(circle.toString());
    
            Line line = new Line();
            line.Show();
            line.SetA(pointA);
            line.SetB(pointB);
            System.out.println(line.toString());
        }
    }
    
    //different class
    public class Point {
    
        protected int x;
        protected int y;
    
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    //different class
    public class Line extends Shape {
    
        Point a;
        Point b;
    
        public Point GetA() {
            return a;
        }
    
        public void SetA(Point a) {
            this.a = a;
        }
    
        public Point GetB() {
            return b;
        }
    
        public void SetB(Point b) {
            this.b = b;
        }
    
       /* @Override
        public void Show() {
            System.out.println("this is a line");
        } */
    
        public String toString() {
            String toString = "Point a is" + "(" + a.x + "," + a.y + ")" + "Point b is" + "(" + b.x + "," + b.y + ")";
            return toString;
        }
    
        
    }
    
    //different class
    public class Circle extends Shape {
    
        Point center;
        double radius;
    
        public Point GetCenter() {
            return center;
        }
    
        public void SetCenter(Point center) {
            this.center = center;
        }
    
        public double GetRadius() {
            return radius;
        }
    
        public void SetRadius(double radius) {
            this.radius = radius;
        }
        
        @Override
        public void Show() {
            System.out.println("this is a circle");
        }
    
        public String toString() {
            String toString = "the center point is" + "(" + center.x + "," + center.y + ")" + "the radius is " + this.radius;
            return toString;
        }
    }
    
    //different class
    public class Rectangle extends Shape {
    
        Point a;
        Point b;
    
        public Point GetA() {
            return a;
        }
    
        public void SetA(Point a) {
            this.a = a;
        }
    
        public Point GetB() {
            return b;
        }
    
        public void SetB(Point b) {
            this.b = b;
        }
        
        @Override
        public void Show() {
            System.out.println("this is a rectangle");
        }
    
        public String toString() {
            String toString = "Point a is" + "(" + a.x + "," + a.y + ")" + "Point b is" + "(" + b.x + "," + b.y + ")";
            return toString;
        }
    }
    Last edited by HelpingIsCaring; 07-23-2013 at 09:05 PM.

  13. #13
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,383
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by Tolls View Post
    I, for one, won't be able to read one of Darryl's posts in quite the same way anymore...
    At least his name isn't something like "William T. Fitzgerald". ;)

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  14. #14
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,686
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    okay well when you have an actual question about that code, feel free to ask it.

    Note: you're not a noob but a novice; a programmer in training. I really hate the word "noob" with a passion because people hide behind it as an excuse to not have to think and to get away with unethical behavior. Please be better than that.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    ok. As a NOVICE i ask the people of this community to help answer this question. i have the code here and the question at the top. ill just restate the question in the exact words. "define a class, shapelist, that can store an arbitrart collection of any objects of subclasses of the shape class."

  16. #16
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,383
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    Fairly straight forward assignment. After looking at your code, I believe you are confusing a class which contains inner classes of those types, as opposed to a class that can contain objects of arbitrary subtypes of type Shape. The latter is much simpler and does not even require knowing the sub classes.

    Also, you mentioned Shape class. So is this your own class for construction? The reason I ask is that there is also a Shape interface as part of the JDK API. Are you required to implement that? Or are you permitted to just use various classes in the JDK that implement Shape as objects to be stored in your ShapeList class?

    Regards,
    Jim
    Last edited by jim829; 07-23-2013 at 09:14 PM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  17. #17
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    yes, this is my own class. and what u said about shape interface is covered later in the next problem. there are six parts to this problem. the thrid part is when i have to implement classes for shapes using interface insted of using inheritance from the superclass. for today i just wanna finish the second part b/c i have some things to do later. if ur solution also covers the third part of the set of problems, GReATT!!!!!!!

  18. #18
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,383
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    Well, here are some questions you need to ask yourself.


    1. What data structure or class(es) exist in Java which lets you store items?
    2. Does Java allow one to assign a subclass instance to its super class variable or field? That is if S extends T may I assign an instance of S to a type T variable or field?
    3. What methods would I need in my ShapeList class to add new Shapes and retrieve already stored ones?


    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  19. #19
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    well to answer those questions as a novice
    1) one dimensional arrays
    2) took me some time to think, but i think its yes. OH, i just read about this, its called casting. but i have never used it before.
    3)i am not sure YET.
    thank you Jim, these questions really made me start thinking. :)
    Last edited by HelpingIsCaring; 07-24-2013 at 12:00 AM.

  20. #20
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    Should i use this thing called a linked list?
    nevermind, im getting help in person. but thx for all ur help, and clearing up that db is the person's name and doesn't stand for anything foul. lol xD
    Last edited by HelpingIsCaring; 07-24-2013 at 01:33 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Classes with arbitrary data members
    By pifrely in forum New To Java
    Replies: 3
    Last Post: 01-26-2013, 09:31 PM
  2. Combo with arbitrary content
    By BadaBingNow in forum SWT / JFace
    Replies: 0
    Last Post: 03-08-2012, 04:09 PM
  3. Arbitrary number of objects, each with a unique name.
    By providence in forum New To Java
    Replies: 8
    Last Post: 02-23-2011, 01:12 AM
  4. gradients between two arbitrary colors
    By falkon114 in forum New To Java
    Replies: 4
    Last Post: 02-09-2011, 05:08 PM
  5. Creating an arbitrary number of variables
    By theodorekon in forum New To Java
    Replies: 1
    Last Post: 04-15-2010, 06:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •