Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help!!! import java.util.ArrayList; public class ChallengeLine In this problem s

ID: 3838844 • Letter: H

Question

Help!!!

import java.util.ArrayList; public class ChallengeLine In this problem set you will create a class to represent lines defined by their slope and y-intercept Cy mx+b An understanding of linear geometry is assumed 2 points Q1: Set up this class to contain doubles m" (slope and "b" Cy-intercept) with getters/setters and a constructor to initialize these values 13 -Create private instance variables "m" and "b" as doubles -Write getter and setter methods for "m" and "b" following the standard naming convention Cie. getM, setB) 15 -Write a constructor that takes 2 doubles and sets the values of "m and "b". The first parameter should correspond to "m" and the second corresponds to "b 3 points Q2: Write a non-static method named evaluate that takes a double as a parameter and returns a double. The method returns the y value of the point on this line with the input parameter being the x value of the point 5 points 25 Q3: Write a non-static method named intersection that takes an instance of ChallengeLine as a parameter and returns an instance of the PointXY class Cprovided) at the intersection of the input line and this line 80 5 points static void Q4CArrayList

Explanation / Answer


import java.util.ArrayList;
public class ChallengeLine {
   double m;
   double b;
   static double y;
   static double x;
   ChallengeLine(double m,double b){
       setm(m);
       setb(b);
      
   }
   public void setm(double m)
   {
       this.m=m;
      
   }
   public void setb(double b){
       this.b=b;
   }
   public double getm(){
       return m;
   }
   public double getb(){
       return b;
   }
   public double evaluate(double x){
       this.x=x;
       this. y=0;
       y=m*x+b;
       return y;
      
   }
   public double intersection(ChallengeLine c){
       double point=c.y*c.x;
       return point;
      
   }

}


ChallengeLinemain.java


import java.util.*;
public class ChallengeLinemain {
static Map<Double,ChallengeLine>cmap=new HashMap<Double,ChallengeLine>();
static List<ChallengeLine>alist=new ArrayList<ChallengeLine>();
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       ChallengeLine ch1=new ChallengeLine(2,3);
       ChallengeLine ch2=new ChallengeLine(4,5);
       ChallengeLine ch3=new ChallengeLine(3,5);
       ChallengeLine ch4=new ChallengeLine(1,3);
       ChallengeLine ch5=new ChallengeLine(2,6);
       alist.add(ch1);
       alist.add(ch2);
       alist.add(ch3);
       alist.add(ch4);
       alist.add(ch5);
      
sort(alist,12);
   }
   public static void sort(List<ChallengeLine> alist,double x){
System.out.println("sorted final data:");
       double y=0;
       for(int i=0;i<alist.size();i++){
           Object o=alist.get(i);
           ChallengeLine c=(ChallengeLine)o;
           y=c.evaluate(x);
           cmap.put(y, c);
       }
       Set s=cmap.entrySet();
       Iterator i=s.iterator();
       while(i.hasNext()){
           Map.Entry mm=(Map.Entry)i.next();
           // System.out.println(mm.getKey());
       }
       Map<Double,ChallengeLine>tmap=new TreeMap<Double,ChallengeLine>(cmap);
       Set set2=tmap.entrySet();
       Iterator i2=set2.iterator();
       while(i2.hasNext()){
           Map.Entry m2=(Map.Entry)i2.next();
           ChallengeLine ccc=(ChallengeLine)m2.getValue();
           double m=ccc.getm();
                   double b=ccc.getb();
                     
           System.out.println(m2.getKey()+" "+"m is:"+m+" and b is:"+b);
       }
      
   }
}

output:
sorted final data:
15.0 m is:1.0 and b is:3.0
27.0 m is:2.0 and b is:3.0
30.0 m is:2.0 and b is:6.0
41.0 m is:3.0 and b is:5.0
53.0 m is:4.0 and b is:5.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote