Results 1 to 2 of 2
  1. #1
    judemartin99 is offline Member
    Join Date
    Feb 2013
    Rep Power

    Default Composition JAVA Programming HELP (Im new to java)

    I'm 16 yrs old and I just started programming as a hobby. In need help in how do to create an application that uses composition. I have a Point class which will maintain a point,that is, an x and y coordinate. Also I don't know how to create a Line class which will contain two Point data members. Line will have the logic to determine the equation of the line such as having methods to calculate the slope, y-intercept, and display the final equation.

    The application itself will use the Point and Line classes. The application should have minimal logic such as only creating objects and calling methods.

    Point Class:

    Java Code:
    public class Point {
        public int x;
        public int y;
        public Point(){
            x =0;
        public Point(int xpoint, int ypoint){
            x = xpoint;
            y = ypoint;
        public void setPoint(int xpoint, int ypoint){
            x = xpoint;
            y = ypoint;
        public int getxpoint(){
            return x;
        public int getypoint(){
            return y;
    Line Class:
    Java Code:
    public class Line {

    Java Code:
    public class Composition {
        public static void main(String[] args) {

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Composition JAVA Programming HELP (Im new to java)

    Nice Hobby. Programming is lots of fun. Regarding your question, I am not certain what you mean by composition programming. There is a design pattern called the composite design pattern where instead of using inheritance, you use instances of a class and then provide public forwarding methods for those instances. So if you could provide some more info I might be able to offer some help.

    However, I can make one recommendation. Unless you really need them to be public, make your class fields private. After all, that is why you have getters and setters.

    Last edited by jim829; 03-29-2013 at 03:10 AM. Reason: Improved response
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 0
    Last Post: 12-31-2012, 03:24 PM
  2. android programming vs game programming using java
    By vgoel38 in forum Forum Lobby
    Replies: 2
    Last Post: 09-08-2012, 12:11 AM
  3. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  4. What is the Composition in Java
    By Santoshbk in forum Advanced Java
    Replies: 4
    Last Post: 04-10-2008, 11:04 AM

Posting Permissions

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