Calling a method from another class with setters and getters in Java - java

I need some help with this as I'm completely lost. I'm trying to call a method I created in another class to output what the grade is for the average entered by the user, but I'm not sure where I messed up. I don't get how to call my other class, I read that using an object as a variable doesn't work in Java, but I have no clue how else to get it to pull through to apply the method in the other class to give the correct grade.
Here's the class that contains the method....
public class Assignment {
private double score;
public double getScore(){
return score;
}
public void setScore(double newScore){
score = newScore;
}
public static void newScore(double a, double b, double c, double d, double f) {
double score1 = a;
double score2 = b;
double score3 = c;
double score4 = d;
double score5 = f;
if (score1 >= 90) {
System.out.println("Your grade is: " + score1);
System.out.println("Great job!");
} else if (score2 >= 80 && score2 < 90) {
System.out.println("Your grade is: " + score2);
System.out.println("Not bad!");
} else if (score3 >= 70 && score3 < 80) {
System.out.println("Your grade is: " + score3);
System.out.println("Need a little work");
} else if (score4 >= 60 && score4 < 70) {
System.out.println("Your grade is: " + score4);
System.out.println("Not looking so good.");
} else if (score5 >= 50 && score5 < 60) {
System.out.println("Your grade is: " + score5);
System.out.print("Study harder!");
} else {
System.out.println("Yikes!");
}
}
}
And here's what I put in the main method...
import java.util.Scanner;
public class Grades {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Assignment newScore = new Assignment ();
System.out.println("Enter your test score: ");
newScore = input.nextDouble();
System.out.println("Your current grade is: " + newScore);
}
}

Don't quite understand your question here. You have a method that takes in multiple score, and it has a set of if-else statements to determine the message to print based off;
if first score is more than 90 do this,
and if first score's condition is not met, then check second score value.
and then if second condition not met, then check third score to see if it met certain score.. blah blah
If you are looking at having an assignment class to keep a set of scores and finally print out each score then do this;
Modify your Assignment class is to allow multiple scores to be kept at a time. To be able to hold multiple scores you will have to change the score variable to be at least an array or a list. That is, List<Double> scores = new ArrayList<Double>();
Then modify the setter method to be something like "addScore(double score)"
public void addScore(double score) {
scores.add(score)
}
In your "newScore" method, use a loop to iterate through the score to output the appropriate score message for each assignment.
for (Double score : scores) {
if (score > 90) {
System.out.println('blah');
}
}
Note the code above are just something I type off my mind, I didn't test it using any compilers so you may have to rework on some syntax errors.

Since the variable newScore is a Assignment object rather than a double, the code newScore = input.nextDouble(); can not be compiled. I suppose you are using the input number as your score, so that line should be
newScore.setScore(input.nextDouble());
Hence the next line should be
System.out.println("Your current grade is: " + newScore.getScore());
Kindly replace these two lines and check if it suites your requirements.
EDIT:
Assignment.java:
public class Assignment {
private double score;
public double getScore(){
return score;
}
public void setScore(double newScore){
score = newScore;
}
public void checkScore(double a, double b, double c, double d, double f) {
if (score >= a) {
System.out.println("Your grade is: " + score);
System.out.println("Great job!");
} else if (score >= b && score < a) {
System.out.println("Your grade is: " + score);
System.out.println("Not bad!");
} else if (score >= c && score < b) {
System.out.println("Your grade is: " + score);
System.out.println("Need a little work");
} else if (score >= d && score < c) {
System.out.println("Your grade is: " + score);
System.out.println("Not looking so good.");
} else if (score >= f && score < d) {
System.out.println("Your grade is: " + score);
System.out.print("Study harder!");
} else {
System.out.println("Yikes!");
}
}
}
Grades.java:
import java.util.Scanner;
public class Grades {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Assignment newScore = new Assignment();
System.out.println("Enter your test score: ");
newScore.setScore(input.nextDouble());
newScore.checkScore(90, 80, 70, 60, 50);
System.out.println("Your current grade is: " + newScore.getScore());
}
}

Related

How can I get my input validation to work so anything outside range -1 - 100 will display the error message?

