NOTE (the code runs for me and i get the output
below) but, i get this error below
(Failed: Rendered summary does not have the expected number of
lines ==> expected: <6> but was: <1>)
Please edit my code for
(studentresultsummary.java) only,
(GradeUtils.java is already completed but feel
free if you want to make some changes)
Output
**********************************************************************
HD: 10 (13.0%)
D: 9 (11.7%)
C: 3 (3.9%)
P: 14 (18.2%)
Z: 41 (53.2%)
Top student: Michael Riley with 97.4% (HD)
*****************************************************
INSTRUCTIONS
We've provided a skeleton of a StudentResultSummary class with
the following methods for you to implement:
add - for adding a single StudentResult to the summary
addAll - for adding multiple StudentResult to the summary
reset - for clearing all data from the summary
renderToString - for printing out the summary, in the same
format as described above.
It is entirely up to you to figure out how to code up these
methods, and to design any other aspects of the class (e.g. fields,
additional helper methods) that are needed to make it work.
Some minor things you will need to account for to pass the
automated tests:
The rendered summary needs look exactly like the example
provided above, including its use of whitespace and punctuation,
and the number of decimal points included in percentage values.
If the summary is rendered before any data is added to it, then
it should render as "No results to show" (without any
punctuation).
If there are multiple students who all achieved the same high
mark, your summary should always show the name of the first student
who achieved the top mark (based on the order that student results
are added to the summary).
------------------------------------------------------------------------------------------------------------------------
studentresultsummary.java code
-----------------------------------------------------------------------------------------------------------------------
[[[[Code for GradeUtils.java]]]]]]
/**
* This utility class is intended to help manage letter
grades,
* like "HD", "D", etc.
*
* You should implement the methods as described below, and
then
* use this class in your solution to reduce some of the complexity
of
* the StudentResultSummary class.
*/
public class GradeUtils {
/*
* Stores the possible letter grades:
* HD (high distinction) is for marks between 85(inclusive) and
100(inclusive)
* D (distinction) is for marks between 75(inclusive) and
85(exclusive)
* C (credit) is for marks between 65(inclusive) and
75(exclusive)
* P (pass) is for marks between 50(inclusive) and
65(exclusive)
* Z (fail) is for marks below 50
*/
public static final String[] GRADES = {"HD","D","C","P","Z"} ;
/*
* Converts a numeric grade (as a number between 0 and 100) to an
index
* into the GRADES array.
*
* For example:
* Calling this with 95 would return 0 (aka "HD")
* Calling this with 54 would return 3 (aka "P")
* Calling this with 32 would return 4 (aka "Z")
*/
public static int getLetterGradeIndex(double grade) {
// write your code here.
if(grade >= 85){
return 0;
}
else if(grade >= 75){
return 1;
}
else if(grade >= 65){
return 2;
}
else if(grade >= 50){
return 3;
}
return 4;
}
/*
* Converts a numeric grade (as a number between 0 and 100) to a
letter grade.
*
* For example:
* Calling this with 95 would return "HD"
* Calling this with 54 would return "P"
* Calling this with 32 would return "Z"
*/
public static String getLetterGrade(double grade) {
// write your code here.
if(grade >= 85){
return GRADES[0];
}
else if(grade >= 75){
return GRADES[1];
}
else if(grade >= 65){
return GRADES[2];
}
else if(grade >= 50){
return GRADES[3];
}
return GRADES[4];
}
}
---------------------------------------------------------------------------------------------------------------------------
->->->[BELOW CODES ARE FOR REFERENCE
ONLY]<-<-<-
[NO NEED TO CHANGE THE CODES BELOW. IT IS JUST FOR
REFERENCE]
runner.java
/**
* Provides an entry point for running the code.
* You do not need to alter this class in any way (unless you
want to).
*/
public class Runner {
/*
* Note: Feel free to change this main method to test
different
* parts of your code and check that it is behaving
correctly.
*
* The automatic marking will work regardless of what
you do to this method
* (as long as the code still compiles,
obvs.)
*/
public static void main(String[] args) throws
Exception {
StudentResult[] allResults =
StudentResult.readFile("results.csv");
//Create summaries for each
subject
String[] subjects = {
"Programming
Fundamentals",
"Communication for IT
Professionals",
"Introduction to
Information Systems"
};
StudentResultSummary[]
subjectSummaries = new StudentResultSummary[subjects.length];
for (int i=0 ; i<subjects.length;
i++) {
subjectSummaries = new
StudentResultSummary();
}
//Go through each result, adding it
to the appropriate summary
for (StudentResult result: allResults)
{
//add result to
appropriate subject summary
for (int i=0 ;
i<subjects.length; i++){
//if the
current result is for the current subject
if
(result.getSubject().equals(subjects)) {
//add it to the corresponding summary
subjectSummaries.add(result);
}
}
}
//print subject histograms
for (int i=0 ; i< subjects.length ;
i++) {
System.out.println("Results for " + subjects);
System.out.println(subjectSummaries.renderToString());
}
}
}
NOTE (the code runs for me and i get the output below) but, i get this error below (Failed: Rendered summary does not h
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
NOTE (the code runs for me and i get the output below) but, i get this error below (Failed: Rendered summary does not h
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!