rendered paste bodyimport java.io.*;
public class ClassScore {
private String getUserInput(String prompt) throws IOException {
String inputLine = null;
System.out.print(prompt + " ");
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine.length() == 0)
return null;
return inputLine.toLowerCase();
} // method getUserInput()
private int getUserInteger(String prompt) {
int convertedValue = -1;
String tempString = null;
try {
tempString = this.getUserInput(prompt);
convertedValue = Integer.parseInt(tempString);
// return convertedValue;
} // try
catch (IOException ex) {
System.out.println("IOEXception: " + ex);
} // catch
catch (java.lang.NumberFormatException ex) {
SimpleOutput.showError("Error converting string \"" + tempString + "\" to an integer.");
convertedValue = this.getUserInteger(prompt);
} // catch
catch (Exception ex) {
System.out.println("Exception: " + ex);
} // catch
return convertedValue;
} // method getUserInteger
public static void main(String[] args) {
int labScores[] = new int[12];
int labMaximums[] = {10, 15, 20, 20, 25, 25, 30, 35, 35, 30, 35, 35};
int assignmentScores[] = new int[6];
int assignmentMaximums[] = {50 ,60, 70, 80, 90, 100};
int labsTotal = 0;
int labsMaximum = 0;
int assignmentsTotal = 0;
int assignmentsMaximum = 0;
int midtermScore;
int midtermMaximum = 100;
int finalScore;
int finalMaximum = 100;
double labsFraction, assignmentsFraction, midtermFraction, finalFraction, classFraction;
// The Class type
ClassScore score = new ClassScore();
try
{
String first=score.getUserInput("Enter First String");
System.out.println("This string has length: "+ first.length());
String second=score.getUserInput("Enter Second String");
System.out.println("This string has length: "+ second.length());
String third=first+ " " +second;
System.out.println(third);
}
catch (IOException ex)
{
System.out.println("IOException: " +ex);
}
// Get the lab scores
/* for (int index = 0; index < 12; index++) {
// Get the lab score
labScores[index] = score.getUserInteger("Enter the Score for lab " + (index+1) + " (out of " +
labMaximums[index] + "): ");
System.out.println("\tThe score for lab " + (index+1) + " is " + labScores[index]);
} // for
// Get the assignment scores
for (int index = 0; index < 6; index++) {
// Get the lab score
assignmentScores[index] = score.getUserInteger("Enter the Score for assignment " + (index+1) +
" (out of " + assignmentMaximums[index] + "): ");
System.out.println("\tThe score for assignment " + (index+1) + " is " + assignmentScores[index]);
} // for
// Get the midterm
midtermScore = score.getUserInteger("Enter the midterm score (out of " + midtermMaximum + "): ");
System.out.println("\tThe midterm score is " + midtermScore);
// Get the final
finalScore = score.getUserInteger("Enter the final score (out of " + finalMaximum + "): ");
System.out.println("\tThe final score is " + finalScore);
// Calculate the labs fraction
for (int index = 0; index < 12; index++) {
labsTotal += labScores[index];
labsMaximum += labMaximums[index];
} // for
labsFraction = labsTotal / (double) labsMaximum;
// Calculate the assignments fraction
for (int index = 0; index < 6; index++) {
assignmentsTotal += assignmentScores[index];
assignmentsMaximum += assignmentMaximums[index];
} // for
assignmentsFraction = assignmentsTotal / (double) assignmentsMaximum;
// Calculate the midterm fraction
midtermFraction = midtermScore / (double) midtermMaximum;
// Calculate the final fraction
finalFraction = finalScore / (double) finalMaximum;
// Calculate the overall class fraction
classFraction = labsFraction * 0.24 + assignmentsFraction * 0.16 + midtermFraction * 0.2 + finalFraction * 0.4;
System.out.println("The class fraction is " + classFraction + ".");
System.out.print("The class grade is ");
if (classFraction >= 0.9)
System.out.println("A.");
else if (classFraction >= 0.8)
System.out.println("B.");
else if (classFraction >= 0.7)
System.out.println("C.");
else if (classFraction >= 0.6)
System.out.println("D.");
else
System.out.println("E."); */
} // method main()
} // class ClassScore