public static void main(String[] args) {
// Defining the constants for min and max range
final int minValue = -1;
final int maxValue = 100;
String message = "Welcome to Simple Gradebook!";
promptForInt(message, minValue, maxValue);
// Declaring variables for the loop & the sentinel variable
int score = 0;
boolean doneYet = false;
do {
// Input Validation
if (score < minValue || score > maxValue) {
System.err.printf(
"Invalid value. The acceptable range is" + " between %d and %d\n" + "Please try again\n",
minValue, maxValue);
score = promptForInt(message, minValue, maxValue);
} else {
doneYet = true;
}
} while (doneYet == false);
}
public static int promptForInt(String message, int minValue, int maxValue) {
// Declaring variables for the loop & the sentinel variable
int sum = 0;
int numStudents = 0;
int score = 0;
System.out.println(message);
// Creating the sentinel loop
do {
System.out.printf("Enter the score for student #%d" + "(or -1 to quit): ", numStudents);
Scanner keyboard = new Scanner(System.in);
score = Integer.parseInt(keyboard.nextLine());
if (score != -1) {
sum += score;
numStudents += 1;
}
} while (score != -1);
double avgScore = (double) sum / numStudents;
// Passing method to this method to convert grade to letter
convertToLetter(avgScore);
System.out.println("The average score is: " + avgScore + " which equates to a " + avgScore);
return 0;
}
How can I get my input validation to work so anything outside range -1 - 100 will display the error message? I want to use the "do-while" loop and thought I was doing it all correctly. If a user enters a value outside the defined range, it should display the error message and prompt again for the score. What am I missing?
A good place to do the validation is inside the method, promptForInt.
Since there is no use of the value returned from method, promptForInt, it's better to declare it as void.
Do not instantiate the Scanner object inside the loop.
The following code has incorporated all these comments:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Defining the constants for min and max range
final int minValue = -1;
final int maxValue = 100;
String message = "Welcome to Simple Gradebook!";
promptForInt(message, minValue, maxValue);
}
public static void promptForInt(String message, int minValue, int maxValue) {
// Declaring variables for the loop & the sentinel variable
int sum = 0;
int numStudents = 0;
int score = 0;
boolean valid;
Scanner keyboard = new Scanner(System.in);
System.out.println(message);
// Loop to continue getting score for students until -1 is entered to quit
do {
System.out.printf("Enter the score for student #%d" + "(or -1 to quit): ", numStudents);
// Loop for getting input of score for the current student
do {
valid = true;
score = Integer.parseInt(keyboard.nextLine());
// Input Validation
if (score < minValue || score > maxValue) {
System.err.printf(
"Invalid value. The acceptable range is" + " between %d and %d\n" + "Please try again\n",
minValue, maxValue);
valid = false;
}
} while (!valid);
if (score != -1) {
sum += score;
numStudents += 1;
}
} while (score != -1);
double avgScore = (double) sum / numStudents;
// Passing method to this method to convert grade to letter
convertToLetter(avgScore);
System.out.println("The average score is: " + avgScore + " which equates to a " + convertToLetter(avgScore));
}
public static char convertToLetter(double avg) {
char gradeLetter;
// Identifying the ranges for the grade letter
if (avg >= 90) {
gradeLetter = 'A';
} else if (avg >= 80) {
gradeLetter = 'B';
} else if (avg >= 70) {
gradeLetter = 'C';
} else if (avg >= 60) {
gradeLetter = 'D';
} else {
gradeLetter = 'F';
}
return gradeLetter;
}
}
A sample run:
Welcome to Simple Gradebook!
Enter the score for student #0(or -1 to quit): -2
Invalid value. The acceptable range is between -1 and 100
Please try again
-4
Invalid value. The acceptable range is between -1 and 100
Please try again
45
Enter the score for student #1(or -1 to quit): 50
Enter the score for student #2(or -1 to quit): -1
The average score is: 47.5 which equates to a F

How to return Scanner.in value from the method to another method

