Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 What are 'objects as data records'?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CjGaughan




PostPosted: Thu Feb 16, 2006 10:07 am   Post subject: What are 'objects as data records'?

One of the 'mastery aspects' I need to complete for my IB Computer Science Dossier, and I was just wondering if I could get a little bit better explanation of what it is.

Thanks.
Sponsor
Sponsor
Sponsor
sponsor
turboliux




PostPosted: Thu Feb 16, 2006 10:13 am   Post subject: (No subject)

Quote:
Mastery aspects
Standard level
To achieve a mastery factor of 1.0, students must have mastered at least 10 of the following 15
aspects.
1. Arrays
2. User-defined objects
3. Objects as data records
4. Simple selection (if-else)
5. Complex selection (nested if, if with multiple conditions or switch)
6. Loops
7. Nested loops
8. User-defined methods
9. User-defined methods with parameters (the parameters have to be useful and used within the
method body)
10. User-defined methods with appropriate return values (primitives or objects)
11. Sorting
12. Searching
13. File i/o
14. Use of additional libraries (such as utilities and graphical libraries not included in appendix 2
Java Examination Tool Subsets)
15. Use of sentinels or flags

It is anticipated that this list will provide students with the option to choose algorithms and data
structures appropriate to the problem rather than contriving a solution to fit the mastery aspects.
Where one aspect includes others, all are credited, for example aspect 10 will also satisfy aspects 8
and 9 (always provided that the use is non-trivial, well-documented and appropriate).

ask which ones you dont understand, i will try to explain
Martin




PostPosted: Thu Feb 16, 2006 10:26 am   Post subject: (No subject)

I would assume that it would be referring to using an object to create a new data type.

For example, you might want to create a Point3d class to handle a point on a 3d space you could create the following data object:

code:
public class Point3d {
    private float x, y, z;
   
    public Point3d() {
        x = 0.0f;
        y = 0.0f;
        z = 0.0f;
    }
   
    public Point3d(float x,float y,float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
   
    public float getX() { return x;}
    public float getY() { return y;}
    public float getZ() { return z;}
   
    public void setX(float x) { this.x = x;}
    public void setY(float y) { this.y = y;}
    public void setZ(float z) { this.z = z;}
   
}


Then when you wanted to create an 3d point, you would just create something like Point3d point = new Point3d(1.0,2.0,3.1);

Cool?

And for stuff like this, C++'s operator overloading would be really nice...
wtd




PostPosted: Thu Feb 16, 2006 12:21 pm   Post subject: (No subject)

Martin wrote:
And for stuff like this, C++'s operator overloading would be really nice...


Being able to create properties would be even more useful in this case.

C#

code:
public class Point3D
{
   private float x, y, z;

   public Point3D(float x, float y, float z)
   {
      this.x = x;
      this.y = y;
      this.z = z;
   }

   public float X
   {
      get { return x; }
      set { this.x = value; }
   }

   public float Y
   {
      get { return y; }
      set { this.y = value; }
   }

   public float Z
   {
      get { return z; }
      set { this.z = value; }
   }
}
rizzix




PostPosted: Thu Feb 16, 2006 4:03 pm   Post subject: (No subject)

wtd wrote:
Being able to create properties would be even more useful in this case.
Maybe but Java relies more on the tools than language constructs. You can just fire up eclipse right click and generate the get/set methods.

A more ideal solution for such a case would be something like this:
Java:
[public] class Point3d {
    [public]  var x = 0;
    [private] var y = 0, z = 0;
   
    [constructor] newWithValues:(Float32 x, Float32 y, Float32 z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
   
    [public] {
        Float32 z:(Void) { @z*2 }
   
        Void setX:(Float32 x) { this.x = x}
        Void setY:(Float32 y) { this.y = y}
        Void setZ:(Float32 z) { this.z = z}
       
        [static] Void main:(String[] args) {
            Point3d p = Point3d.newWithValues:(1.0f, 2.0f, 3.0f);
           
            Float32 x;
           
            p.setX: 4.0f;
            x = p.x// 4.0f
           
            p.x = 9.0f;
            x = p.x// 9.0f
           
            Float32 z = p.z// 6.0f
           
           
            Float32 z2 = @p.z; // access variable, but since it's declared
                               // private, it would result in a
                               // compile time error. Otherwise it would have
                               // resulted in 3.0f
        }
    }
}


where the method hides the variable by default. Smile
turboliux




PostPosted: Thu Feb 16, 2006 6:20 pm   Post subject: (No subject)

oops, didn't read the title which was the question... Laughing
but anyways, "3. Objects as data records " means that you need to create a class and then one or more objects from that class which will hold some sort of data. It has to be non-trivial, so that class is not already in java library. once you came up with idea for your project, you will be able to write that class.
For example, lets say we are creating some sort of public library software which will help the librarian to check in/out books:
code:
import java.util.*;

class data {
        private int id;
        private String title;
        private String author;
        private String category;
        private boolean istaken;
        private Date published;
        private Date taken;
        private Date returned;
       
        public void setId (int id) {
                this.id = id;   
        }
       
        public int getId () {
                return id;     
        }
       
        public void setTitle (String title) {
                this.title = title;     
        }
       
        public String getTitle () {
                return title;   
        }
        //and more such (get, set) methods
}

so lets say in your this simple program is in console, and the user is asked to input data (I used IBIO class, you may have had experience with it before)
code:
class LibrarySoft {
        static int choice = 0;
        static boolean addmore = false;
        static IBIO io = new IBIO();    //this is JETS class, makes life eisier
        static Data dt1 = new Data();
        static Data dt2 = new Data();
        //some more variables here...
       
        public static void main (String args[]) {
               
                //blah blah
                //some statements here
                //and there...
               
                //some methods here...
               
                if (choice == 1) {
                        String str = io.inputString ("whats the title of the book? "); 
                       
                        //now here dt1 is first object which has a data record
                        dt1.setTitle(str);
                        str = io.inputString ("whats the author of the book? ");
                        dt1.setAuthor(str);
                        dt1.setCategory(io.inputString ("whats the category of the book? "));
                }
               
                //some more statements here
               
                if (addmore) {
                        str = io.inputString ("whats the title of the book? "); 
                       
                        //now here dt2 is second object which has a data record
                        dt2.setTitle(str);
                        dt2.setAuthor(io.inputString ("whats the author of the book? "));
                        dt2.setCategory(io.inputString ("whats the category of the book? "));
                }
        }
}

hope it was usefull.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: