public class Point{ private int x; private int y; public Point(int x,int y){ thi
ID: 3930443 • Letter: P
Question
public class Point{
private int x;
private int y;
public Point(int x,int y){
this.x=x;
this.y=y;
}
}
1. write a java statement to instantiate a point object, called p, using any values for x and y of your choice.
3.write a method
int analyzeScores(int[] scoresArray)
that takes an array of integers as input. Assume the array contains student grades in a certain test. The method determins and returns how many scores are above or equal to the average.
for example, calling the method on the below array returns 6 because the average of the numbers is 78.4 and there are 6 values in the array that are greater than 78.4( which are 80,93,92,95,100 and 65)
65 75 65 80 93 92 95 100 34 85Explanation / Answer
Question 1:
Point p = new Point(3,4);
Question 2:
public class DistancePoint {
public static void main(String[] args) {
Point p1 = new Point(3,4);
Point p2 = new Point(5,6);
double distance = Math.sqrt(Math.pow(p2.getX()-p1.getX(), 2) + Math.pow(p2.getY()-p1.getY(), 2));
System.out.println("Distance is "+distance);
}
}
Question 3:
public static int analyzeScores(int[] scoresArray){
int sum = 0;
int count = 0;
double average;
for(int i=0; i<scoresArray.length; i++){
sum = sum + scoresArray[i];
}
average = sum/(double)scoresArray.length;
System.out.println("Average is "+average);
for(int i=0; i<scoresArray.length; i++){
if(average <= scoresArray[i]){
count++;
}
}
return count;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.