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

q2: Write a public static method named q2 that takes two ints as parameters repr

ID: 3704751 • Letter: Q

Question

q2: Write a public static method named q2 that takes two ints as parameters representing a 2d point (The first parameter is the x-value, second is the y-value) and returns a double. The return value shall be the Euclidean distance between the input point and the point (-20,-22) * See (https://docs.oracle.com/javase/8/docs/api/Java/lang/Math.html#method.summary) for a complete list of methods contained in the Math class. You may call any of these methods in your method q3: Write a public static method named q3 that takes no parameters and returns void. The method should print all the integers from 4 to 172 to the screen. The output should be inclusive of these end points s/ q4: Write a public static method named q4 that takes an ArrayList of Doubles as a parameter and returns an ArrayList of Doubles. The returned ArrayList will contain only the values from the input ArrayList that have a natural logarithm within 1.0 of .59 (ie the target value of the natural logarithm is 0.59 and the allowed variance from this " target is 1.0) q5: Write a public static method named q5 that takes no parameters and returns a HashMap of Integers to Doubles. The returned HashMap should contain all the integers from 13 to 21 * as keys mapping to their square root as values. The output should be inclusive of the end * points ?

Explanation / Answer

NOte:Could u plz check the output.

________________

Demo.java

import java.util.HashMap;

import java.util.Map;

import java.util.Scanner;

import java.util.Set;

public class Demo {

public static void main(String[] args) {

int x,y;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the inputs entered by the user

System.out.print("Enter the x-value :");

x=sc.nextInt();

System.out.print("Enter the y-value :");

y=sc.nextInt();

//calling the method

double dis=q2(x,y);

//Displaying the output

System.out.printf("The Distance is :%.2f",dis);

q3();

Map<Integer,Double> m;

m=q5();

System.out.println("Displaying the HashMap Key Value Pairs:");

for(Map.Entry e:m.entrySet()){  

System.out.printf("%d %.2f ",e.getKey(),e.getValue());  

}  

}

private static Map<Integer, Double> q5() {

Map<Integer,Double> map=new HashMap<Integer,Double>();

for(int i=13;i<=23;i++)

{

map.put(i,Math.sqrt(i));

}

return map;

}

private static void q3() {

int cnt=0;

System.out.println(" Displaying the numbers :");

for(int i=4;i<+172;i++)

{

cnt++;

System.out.print(i+" ");

if(cnt%10==0)

System.out.println();

}

System.out.println();

}

//This method will calculate the distance between two points  

private static double q2(int x1, int y1) {

int x2=-20,y2=22;

return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));

}

}

__________________

Output:

Enter the x-value :3

Enter the y-value :7

The Distance is :27.46

Displaying the numbers :

4 5 6 7 8 9 10 11 12 13

14 15 16 17 18 19 20 21 22 23

24 25 26 27 28 29 30 31 32 33

34 35 36 37 38 39 40 41 42 43

44 45 46 47 48 49 50 51 52 53

54 55 56 57 58 59 60 61 62 63

64 65 66 67 68 69 70 71 72 73

74 75 76 77 78 79 80 81 82 83

84 85 86 87 88 89 90 91 92 93

94 95 96 97 98 99 100 101 102 103

104 105 106 107 108 109 110 111 112 113

114 115 116 117 118 119 120 121 122 123

124 125 126 127 128 129 130 131 132 133

134 135 136 137 138 139 140 141 142 143

144 145 146 147 148 149 150 151 152 153

154 155 156 157 158 159 160 161 162 163

164 165 166 167 168 169 170 171

Displaying the HashMap Key Value Pairs:

17 4.12

16 4.00

19 4.36

18 4.24

21 4.58

20 4.47

23 4.80

22 4.69

13 3.61

14 3.74

15 3.87

______________Thank YOu