Thread for Programming and Realeted Topics

¤--bACarDi--¤

Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    Hey Guys check out this code !!!! get two points and return the line !! checked for all occurrences !!!! Please tell me if there are any errors !!!!!!

    Code:
    package line;
    import java.util.Scanner;
    
    /**
     *
     * @author lakmal
     */
     class Line {
         Points p1=new Points();
         Points p2=new Points();
         static boolean isContinue=true;
         static Scanner input=new Scanner(System.in);
         static  String op;
    
        
    
         void getLine(Points p1,Points p2){
             System.out.println("Your two points are ");
             System.out.println("("+p1.xCordinate+","+p1.yCordinate+")");
             System.out.println("("+p2.xCordinate+","+p2.yCordinate+")");
             double yCoeff=p2.xCordinate-p1.xCordinate;
             double xCoeff=p2.yCordinate-p1.yCordinate;
             double constant=p1.yCordinate*(p2.xCordinate-p1.xCordinate)-p1.xCordinate*(p2.yCordinate-p1.yCordinate);
             System.out.println("Your Line is:");
             if (yCoeff==0){
                 System.out.println("X="+p2.xCordinate);
             }
             else if (xCoeff==0)
                 System.out.println("Y="+p2.yCordinate);
             else{
             if (constant!=0){
             if ((constant/yCoeff)>0){
                  op = "+";
             }
             else if ((constant/yCoeff)<0){
                    op="";
             }
    
             System.out.println("Y="+xCoeff/yCoeff+"X" + op + (constant)/yCoeff);
         }
             else
                 System.out.println("Y="+ xCoeff/yCoeff+"X");
         }
         }
    
    
         void getPoints(){
             System.out.println("Enter your First Point:");
             System.out.print("X=");
    
             this.p1.xCordinate=input.nextInt();
             System.out.print("Y=");
             this.p1.yCordinate=input.nextInt();
    
             System.out.println("Enter your Second Point:");
             System.out.print("X=");
             this.p2.xCordinate=input.nextInt();
             System.out.print("Y=");
             this.p2.yCordinate=input.nextInt();
             this.getLine(this.p1,this.p2);
         }
    
    
         public static void main(String[] args) {
             do {
    
             Line l1=new Line();
             l1.getPoints();
             
             System.out.println("Do you want to Continuw with anothe line:(y/n)");
             char state=input.next().charAt(0);
             if (state=='n')
                 isContinue=false;
    
             } while (isContinue=true);
    
        }
    }
    
    class Points {
          int xCordinate;
          int yCordinate;
    
    }

    Happy Codings !!!!! For More Java And C++ codes Visit

    http://www.elakiri.com/forum/showthread.php?t=245895


    :baffled::baffled: Can you bit explain whatz this coding ?? I mean what its doing ?? :)
     

    ¤--bACarDi--¤

    Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    Hmm Machan did u have JAVA installed in your PC ....then i suggest you to run this and see!!!!!

    Actually this is a simple code for get two points as input and to output the line which goes across that two points !!!!!

    Try and see !!!!

    seems java not working in here now. Really today im back to java after 3 months i guess :nerd::eek:
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    I'm currently developing(nearly done :P) a C++ program that draws lines on DOS Console :P Crazy idea huh! it does draw correctly now but i thought of optimizing it a bit, I'll post it tomorrow

    Try to code it! :D and hey give some screenshots(I dont know how to run java codes, just tried running the code lakmal gave for line equation but it gave some errors :S)
     

    ¤--bACarDi--¤

    Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    I'm currently developing(nearly done :P) a C++ program that draws lines on DOS Console :P Crazy idea huh! it does draw correctly now but i thought of optimizing it a bit, I'll post it tomorrow

    Try to code it! :D and hey give some screenshots(I dont know how to run java codes, just tried running the code lakmal gave for line equation but it gave some errors :S)


    lines No idea ban ??:confused: Can you give a Screenshot ??
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    90574888.jpg
    lines No idea ban ??:confused: Can you give a Screenshot ??
     

    rclakmal

    Active member
  • May 8, 2008
    698
    183
    43
    In a galaxy far far away
    I'm currently developing(nearly done :P) a C++ program that draws lines on DOS Console :P Crazy idea huh! it does draw correctly now but i thought of optimizing it a bit, I'll post it tomorrow

    Try to code it! :D and hey give some screenshots(I dont know how to run java codes, just tried running the code lakmal gave for line equation but it gave some errors :S)

    Elaz Go on with ur code !!:D

    Actually I run java programmes through Netbeans !!!! but if u haven't installed it on ur PC its all right u can still run this on Command Prompt.

    Step 1

    Copy the above code to a note pad file and save it on desktop(or a place where u like ) But you have to give the correct path when you Compile the code !!! I think U have installed JDK on ur PC and u have to set path ( i think u know how to do that ) and type javac on command prompt .If CMD identifies the comamnd then u have insatlled jdk succesfully .

    Improtantly delete the line "package line;" from ur code ( It is used in Netbeans)

    63101744.jpg


    then go to command prompt and go the palce where u saved file (i saved it in desktop) and type javac Line.java

    then it will compile and in the next line type java Line

    28016126.jpg


    You r done!!!!!!!!!
     

    crashzone

    Well-known member
  • Jun 6, 2008
    2,945
    175
    63
    Can any one help me to create a download manager using VB.net.I want options like download direct links Giving from a text.also need some codes for disconnect a dial up connection.If the link redirect to mirror it also can be download .Plz help.
     

    v7soft

    Member
    Aug 23, 2008
    618
    54
    0
    i dnt knw C++ or java this is C
    /*sum of the 1-n odd’s using for loop */
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i=1, tot=0,test;
    printf(“enter the number \n”);
    scanf(“%d”,&num);

    for (i=1;i<=num;i++)
    {
    test=i%2;
    if(test!=0)
    {
    tot+=i;
    printf(“odd number is%d \n”,i);

    }
    }
    printf(“TOT OF 1 to %d odd’s is %d \n”,num,tot);
    getch();
    }
     

    crashzone

    Well-known member
  • Jun 6, 2008
    2,945
    175
    63
    Can any one help me to create a download manager using VB.net.I want options like download direct links Giving from a text.also need some codes for disconnect a dial up connection.If the link redirect to mirror it also can be download .Plz help.
     

    rclakmal

    Active member
  • May 8, 2008
    698
    183
    43
    In a galaxy far far away
    i dnt knw C++ or java this is C
    /*sum of the 1-n odd’s using for loop */
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i=1, tot=0,test;
    printf(“enter the number \n”);
    scanf(“%d”,&num);

    for (i=1;i<=num;i++)
    {
    test=i%2;
    if(test!=0)
    {
    tot+=i;
    printf(“odd number is%d \n”,i);

    }
    }
    printf(“TOT OF 1 to %d odd’s is %d \n”,num,tot);
    getch();
    }

    Good work !! then why dont u try and post solutions for above problems in C !!!!!!! :D Cmon !!!!
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Can any one help me to create a download manager using VB.net.I want options like download direct links Giving from a text.also need some codes for disconnect a dial up connection.If the link redirect to mirror it also can be download .Plz help.

    I dont know VB.NET but you can use pscode.com
    for examples if you want. I recommend API calls to wininet.dll to get things done.