I want to make some simple program which will count monthly rate of product. There is two inputs: cost of the product - between 100-10000 and number of rates - between 6-48. I wanted to do it like in the code below:
import java.util.Scanner;
public class Calculator {
Scanner sc = new Scanner (System.in);
double productCost;
int numberOfRates;
double loanInterestRate;
double monthlyRate;
Double print () {
Calculator c = new Calculator();
System.out.println ("Enter the value of your product from 100 to 10 000 : ");
productCost=sc.nextDouble();
if (productCost < 100){
System.out.println ("You have to choose price between 100 to 10000. Try again: ");
c.print();
} else if (productCost >10000){
System.out.println ("You have to choose price between 100 to 10000. Try again: ");
c.print();
} else if (productCost >= 100 || productCost <=10000){
c.print1();
return = productCost;
// how to return productCost to be used in next method print1()?
}
else return null;
}
void print1(){
Calculator c = new Calculator();
System.out.println ("Now enter how many rates do you want to pay from 6 to 48: ");
numberOfRates=sc.nextInt();
if (numberOfRates<6){
System.out.println ("You can't choose this number of rates. Choose between 6-48: ");
c.print1();
} else if (numberOfRates>48){
System.out.println ("You can't choose this number of rates. Choose between 6-48: ");
c.print1();
} else if (numberOfRates>=6 || numberOfRates<=12) {
loanInterestRate=1.025;
monthlyRate = (productCost*loanInterestRate)/numberOfRates;
System.out.printf("Your monthly rate is: "+ "%.2f%n",monthlyRate);
} else if (numberOfRates>=13 || numberOfRates <=24 ) {
loanInterestRate=1.05;
monthlyRate = (productCost*loanInterestRate)/numberOfRates;
System.out.printf("Your monthly rate is: "+ "%.2f%n",monthlyRate);
} else if (numberOfRates >=25|| numberOfRates<=48){
loanInterestRate=1.1;
monthlyRate = (productCost*loanInterestRate)/numberOfRates;
System.out.printf("Your monthly rate is: "+ "%.2f%n",monthlyRate);
}
}
}
And the main method only calling the method from the other class.
public class MonthlyRate {
public static void main(String[] args) {
Calculator calc = new Calculator();
calc.print();
// TODO code application logic here
}
}
And what is the problem, I don't know how to return the "double productCost" from the method "print()". productCost is taking from the input and this is double but NetBeans showing me that it's not correct type. Can anybody help me understand where is the problem?
Simply do
return productCost;
return is a keyword, not a variable. It 'returns' the given value and exits the function, so that the entity calling the function can do this:
public static void main(String[] args) {
...
double cost = calc.print(); // note calc.print() PRODUCES a value, which we assign to `cost`
...
}
You can then do whatever you want with cost (or whatever you choose to name the variable), including passing it to another function.
Your program needs changes in a few places. I have done those changes and written below the updated program:
import java.util.Scanner;
class Calculator {
Scanner sc = new Scanner(System.in);
double productCost;
int numberOfRates;
double loanInterestRate;
double monthlyRate;
void print() {
Calculator c = new Calculator();
System.out.println("Enter the value of your product from 100 to 10 000 : ");
productCost = sc.nextDouble();
if (productCost < 100) {
System.out.println("You have to choose price between 100 to 10000. Try again: ");
c.print();
} else if (productCost > 10000) {
System.out.println("You have to choose price between 100 to 10000. Try again: ");
c.print();
} else if (productCost >= 100 || productCost <= 10000) {
print1(productCost);
}
}
void print1(double productCost) {
Calculator c = new Calculator();
System.out.println("Now enter how many rates do you want to pay from 6 to 48: ");
numberOfRates = sc.nextInt();
if (numberOfRates < 6) {
System.out.println("You can't choose this number of rates. Choose between 6-48: ");
c.print1(productCost);
} else if (numberOfRates > 48) {
System.out.println("You can't choose this number of rates. Choose between 6-48: ");
c.print1(productCost);
} else if (numberOfRates >= 6 || numberOfRates <= 12) {
loanInterestRate = 1.025;
monthlyRate = (productCost * loanInterestRate) / numberOfRates;
System.out.printf("Your monthly rate is: " + "%.2f%n", monthlyRate);
} else if (numberOfRates >= 13 || numberOfRates <= 24) {
loanInterestRate = 1.05;
monthlyRate = (productCost * loanInterestRate) / numberOfRates;
System.out.printf("Your monthly rate is: " + "%.2f%n", monthlyRate);
} else if (numberOfRates >= 25 || numberOfRates <= 48) {
loanInterestRate = 1.1;
monthlyRate = (productCost * loanInterestRate) / numberOfRates;
System.out.printf("Your monthly rate is: " + "%.2f%n", monthlyRate);
}
}
}
public class MonthlyRate {
public static void main(String[] args) {
Calculator calc = new Calculator();
calc.print();
// TODO code application logic here
}
}
It is easy to understand the changes after comparing your program with this updated program. Nevertheless, feel free to let me know if you need any further help on this.

