Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Slopes/ Equations of a Line extended Code

  1. #1
    Junior Member Eoing008's Avatar
    Join Date
    Dec 2012
    Location
    Dublin, Ireland
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Slopes/ Equations of a Line extended Code

    Hi, need some help with this one. All I was asked was to find out if the three points are on the same line. I think that works. But I decided to go a little farther and try getting the equations of the relevant lines. That is where I am going wrong. All that is written in the Eclipse ( my IDE) console is the slopes or what I think is the slopes! Can anyone help please? By the way, this is revision. But I am very rusty and have never been a "Ace" programmer. Something I am trying to fix. Thanks in advance for any help given.


    import java.util.*;
    public class SameStraightLine
    {
    	public static void main(String[] args)
    	{
    		Scanner input= new Scanner(System.in);
    		int x1,y1,x2,y2,x3,y3,m1,m2,m3,l1,l2,l3;
    		int x= 120;char X = (char)x;
    		int y=121; char Y= (char)y;
    		Boolean SameLine= true;
    		System.out.println("Please enter the x1 co-ordinate: ");
    		x1=input.nextInt();
     
    		System.out.println("Please enter the y1 co-ordinate: ");
    		y1=input.nextInt();
     
    		System.out.println("Please enter the x2 co-ordinate: ");
    		x2=input.nextInt();
     
    		System.out.println("Please enter the y2 co-ordinate: ");
    		y2=input.nextInt();	
     
    		System.out.println("Please enter the x3 co-ordinate: ");
    		x3=input.nextInt();
     
    		System.out.println("Please enter the y3 co-ordinate: ");
    		y3=input.nextInt();
     
    		m1=((y2-y1)/(x2-x1));
    		m2=((y3-y2)/(x3-x2));
    		m3=((y1-y3)/(x1-x3));
     
    		l1=(y-y1-(m1*(x-x1)));
    		l2=(y-y2-(m2*(x-x2)));
    		l3=(y-y3-(m3*(x-x3)));
     
    		System.out.println("The equation of the line l1 is: "+l1);
     
    		System.out.println("The equation of the line l2 is: "+l2);
     
    		System.out.println("The equation of the line l3 is: "+l3);
     
     
    		if (l1==l2 && l2==l3)
    		{
    			System.out.println("It is "+SameLine+" that they lie on the same line");
     
    		}
    		else
     
    		{
    			System.out.println("It is "+(!SameLine)+" that they lie on the same line");
     
    		}
    	}
    }
    Last edited by jps; December 6th, 2012 at 05:25 AM. Reason: fixed code tag


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Slopes/ Equations of a Line extended Code

    Can you post the program's output and explain what is wrong with it and show what it should be?
    Also provide all the input required to execute the program. A very easy way to do that is by putting a String in the Scanner class's constructor:
    Scanner input= new Scanner("1\n33\n5\n44\n4\n");

    Can you make a line of code like the above with all the test data for the program to make for easier testing and to be sure the correct data is entered.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Making Slopes for a Platformer Game
    By Gravity Games in forum Java Theory & Questions
    Replies: 4
    Last Post: November 8th, 2012, 07:22 PM
  2. How do i make two equations have to be equal?
    By jamesR in forum Java Theory & Questions
    Replies: 2
    Last Post: October 3rd, 2012, 12:10 AM
  3. have code - need one line fixed please!
    By ash12 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 7th, 2012, 07:24 PM
  4. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  5. Help with a line of my code.
    By Miical94 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 7th, 2011, 11:00 AM