hi, i was given this project to do in my java class but i dont exactly know what i have to do.... i understand that i need to create 2 classes, point that extends pair and labeledpoint that extends point.... but i have no idea what else the professor wants and he's not answering emails.... i was hoping someone could enlighten me.... heres the website:

http://pegasus.rutgers.edu/~randall/102/proj3.pdf

thanks in advance!

Alex

look at the three points given for the class Point, they tell you what each method should do, and so you have to figure out the code for each method, taking in mind the class Pair.

that goes also with the class LabeledPoint, the comment next to each line tells you how to implement the class.

make sure you know concepts of inheritance, it is the most important part here.

well....

I'm pretty sure you're not the only person to having received this task, maybe your fellow students could have given you some tips.

here's one from my part: stop waiting for the last day to make your assignments, especially those about a subject you're not very good at.

the task is not real hard, and you'll be (without a doubt) able to complete this before tomorrow. all you need to know is in the task description, or can at least be derived from it

the project actually isn't due until thursday... believe me, I've learned my lesson about leaving things till last minute.... ill try and do it today when I get home from school. thanks

the project actually isn't due until thursday...

the date was on the assignment, according to that, it's due tomorrow :), well, have fun anyway

thanks for the heads up.... he mentioned in class that all projects are due thursdays.... he must have moved it up

ok so ive tried to figure this out for 2 hours now and ive developed a headache... i just don't understand... i make 2 classes, point that extends pair and labeledpoint that extends point.... in point i made it invoke the constructor by using public Point(){super(Pair);}.... i dont quite understand what the tostring method does... nor do i understand the difference between the pair and point.... then in the point subclass i'm supposed 2 write a command to get the distance from the origin and a SECOND command to get the distance from the current point to p... so i used

double d= point.distance(origin);
{
    return d;
}

when i compile the main it tells me

Main.java:7: cannot find symbol
symbol  : method distance()
location: class Point
System.out.println(point.distance());

i'm going nuts here.... can someone please help me out??? thanks

Edited 3 Years Ago by mike_2000_17: Fixed formatting

this is the link to the project assignment http://pegasus.rutgers.edu/~randall/102/proj3.pdf ..... im pretty lost on this one.... this is what i have

public class Main{
    public static void main(String[] args){
        Pair pair=new Pair(1,2);
        System.out.println(pair);
        Point point=new Point(3,4);
        System.out.println(point);
        System.out.println(point.distance());
        Point point2=new Point(-3,5);
        System.out.println(point2);
        System.out.println(point2.distance());
        System.out.println(point.distance(point2));
        System.out.println(point2.distance(point));
        Point origin=new LabeledPoint("Origin",new Point(0,0));
        System.out.println(origin);
        Point p2=new LabeledPoint("Point 2",point2);
        System.out.println(p2);
        System.out.println(p2.distance());
    }
}


public class Pair{
protected int x, y;
Pair(int xx, int yy)
    {
        x=xx;
        y=yy;
    }
public String toString(){
return "Pair["+x+","+y+"]";
}
}


public class Point extends Pair
{

public Point(){super(Pair);}
Point origin= new Point(0,0);

double d= point.distance(origin);
{
    return d;
}
Point(int xx, int yy)
    {
        x=xx;
        y=yy;
    }
}

on the labeledpoint class i dont even know where to start... i just copied what the professor told us to implement:

public class LabeledPoint extends Point
{

protected String label; // New instance variable 
    (String s, Point p) // set label to s 
    String toString()

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

if anyone could give me a specific outline of where to begin and what to do exactly i would greatly appreciate it... thanks in advance!

Well the first thing you should do is put all of the functions that your professor requires in the code. Have them return nonsense values, but put them in. This will cut down on the number of errors to a more manageable level.

Second, you need to format your code. Every time you have a starting bracket, indent the code inside that bracket a few spaces. When the ending bracket comes, stop indenting. That way everything lines up and is pleasing to the eye and you can spot what code goes with what quickly. You are much more likely to spot things quickly and more likely to get help from other people that way.

Third, use code tage. Like this:

[code=JAVA] // your code here

[/code]
Again, makes it easier for us to follow and we can point out line numbers.

in the point class, im supposed to invoke the constructor from the pair class.... how do i do this correctly? i did it like this but i'm sure its wrong:

public Point()
    {
        super(Pair);
    }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

ok so my point class now goes like this but it still doesn't work..... basically he gives u the class pair, the test file main, the output, and we have to write 2 subclasses... i cant make it work together... pleaseeeee help!!!

public class Point extends Pair
{
    super(xx,yy);