Identifying what part of the code is responsible for making the program do what the user say in the number of tests

This program is about a user being prompted to enter how many tests they want the average of and then the program will ask them to input however many they said. I am having trouble identifying how the code does that. What makes it know to return as many inputs as the user asks. Thank you!
I looked at the while function but that seems to only be if the user inputs something like 0 or a negative number (I think).
import java.util.Scanner;
public class average {
public static String getLetterGrade(double average) {
if (average < 60) {
return "F";
} else if (average < 70) {
return "D";
} else if (average < 80) {
return "C";
} else if (average < 90){
return "B";
}
else;{
return "A";
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Welcome, please type your first name. ");
String name = scan.nextLine();
System.out.println("Welcome, please type your last name. ");
String last = scan.nextLine();
int n;
System.out.println("How many tests would you like the average of?");
n = scan.nextInt();
while(n<0) {
System.out.println("Invalid input.");
System.out.println("How many tests would you like the average
of?");
n = scan.nextInt();
}
double sum = 0, grade;
System.out.println("Enter " + n + " scores.");
for(int i = 0;i<n;i++) {
grade = scan.nextDouble();
sum += grade;
}
double average = (sum/n);
System.out.println("Okay " + name.charAt(0) + last.charAt(0) + ", your
average score is " + (average));
System.out.println("Your letter grade is a " +
getLetterGrade(average));
}
}
There are no errors in this program it runs and does what it is suppose to do.

Write a program that reads student scores, gets the best score, and then assigns grades

Can someone please tell me why my code is not providing the correct output? Here aare the instructions "
I need to write a program that reads student scores, gets the best
score, and then assigns grades based on the following scheme:
1) Grade is A if score is >= best - 10
2) Grade is B if score is >= best - 20;
3) Grade is C if score is >= best - 30;
4) Grade is D if score is >= best - 40;
5) Grade is F otherwise.
The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. My problem comes from pulling the grades from an array, this is what I have so far:
// Here is my code. Thank You
import java.util.Scanner; // imports the scanner function
public class NBpractice { //class is formed
public static void main(String []args) { // main method
// user input is asked for the number of students
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int studentNum = input.nextInt();
//user input is asked for students scores
Scanner input2 = new Scanner(System.in);
System.out.print("Enter " + studentNum + " scores: ");
int scores = input2.nextInt();
int best = 80;
char letterGrade;
int scoresArray[] = new int[studentNum]; // array is created and holds the # of place values as students
for (int i = 0; i < scoresArray.length; i++) { // for loop created
scoresArray[i] = input2.nextInt(); //array values are assigned to user's input
best = scoresArray[0];
if (best < scoresArray[i]) {
best = scoresArray[i];
}
//-----------------------------------------------------------------------------
if (scores >= (best - 10)) {
letterGrade = 'A';
}
else if (scores >= (best - 20)) {
letterGrade = 'B';
}
else if (scores
>= (best - 30)) {
letterGrade = 'C';
}
else if (scores >= (best - 30)) {
letterGrade = 'D';
}
else {
letterGrade = 'F';
}
System.out.println("Student " + i + " Score is " + scoresArray[i] + " and grade is: " + letterGrade );
}
//------------------------------------------------------------
}
}
Some pointers...
This: System.out.print("Enter " + studentNum + " scores: "); and int scores = input2.nextInt(); need to go in the for loop body.
Use the for loop to populate the array.
Once that the for loop is executed, find the best (highest) score in the array.
Use another for loop to sort out the grades.
As is, your program will only ask for the grades and pretty much assumes that the best grade is 80, which might not always be the case.
You'll need two separate for loops. One to read the grades, and get the best, and the second for loop to normalize the grades.
int[] scores = new int[amount];
int best = -1;
for(int i = 0; i < amount; i++)
{
scores[i] = in.nextInt();
if(scores[i] > best)
best = scores[i];
}
System.out.println(Arrays.toString(scores));
// Now that we have the best, we can normalize
// the rest of the scores based on the best
// and assign the corresponding letter grade.
String[] grades = new String[amount];
for(int i = 0; i < amount; i++)
{
int score = scores[i] * 100 / best;
if(score >= 90)
grades[i] = "A";
else if(score >= 80)
grades[i] = "B";
else if(score >= 70)
grades[i] = "C";
else if(score >= 60)
grades[i] = "D";
else
grades[i] = "F";
scores[i] = score;
}
System.out.println(Arrays.toString(scores));
System.out.println(Arrays.toString(grades));
Test input 80 60 75 83 67 outputs:
[80, 60, 75, 83, 67]
[96, 72, 90, 100, 80]
[A, C, A, A, B]
I would recommend using a Student class and not work with parallel lists or arrays. A Student class can for example look like this:
class Student {
int score;
String grade; // could also be an Enum
public int getScore() {
return this.score;
}
public void setScore(int score) {
this.score = score;
}
public String getGrade() {
return this.grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
#Override
public String toString() {
return "Student{" + "score=" + score + ", grade='" + grade + '\'' + '}';
}
}
You can then make instance of the Students and add them to an ArrayList in you public static void main.
I think you have to use two loops because you cannot know beforehand what the best grade will be. In your main you can make enter the students add them to a List and compare their grades;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int highScore = 0;
int numOfStudent = input.nextInt();
List<Student> studentList = new ArrayList<>();
for (int i = 1; i <= numOfStudent; i++) { // you might want to add Exception handling here, by surrounding it with a try / catch or do more checks than only i <= numOfStudent
System.out.printf("please fill in the score of student no %d \n", i);
int score = input.nextInt();
Student student = new Student();
student.setScore(score);
if (score > highScore) {
highScore = score;
}
studentList.add(student);
}
System.out.println("these are the scores and grades of the Students");
for (Student s : studentList) {
if (s.getScore() >= highScore - 10) {
s.setGrade("A");
}
else if (s.getScore() >= highScore - 20) {
s.setGrade("B");
}
else if (s.getScore() >= highScore - 30) {
s.setGrade("C");
}
else if (s.getScore() >= highScore - 40) {
s.setGrade("D");
}
else {
s.setGrade("F");
}
System.out.println(s);
}
}
package Chapter7;
import java.util.Scanner;
public class Exercise7_1 {
public static void main(String[] args) {
// Assign grades
Scanner input = new Scanner(System.in);
int numStudents;
int[] scores;
int best;
System.out.println("Enter the number of students: ");
numStudents = input.nextInt();
scores = new int[numStudents];
System.out.println("Enter " + numStudents + " scores: ");
for (int i = 0; i < numStudents; i++) {
scores[i] = input.nextInt();
}
displayGrades(findBestScore(scores), scores);
}
public static int findBestScore(int[] scores) {
int best = scores[0];
for (int i = 1; i < scores.length-1; i++) {
if (scores[i] > best)
best = scores[i];
}
return best;
}
public static void displayGrades(int best, int[] scores ) {
char grade = ' ';
for (int i = 0; i < scores.length; i++) {
if (scores[i] >= best-10)
grade = 'A';
else if (best - 10 > scores[i] && scores[i] >= best - 20)
grade = 'B';
else if (best - 20 > scores[i] && scores[i] >= best -30)
grade = 'C';
else if (best - 30 > scores[i] && scores[i] >= best -40)
grade = 'D';
else if (best - 40 > scores[i])
grade = 'F';
System.out.println("Student " + i + " score is " + scores[i] + " and grade is " + grade);
}
}
}

