java。 急 ! 编程语言!
3个回答
展开全部
import java.util.Arrays;
import java.util.Random;
public class RandScoreTest {
private int[] scoresA;
private int[] scoresB;
private int[] scoresTotal;
private int scoreMax;
private transient Random random = new Random();
public static void main(String[] args) {
RandScoreTest randScoreTest = new RandScoreTest(150, 180, 50);
System.out.println("scores A:");
randScoreTest.printScoresA();
System.out.println("scores B:");
randScoreTest.printScoresB();
System.out.println("scores Total:");
randScoreTest.printScoresTotal();
randScoreTest.shuttleSortHighToLow();
System.out.println("scores Total low to high:");
randScoreTest.printScoresTotalInvert();
System.out.println("scores Total high to low:");
randScoreTest.printScoresTotal();
System.out.println("highest score:");
System.out.println(randScoreTest.getMaxScore());
System.out.println("lowest score:");
System.out.println(randScoreTest.getMinScore());
System.out.println("average score:");
System.out.println(randScoreTest.getAverageScore());
System.out.println("standard deviation:");
System.out.println(randScoreTest.standardDeviation());
}
public RandScoreTest(int aCount, int bCount, int scoreMax) {
scoresA = new int[aCount];
scoresB = new int[bCount];
scoresTotal = new int[aCount > bCount ? aCount : bCount];
this.scoreMax = scoreMax;
generateScores(scoresA);
generateScores(scoresB);
}
private void generateScores(int[] scores) {
for (int i = 0, len = scores.length; i < len; i++) {
scores[i] = random.nextInt(scoreMax);
scoresTotal[i] += scores[i];
}
}
public void printScoresA() {
printScores(scoresA);
}
public void printScoresB() {
printScores(scoresB);
}
public void printScoresTotal() {
printScores(scoresTotal);
}
private void printScores(int[] scores) {
System.out.println(Arrays.toString(scores));
}
public void printScoresTotalInvert() {
StringBuilder buf = new StringBuilder();
for (int i = scoresTotal.length - 1; i >= 0; i--) {
buf.append(scoresTotal[i]).append(",");
}
System.out.println(buf.toString());
}
public void shuttleSortHighToLow() {
for (int i = 0; i < scoresTotal.length - 1; i++) {
for (int j = i + 1; j < scoresTotal.length; j++) {
if (scoresTotal[i] <= scoresTotal[j]) {
int temp = scoresTotal[i];
scoresTotal[i] = scoresTotal[j];
scoresTotal[j] = temp;
}
}
}
}
public int getMaxScore() {
return scoresTotal[0];
}
public int getMinScore() {
return scoresTotal[scoresTotal.length - 1];
}
public int getAverageScore() {
int sum = 0;
for (int i = 0, len = scoresTotal.length; i < len; i++) {
sum += scoresTotal[i];
}
return sum / scoresTotal.length;
}
public double standardDeviation() {
long sum1 = 0;
int sum2 = 0;
int len = scoresTotal.length;
for (int i = 0; i < len; i++) {
sum1 += scoresTotal[i] * scoresTotal[i];
sum2 += scoresTotal[i];
}
return Math.pow((sum1 - sum2 * sum2 / len) / (len - 1), 0.5);
}
}
import java.util.Random;
public class RandScoreTest {
private int[] scoresA;
private int[] scoresB;
private int[] scoresTotal;
private int scoreMax;
private transient Random random = new Random();
public static void main(String[] args) {
RandScoreTest randScoreTest = new RandScoreTest(150, 180, 50);
System.out.println("scores A:");
randScoreTest.printScoresA();
System.out.println("scores B:");
randScoreTest.printScoresB();
System.out.println("scores Total:");
randScoreTest.printScoresTotal();
randScoreTest.shuttleSortHighToLow();
System.out.println("scores Total low to high:");
randScoreTest.printScoresTotalInvert();
System.out.println("scores Total high to low:");
randScoreTest.printScoresTotal();
System.out.println("highest score:");
System.out.println(randScoreTest.getMaxScore());
System.out.println("lowest score:");
System.out.println(randScoreTest.getMinScore());
System.out.println("average score:");
System.out.println(randScoreTest.getAverageScore());
System.out.println("standard deviation:");
System.out.println(randScoreTest.standardDeviation());
}
public RandScoreTest(int aCount, int bCount, int scoreMax) {
scoresA = new int[aCount];
scoresB = new int[bCount];
scoresTotal = new int[aCount > bCount ? aCount : bCount];
this.scoreMax = scoreMax;
generateScores(scoresA);
generateScores(scoresB);
}
private void generateScores(int[] scores) {
for (int i = 0, len = scores.length; i < len; i++) {
scores[i] = random.nextInt(scoreMax);
scoresTotal[i] += scores[i];
}
}
public void printScoresA() {
printScores(scoresA);
}
public void printScoresB() {
printScores(scoresB);
}
public void printScoresTotal() {
printScores(scoresTotal);
}
private void printScores(int[] scores) {
System.out.println(Arrays.toString(scores));
}
public void printScoresTotalInvert() {
StringBuilder buf = new StringBuilder();
for (int i = scoresTotal.length - 1; i >= 0; i--) {
buf.append(scoresTotal[i]).append(",");
}
System.out.println(buf.toString());
}
public void shuttleSortHighToLow() {
for (int i = 0; i < scoresTotal.length - 1; i++) {
for (int j = i + 1; j < scoresTotal.length; j++) {
if (scoresTotal[i] <= scoresTotal[j]) {
int temp = scoresTotal[i];
scoresTotal[i] = scoresTotal[j];
scoresTotal[j] = temp;
}
}
}
}
public int getMaxScore() {
return scoresTotal[0];
}
public int getMinScore() {
return scoresTotal[scoresTotal.length - 1];
}
public int getAverageScore() {
int sum = 0;
for (int i = 0, len = scoresTotal.length; i < len; i++) {
sum += scoresTotal[i];
}
return sum / scoresTotal.length;
}
public double standardDeviation() {
long sum1 = 0;
int sum2 = 0;
int len = scoresTotal.length;
for (int i = 0; i < len; i++) {
sum1 += scoresTotal[i] * scoresTotal[i];
sum2 += scoresTotal[i];
}
return Math.pow((sum1 - sum2 * sum2 / len) / (len - 1), 0.5);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码太长,留邮箱吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这么多,彩30分
追问
...可以加分
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询