我只是需要一些帮助来将输出格式化为特定的方式。我满足了作业的所有要求,除了输出。
对于这篇文章的错误格式,我深表歉意,非常感谢任何建议和帮助。
我需要输出看起来像:
随机先生 - 500 美元
BobRandom 先生 - 250 美元
等 - 8 次以上
(所有美元的总和)
这是我的代码:
import javax.swing.JOptionPane;
import java.util.Arrays;
public class PeerTutors {
public static void main(String[] args) {
String[] myNameArray = new String[2];
String[] myGradeArray = new String[2];
double[] myStudentArray = new double[2];
double[] stipend = new double[2];
int sum = 0;
for (int i = 0; i < 2; i++) {
myNameArray[i] = (JOptionPane
.showInputDialog(null,
"Enter the Peer Tutor name, last name then followed by the first name."));
}
Arrays.sort(myNameArray, String.CASE_INSENSITIVE_ORDER);
JOptionPane.showMessageDialog(null, "The Peer Tutors Names are :"
+ Arrays.toString(myNameArray));
for (int a = 0; a < 2; a++) {
myGradeArray[a] = JOptionPane.showInputDialog(null,
"Please enter the highest degree earned for: "
+ myNameArray[a]);
}
JOptionPane.showMessageDialog(null, "The Peer Tutors Names are :"
+ Arrays.toString(myNameArray) + Arrays.toString(myGradeArray));
for (int b = 0; b < 2; b++) {
myStudentArray[b] = Double.parseDouble(JOptionPane.showInputDialog(
null, "Please enter the number of students"
+ myNameArray[b] + " has assisted"));
}
JOptionPane.showMessageDialog(null,
"The Peer Tutors Report: " + Arrays.toString(myNameArray)
+ "with" + Arrays.toString(myStudentArray)
+ " of children tutoring");
for (int c = 0; c < 2; c++) {
if (myGradeArray[c].equals("BS")) {
stipend[c] = 9.5 * myStudentArray[c];
} else if (myGradeArray[c].equals("MS")) {
stipend[c] = 15 * myStudentArray[c];
} else {
stipend[c] = 20 * myStudentArray[c];
}
}
for (double d : stipend) {
sum += d;
}
for (int d = 0; d < 2; d++) {
JOptionPane.showMessageDialog(null, myNameArray[d] + "-"
+ stipend[d] + "\n");
}
}
}