Please edit (studentresultsummary.java) only, the other codes are for you for reference the code runs but i get these er

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Please edit (studentresultsummary.java) only, the other codes are for you for reference the code runs but i get these er

Post by answerhappygod »

Please edit (studentresultsummary.java) only, the other codes
are for you for reference
Please Edit Studentresultsummary Java Only The Other Codes Are For You For Reference The Code Runs But I Get These Er 1
Please Edit Studentresultsummary Java Only The Other Codes Are For You For Reference The Code Runs But I Get These Er 1 (126.47 KiB) Viewed 69 times
the code runs but i get these errors below
-Failed: Rendered summary does not have the expected number of
lines ==> expected: <6> but was: <1>
Note(if possible avoid importing libraries in the main code like
myarraylist..etc in studentresuktsummary as these were imported and
used in the reference code studentresult)
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
-----------------------------------------------------------------------------------------------------------------------
->->->[BELOW CODES ARE FOR REFERENCE
ONLY]<-<-<-
[NO NEED TO CHANGE THE CODES BELOW. IT IS JUST FOR
REFERENCE]
code for [StudentResult.java]
import java.io.File;
import java.io.FileReader ;
import java.io.BufferedReader ;
import java.util.ArrayList ;
/**
* This class stores a grade for a student in a specific
subject.
*
* You do not need to alter this class in any way.
*/
public class StudentResult {
private String name ;
private String subject ;
private double grade ;
public StudentResult(String name, String subject, double grade)
{
this.name = name ;
this.subject = subject ;
this.grade = grade ;
}
public String getName() {
return name ;
}
public String getSubject() {
return subject ;
}
public double getGrade() {
return grade ;
}
public String toString() {
return name + " (" + subject + ") " + grade + "%";
}
public static StudentResult[] readFile(String path) throws
Exception {
ArrayList<StudentResult> results = new ArrayList<>()
;

File file = new File(path);
BufferedReader reader = new BufferedReader(new
FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
String[] values = line.split(",");
StudentResult result = new StudentResult(values[0], values[1],
Double.valueOf(values[2])) ;
results.add(result);
}
return results.toArray(new StudentResult[results.size()]);
}
public static void main(String args[]) throws Exception {
StudentResult[] results = readFile("results.csv");
for (StudentResult result: results) {
System.out.println(result);
}
}
}
---------------------------------------------------------------------------------------
code for [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());
}
}
}
----------------------------------------------------------------------------------------------------------
[percent formatter CODE]
import java.text.NumberFormat ;
/*
* This utility class helps with printing tidy percentage
values.
*
* You don't need to make any changes to it, just use it as
is.
*/
public class PercentFormatter {
private NumberFormat format ;
public PercentFormatter() {

this.format = NumberFormat.getInstance();

this.format.setMinimumFractionDigits(1);
this.format.setMaximumFractionDigits(1);
}
/*
* Prints a percentage value from the given dividend and
devisor.
*
* For example, passing 1 and 4 as the dividend and devisor
respectively would
* return "25.0%"
*/
public String format(int dividend, int devisor) {
if (devisor == 0) {
return "N/A" ;
}
double fraction = (double) dividend / devisor ;
return format(fraction*100) ;
}
/*
* Prints a percentage value from the given value.
*
* For example, passing 25 as the value would
* return "25.0%"
*/
public String format(double value) {
return format.format(value) + "%";
}
}
+ Studen... StudentR... GradeU... results.... Percent... Runner... [] 1 /* 2 * Implement this class according to the specification provided, so that it 3 * can print a summary of how many students achieved each grade (HD, D, etc) 4 * and who the top student was. 5 */ import java.util.ArrayList; 6 7 public class StudentResultSummary { 8 9 //add any necessary fields here. 10 //it's up to you to figure out what you need, 11 //and what should be public or private, static or not. escription 12
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply