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

Hi, I need help with this please provide correct code by testing each part and g

ID: 3588812 • Letter: H

Question

Hi, I need help with this please provide correct code by testing each part and getting the expected output. Thanks a lot!

"Model.java 3 1 package code; 3 import java.util.HashMap; 8 This assignment is the first step to a geography-based application. It gives you practice with the following 9 concepts: 11loops 12 13HashMaps Conditionals 5 The methods you write will use: 16 17 HashMap - this is a mapping of place names Ce.g "Tnawonda City") to their locations, 18 expressed in term of latitude and longitude points (this is what the Point2D is used for) 19 20 HashMap String, Integer> - this is a mapping of place names to their populations 21 22 New classes you will work with this homework include: 23 24 Point2D -a pair of double values which we use to represent points on a map, in latitude and longitude 25 A very useful method defined on a Point2D object is called 'distance'. If a and b are Point2D objects 26a.distance(b) returns the distance between the two points (as a double) The methods a.getXO and a.getYO 27return the x and y coordinates of the point a, respectively 29Integer - an object which holds a primitive int value. We've seen this idea before: a Character object 30 holds a primitive char value. Integer and Character are called wrapper classes-their objects hold values 31 of the corresponding primitive type. Every primitive type has a corresponding wrapper class The compiler 32 can generally convert between an Integer and int transparently as needed Cand similarly for other wrapper 33class primitive type pairings) 34 35 Autograding will be set up in Autolab no later than Tuesday, October 3 37 36 38 public class Model l 39 40 DESCRIBING A PLACE 42 43 * Given: 45 46 47 a String, the name of place, a HashMap

Explanation / Answer

//Model.java

package code;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class Model {

   public String description(String name,HashMap<String,Point2D> location,HashMap<String,Integer> population){
      
       Map.Entry<String,Point2D> entry=location.entrySet().iterator().next();
       String key= entry.getKey();
       Point2D p=entry.getValue();
      
       Map.Entry<String,Integer> entry2=population.entrySet().iterator().next();
       String key2= entry2.getKey();
       Integer pop=entry2.getValue();
       if(name.equals(key2))
       {
           if(name.equals(key))
      
       {
           String answer=key+" has latitude "+p.getX()+", longitude "+p.getY()+", and has a population of "+pop+" persons.";
           return answer;
       }
           else
               return "Requested place is Unknown: "+key;  
       }
       else
       return "Requested place is Unknown: "+key2;
   }
  
   public String closestToPoint(Point2D p,HashMap<String,Point2D> location){
       int i=0;
       double[] closedistance=new double[location.size()];
       HashMap<Double,String> close=new HashMap<Double,String>();
       String closest="";
       Iterator<Map.Entry<String,Point2D>> it = location.entrySet().iterator();
       while (it.hasNext()) {
            Entry<String, Point2D> pair = it.next();
            closedistance[i]=p.distance(pair.getValue());
            close.put(closedistance[i],pair.getKey());
            i++;
       }
       Arrays.sort(closedistance);
       return close.get(closedistance[0]);
   }
  
// not complete method .  
public String largestToPoint(Point2D p,double radius,HashMap<String,Point2D> location,HashMap<String,Integer> population){
      
       String largest="";
       return largest;
   }
  

public double longestDistance(HashMap<String,Point2D> location){
   int i=0;
   double[] longdistance=new double[location.size()];
   HashMap<Double,String> close=new HashMap<Double,String>();
   Point2D p=new Point2D(0.0,0.0);
   Iterator<Map.Entry<String,Point2D>> it = location.entrySet().iterator();
   while (it.hasNext()) {
        Entry<String, Point2D> pair = it.next();
       longdistance[i]=pair.getValue().distance(p);
       p=pair.getValue();
        close.put(longdistance[i],pair.getKey());
        i++;
   }
   Arrays.sort(longdistance);
   return longdistance[longdistance.length-1];

}
}

//Testing.java

package code;

import java.util.HashMap;

public class Testing {

   public static void main(String[] args) {

       Model m=new Model();

       HashMap<String,Integer> pop=new HashMap<String,Integer>();

       pop.put("Tonawanda City",15130);


       HashMap<String,Point2D> loc=new HashMap<String,Point2D>();
       Point2D pt=new Point2D(43.020335, -78.880315);


       loc.put("Tonawanda City",pt);

       String s=m.description("Tonawanda City", loc, pop);

       System.out.println(s);
       Point2D pt2=new Point2D(43.002277, -78.78731);

       pop.put("Dais Hall",13021);
       loc.put("Davis Hall",pt2);

       Point2D pt3=new Point2D(42.886448,-78.878372);


       loc.put("City of Buffalo",pt3);

       String closeCity=m.closestToPoint(pt, loc);
       System.out.println("close city: "+closeCity);

       double longDistance=m.longestDistance(loc);

       System.out.println("Longest distance is :"+longDistance);

   }


}


//Point2D.java

package code;

public class Point2D {
  
   private double x;
   private double y;
  
   public final double getX() {
       return x;
   }
   public void setX(double x) {
       this.x = x;
   }
   public final double getY() {
       return y;
   }
   public void setY(double y) {
       this.y = y;
   }
   public Point2D(double x, double y) {
       super();
       this.x = x;
       this.y = y;
   }
  
  
  
   public double distance(Point2D point){
       double a=getX()-point.getX();
       double b=getY()-point.getY();
       return Math.sqrt(a*a+b*b);
   }
   @Override
   public String toString() {
       return "Point2D [x=" + x + ", y=" + y + "]";
   }

  
  
  
  
  
}

/*output:-

Tonawanda City has latitude 43.020335, longitude -78.880315, and has a population of 15130 persons.
close city: Tonawanda City
Longest distance between Tonawada city and davis Hall is :89.84905852601601


*/

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