Finding the highest and the lowest value

I have this assignment I gotta do. It looks good, except for the getHighest output and the getLowest result. Here's my code:
KNW_CourseGradesV2 Class:
public class KNW_CourseGradesV2 implements KNW_Analyzable
{
//Declare array variable
private KNW_GradedActivity[] grades = new KNW_GradedActivity[4];
String results;
/**
* Constructor
* */
public KNW_CourseGradesV2()
{
}
public void setLab(KNW_GradedActivity lab)
{
grades[0] = lab;
}
public void setPassFailExam(KNW_GradedActivity pfe)
{
grades[1] = pfe;
}
public void setEssay(KNW_GradedActivity essay)
{
grades[2] = essay;
}
public void setFinalExam(KNW_FinalExam fe)
{
grades[3] = fe;
}
public void setTotalGrade(KNW_GradedActivity tg)
{
grades[4] = tg;
}
public String toString()
{
//Lay out all of the scores
return "Lab Score: " + grades[0].getScore() +
"\tGrade: " + grades[0].getGrade() +
"\nPass/Fail Exam: " + grades[1].getScore() +
"\tGrade: " + grades[1].getGrade() +
"\nEssay Score: " + grades[2].getScore() +
"\tGrade: " + grades[2].getGrade() +
"\nFinal Exam Score: " + grades[3].getScore() +
"\tGrade: " + grades[3].getGrade();
}
//Find the average of the grades
public double getAverage()
{
double sum = 0.0;
double average = 0.0;
double total = 0.0;
//For loop to calc. the average
for(int i =0; i<grades.length; i++)
{
total =+ grades[i].getScore();
average = sum/grades.length;
}
return average;
}
public KNW_GradedActivity getHighest()
{
double highest = grades[0].getScore();
for(int i = 0; i < grades.length; i++)
{
if(grades[i].getScore() > highest)
{
highest = grades[i].getScore();
}
}
//Created KNW_GradedActivity object to bring the highest number
//into the setScore method so it can be a double
KNW_GradedActivity gaH = new KNW_GradedActivity();
gaH.setScore(highest);
return gaH;
}
public KNW_GradedActivity getLowest()
{
double lowest = grades[0].getScore();
for(int i = 0; i < grades.length; i++)
{
if(grades[i].getScore() > lowest)
{
lowest = grades[i].getScore();
}
}
//Samething here, just doing it for the lowest number
KNW_GradedActivity gaL = new KNW_GradedActivity();
gaL.setScore(lowest);
return gaL;
}
}
KNW_Analyzable Class:
public interface KNW_Analyzable
{
double getAverage();
KNW_GradedActivity getHighest();
KNW_GradedActivity getLowest();
}
KNW_GradedActivity Class:
public class KNW_GradedActivity
{
private double score; // Numeric score
/**
The setScore method sets the score field.
#param s The value to store in score.
*/
public void setScore(double s)
{
score = s;
}
/**
The getScore method returns the score.
#return The value stored in the score field.
*/
public double getScore()
{
return score;
}
/**
The getGrade method returns a letter grade
determined from the score field.
#return The letter grade.
*/
public char getGrade()
{
char letterGrade;
if (score >= 90)
letterGrade = 'A';
else if (score >= 80)
letterGrade = 'B';
else if (score >= 70)
letterGrade = 'C';
else if (score >= 60)
letterGrade = 'D';
else
letterGrade = 'F';
return letterGrade;
}
}
And here is the output I get. I will just show the problem I am facing, won't show all of the output.
Output:
Average: 0.0
Highest: KNW_GradedActivity#565d3fa7
Lowest: KNW_GradedActivity#655c4395>
I have been trying for about a week to figure this out and find what is happening, and I can't seem to find it.
Notice that in the return of your methods, you are actually returning gaH and gaL, both of which are KNW_GradedActivity Objects. If you want to see the score, you should probably return gaH.getScore() and gaL.getScore().
Why not to use Stream and DoubleSummaryStatistics to get the stats? Let the api do all the calculations:
List<KNW_GradedActivity> grades = Arrays.asList(new KNW_GradedActivity(), new KNW_GradedActivity(), new KNW_GradedActivity());
grades.get(0).setScore(91);
grades.get(1).setScore(81);
grades.get(2).setScore(71);
DoubleSummaryStatistics statistics = grades.stream().
collect(Collectors.summarizingDouble(KNW_GradedActivity::getScore));
System.out.println(statistics);
// DoubleSummaryStatistics{count=3, sum=243.000000, min=71.000000, average=81.000000, max=91.000000}
Another alternative is to override toString method in your KNW_GradedActivity class:
#Override
public String toString() {
return "{" +
"score=" + score +
", grade='" + getGrade() + '\'' +
'}';
}
This way you dont have to change your actual print statement and will have a nice output combining your score and grade. It will look like:
{score=90.0, grade='A'}

Categories

Resources