function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Naresh Kumar Mohan ThirukkovaluruNaresh Kumar Mohan Thirukkovaluru 

i want to write a point class to find slope between two points. I tried but its not working properly.

ShashForceShashForce
Hi,

If you can post your code snippet, we might be able to determine whats not working.

Thanks,
Shashank
ShashForceShashForce
Hi Naresh,

Would you mind posting your code in a more readable format?

Thanks,
Shashank
Virendra ChouhanVirendra Chouhan
Hi Naresh !

Why you use getvalues and setValues !
i think you have parameterized constructor and it is enogh to assgin value to x1 and x2.
Virendra ChouhanVirendra Chouhan
public class PointNew{

    integer x1,y1; 
  
  public PointNew(integer x10,integer y10){
         system.debug('PC');
         x1=x10;
         y1=y10;
                } 
 
 public double slope(integer x2,integer y2){
         double sp;
         sp=(y2-y1)/(x2-x1);
          return sp;
     }  
 
  public decimal distance(integer x2,integer y2){
         decimal ds;
         ds = math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        return ds; 
    }   

   public void Display(){   
 system.debug('point is = ('+x1+','+y1+') '); 
    } }


Test Class---

@isTest
public class PointNewTest{   
  
public static testMethod void name(){ 
 
    PointNew pt = new PointNew(1,-4);  
      
      double slp = pt.slope(-4,2); 
      double ds = pt.distance(5,10);
      pt.display();
    
}

}

Virendra ChouhanVirendra Chouhan
You have to store x2 and y2's values in a variable and print them.
Naresh Kumar Mohan ThirukkovaluruNaresh Kumar Mohan Thirukkovaluru
@virendra chauhan.........my sir said dat ur code and mine both are wrong in oops perspective.

do u hav any idea abt dat
Virendra ChouhanVirendra Chouhan
Give me the senario.