0
私のインストラクターが本当に上手く行きませんでした。彼の例は私を助けてくれません。外部ライブラリからメソッドを呼び出すにはどうすればよいですか?
static double Q1(NormalDistribution distro, double x){
// return the z-score of x in the given distribution
}
与えられた分布のxのzスコアを返します。私たちはすべての数学を行う必要がなく、毎回 "車輪を再発明"する必要がないために、私たちは図書館をインポートするように教えられ、私はそれをインポートしました、私はちょうどメソッドのクラスを呼び出す方法について混乱しています。あなたがあなたの主なメソッド内で外部クラスのインスタンスを作成する必要があるとしている
外部ライブラリ
package cse115.math;
import java.util.ArrayList;
public class NormalDistribution{
private double standardDeviation;
private double mean;
public NormalDistribution(double standardDeviation, double mean){
this.standardDeviation = standardDeviation;
this.mean = mean;
}
/**
* Creates a normal distribution given a data set.
*/
public NormalDistribution(ArrayList<Double> data){
double sum = 0.0;
for(double value : data){
sum += value;
}
double mean = sum/data.size();
double variance = 0.0;
for(double value : data){
variance += Math.pow(value - mean, 2.0);
}
variance /= data.size();
this.mean = mean;
this.standardDeviation = Math.sqrt(variance);
// yes, this method puts 3 free points on the table for the observant.
}
/**
* Returns the z-score of the provided value. Z-score is the number of standard deviations the value
* is away from the mean.
*/
public double zScore(double value){
return (value - this.mean)/this.standardDeviation;
}
public double getStandardDeviation(){
return this.standardDeviation;
}
public double getMean(){
return this.mean;
}
@Override
public String toString(){
return "{" +
"mean=" + mean +
", standardDeviation=" + standardDeviation +
'}';
}
}