    double distance()
    {
        return Math.sqrt(x^2 + y^2);
    }
    double distance(Point p)
    {
        return Math.sqrt((x-p.x)^2+(y-p.y)^2);
    }
    public String toString()
    {
        return "Point["+x+","+y+"]";

    }
}

public class Main
{
    public static void main(String[] args)
    {
        Pair pair=new Pair(1,2);
        System.out.println(pair);
        Point point=new Point(3,4);
        System.out.println(point);
        System.out.println(point.distance());
        Point point2=new Point(-3,5);
        System.out.println(point2);
        System.out.println(point2.distance());
        System.out.println(point.distance(point2));
        System.out.println(point2.distance(point));
        Point origin=new LabeledPoint("Origin",new Point(0,0));
        System.out.println(origin);
        Point p2=new LabeledPoint("Point 2",point2);
        System.out.println(p2);
        System.out.println(p2.distance());
    }
}


public class Pair
{
    protected int x, y;
        Pair(int xx, int yy)
        {
            x=xx;
            y=yy;
        }
    public String toString()
        {
            return "Pair["+x+","+y+"]";

        }
}


public class LabeledPoint extends Point
{
    protected String label;
    int s;
    int p;


    LabeledPoint(String s, Point p); 
    String toString();

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Use code tags please...

[code=JAVA] //paste your code here

[/code]

yields this after running through beautifier:
http://www.prettyprinter.de/

public class Point extends Pair
{
    super(xx,yy);
    double distance()
    {
        return Math.sqrt(x^2 + y^2);
    }
    double distance(Point p)
    {
        return Math.sqrt((x-p.x)^2+(y-p.y)^2);
    }
    public String toString()
    {
        return "Point["+x+","+y+"]";
    }
}
public class Main
{
    public static void main(String[] args)
    {
        Pair pair=new Pair(1,2);
        System.out.println(pair);
        Point point=new Point(3,4);
        System.out.println(point);
        System.out.println(point.distance());
        Point point2=new Point(-3,5);
        System.out.println(point2);
        System.out.println(point2.distance());
        System.out.println(point.distance(point2));
        System.out.println(point2.distance(point));
        Point origin=new LabeledPoint("Origin",new Point(0,0));
        System.out.println(origin);
        Point p2=new LabeledPoint("Point 2",point2);
        System.out.println(p2);
        System.out.println(p2.distance());
    }
}
public class Pair
{
    protected int x, y;
    Pair(int xx, int yy)
    {
        x=xx;
        y=yy;
    }
    public String toString()
    {
        return "Pair["+x+","+y+"]";
    }
}
public class LabeledPoint extends Point
{
    protected String label;
    int s;
    int p;
    LabeledPoint(String s, Point p);
    String toString();
}

Anything in particular giving you problems? What are the error messages?

the labeledpoint class is the one I have to debug but, I took out the part that uses it from the main file and ran it to see what it would do.... turns out instead of giving me the square root of the point (3,4) its giving me the square root of the pair (1,2)

Is this all in one file or are there several? Seems to me like you need a separate file for each public class. Beyond that, lines 56 and 57 are illegal.

LabeledPoint(String s, Point p);
String toString();

Are these functions? If so, where are the function bodies? Your last post suggests you got this to compile and run, but I don't see how it could.

if you go into the main file and remove everything from "point origin=new LabeledPoint("Origin", new Point(0,0));" on, it doesnt call LabeledPoint.class for anything, so it just compiles the rest of it using the subclass point.java... it's supposed to return the squareroot of the point (3,5) but instead it returns the square root of the pair(1,2).... if you look on the first post of this thread, there's the website where the project is listed... i don't know what to do with the LabeledPoint class and the whole program isn't working in general... that's what i meant by when i compiled it. if anyone could look at the site and give me some feedback on what do do, i'd greatly appreciate it... ive gotten some vague explanations but i need something more in depth as i am just a beginner. thanks!!

For one thing, this

public class Point extends Pair
{
    super(xx,yy);

is not a valid constructor. Re-examine your class notes on basic class structure.

i have changed it to:

public class Point extends Pair
{
Point(int xx,yy)
{
super(xx,yy);
}

We're not being vague, you are. What you are posting in your code is not what is reflected in the assignment and apparently is not what you compiled, yet you don't mention that, and your code makes it appear that it's all in one file. You also should repost the link to the assignment in the current post so we don't have to scroll back. Also, you are not using code tags.

What it looks like to me is that your professor wants you to have a separate file for each class. The name of the file should be the name of the class name followed by ".java".

I'll repeat, these lines within your LabeledPoint class are illegal:

LabeledPoint(String s, Point p);
String toString();

Make them like this:

LabeledPoint (String s, Point p)
{
// implementation code
}

public String toString ()
{
     return "";
}

These functions do nothing, but they'll compile. I'll repeat, get all the functions set up first so they can compile and can be called, and have a program that runs successfully even if it does nothing, then worry about stuff like whether the functions do the right things. Right now your programs are not going to compile.

Post your revised code with an explanation of what you've done and what you haven't, etc., and whether it compiles and the error messages, etc., and I'll be happy to help.

This article has been dead for over six months. Start a new discussion instead.