Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 65
  1. #41
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  2. #42
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    Java Code:
    public class LineSegment
     {
     	private double x1;
    	private double x2;
    	private double y1;
    	private double y2;
    	private double length;
    	private double MidPointX;
    	private double MidPointY;
     
    	public LineSegment( double dX1,double dY1,double dX2,double dY2 ){
    		x1 = dX1;
    		x2 = dX2;
    		y1 = dY1;
    		y2 = dY2;
    	}
    	
    	public void setx1(double dX1){
    		x1 = dX1;
    	}
    	public void setx2(double dX2){
    		x2 = dX2;
    	}
    	public void sety1(double dY1){
    		y1 = dY1;
    	}
    	public void sety2(double dY2){
    		y2 = dY2;
    	}
    	public double setlength(double newlength){
    		length = newlength;
    		newlength = Math.sqrt(Math.pow(x2+x1,2) + Math.pow(y2+y1,2));
    	}
    	public double setMidPointX(double newMidPointX){
    		MidPointX = newMidPointX;
    		newMidPointX = (x1+x2) / 2; 
    	} 
    	public double setMidPointY(double newMidPointY){
    		MidPointY = newMidPointY;
    		newMidPointY = (y1+y2) / 2;
    	}	
    	public double getx1(){
    		return x1;
    	}
    	public double getx2(){
    		return x2;
    	}
    	public double gety1(){
    		return y1;
    	}
    	public double gety2(){
    		return y2;
    	}	
    	public double getlength(){
    		return length;
    	}
    	public double getMidPointX(){
    		return MidPointX;
    	}
    	public double getMidPointY(){
    		return MidPointY;
    	}	
    	
     }
    look good??? it doesnt compile though

  3. #43
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by s_dawg101 View Post
    look good???
    Better

    it doesnt compile though
    Tells us little. How doesn't it compile? Which line is causing the error? What message are you seeing?

  4. #44
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    Java Code:
    LineSegment.java:36: missing return statement
    	}
    	^
    LineSegment.java:40: missing return statement
    	} 
    	^
    LineSegment.java:44: missing return statement
    	}	
    	^
    3 errors

  5. #45
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The error is telling you exactly what is wrong. The error messages are usually quite straightforward. It's telling you that you have a method that is supposed to return a result but that method is missing a .... ?

    and the line numbers are telling you where the problems are.

  6. #46
    Vio
    Vio is offline Member
    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    18
    Rep Power
    0

    Default

    You've got 3 setters, in which your method declaration has a double in it, so it expects that you return a value, but since it is a setter there should be nothing returned. So you need to change "double" in "void"(void= your method does not expect that it returns something).

  7. #47
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Yeah, I didn't look at the code too carefully. It looks as if he's trying to combine getters and setters in one method. I would posit that midPointX and midPointY shouldn't be fields or set at all, that they should be calculated results calculated on the fly in getters only.

  8. #48
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    ok it compiled. now how would i create a class to run this program????

  9. #49
    Vio
    Vio is offline Member
    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    18
    Rep Power
    0

    Default

    Look up "Main classes" and then in your main class you make a new instance of your LineSegment object (look up "creating an instance of an object")

    and then I should take a better look at this piece of code, you already changed double in void but like Fubarable said you're mixing setters and methods that calculate something which is wrong.

    Java Code:
    public double setlength(double newlength){
    		length = newlength;
    		newlength = Math.sqrt(Math.pow(x2+x1,2) + Math.pow(y2+y1,2));
    	}
    	public double setMidPointX(double newMidPointX){
    		MidPointX = newMidPointX;
    		newMidPointX = (x1+x2) / 2; 
    	} 
    	public double setMidPointY(double newMidPointY){
    		MidPointY = newMidPointY;
    		newMidPointY = (y1+y2) / 2;
    }

  10. #50
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    what do i need to correct????

  11. #51
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    
    public class LineSegmentDemo
     {
     	public static void main(String[] args)
    	{
    	
    	Scanner keyboard = new Scanner (System.in);
    	
    	double x1;
    	double x2;
    	double y1;
    	double y2;
    	
    	System.out.println("What is the first x-coordinate?     ");
    	x1 = keyboard.nextInt();
    	
    	System.out.println("What is the first y-coordinate?     ");
    	y1 = keyboard.nextInt();
    	
    	System.out.println("What is the second x-coordinate?    ");
    	x2 = keyboard.nextInt();
    	
    	System.out.println("What is the second y-coordinate?    ");
    	y2 = keyboard.nextInt();
    	
    	}
     }
    this is what i have so far. how would i incorporate what the user puts in for the x and y values to the midpoint and distance formula???

  12. #52
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    
    public class LineSegmentDemo
     {
     	public static void main(String[] args)
    	{
    	
    	Scanner keyboard = new Scanner (System.in);
    	
    	double x1;
    	double x2;
    	double y1;
    	double y2;
    	
    	LineSegment problem = new LineSegment();
    	
    	System.out.print("What is the first x-coordinate?     ");
    	x1 = keyboard.nextInt();
    	
    	System.out.print("What is the first y-coordinate?     ");
    	y1 = keyboard.nextInt();
    	
    	System.out.print("What is the second x-coordinate?    ");
    	x2 = keyboard.nextInt();
    	
    	System.out.print("What is the second y-coordinate?    ");
    	y2 = keyboard.nextInt();
    	
    	System.out.print("The length of the line segment is: "  + problem.getlength());
    	
    	System.out.print("The mid-point of the line segment is: (" + problem.getMidPointX() + "," + problem.getMidPointY());
    	}
     }
    ok this is what i have for the demo class. it doesnt compile because there is one error.
    Java Code:
    symbol  : constructor LineSegment()
    location: class LineSegment
    	LineSegment problem = new LineSegment();
    	                      ^
    1 error
    what does this mean? how do i correct it??

  13. #53
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The rest of the error message tells you more, doesn't it? It tells you exactly what the problem is, I believe. Post it please.

  14. #54
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    thats all the error says

    i copied it exactly

  15. #55
    Vio
    Vio is offline Member
    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    18
    Rep Power
    0

    Default

    Take a look at your LineSegment class and it's constructor, your constructor demands a few things.

  16. #56
    pellebye is offline Member
    Join Date
    Apr 2009
    Posts
    54
    Rep Power
    0

    Default

    Why have you taken away the constructor you made in your post #4

    Java Code:
    public LineSegment( double dX1, double dY1
    double dX2, double dY2 ){
    x1 = dX1;
    x2 = dX2;
    y1 = dY1;
    y2 = dY2;
    }
    -
    Life is not the worst thing we have ... in a few minutes my coffee is ready.

  17. #57
    Vio
    Vio is offline Member
    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by pellebye View Post
    Why have you taken away the constructor you made in your post #4

    Java Code:
    public LineSegment( double dX1, double dY1
    double dX2, double dY2 ){
    x1 = dX1;
    x2 = dX2;
    y1 = dY1;
    y2 = dY2;
    }
    He didn't?

  18. #58
    pellebye is offline Member
    Join Date
    Apr 2009
    Posts
    54
    Rep Power
    0

    Default

    Ok, I just look at post #52 and cannot see no constructor.
    -
    Life is not the worst thing we have ... in a few minutes my coffee is ready.

  19. #59
    Vio
    Vio is offline Member
    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by pellebye View Post
    Ok, I just look at post #52 and cannot see no constructor.
    That's his main class.

  20. #60
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Child-Class Calling a Method in a Parent-Class
    By Blah_ in forum New To Java
    Replies: 5
    Last Post: 09-29-2009, 03:48 AM
  2. Replies: 7
    Last Post: 05-06-2009, 01:42 PM
  3. Replies: 8
    Last Post: 03-21-2009, 10:34 AM
  4. Replies: 0
    Last Post: 05-13-2008, 07:16 AM
  5. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 09:12 PM

Tags for this Thread

Posting Permissions

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