Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2.2 You Trylt: Grader Create a class called Top2Grader that calculates a student's grade by averaging the student's top two highest grades. If there is

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

2.2 You Trylt: Grader Create a class called Top2Grader that calculates a student's grade by averaging the student's top two highest grades. If there is only one grade, then that grade should be returned. If there are no grades, then o. should be returned. Finally, your Top2Grader should override tostring so that it returns "Top2Grader'. Please refer to the class diagram below to determine how your class should be constructed: Main Grader private integer m_aryo public Grader(Integer aryt) public double calculateGradeo public Integer getGrades public String toStringo is-a Top 2 Grader is-a is-a MedianGrader CurveGrader private int m_curve public CurveGrader(Integer aryll, int curve) public double calculateGradeo public String toStringo public Median Grader(Integer aryD) public double calculateGrade public String toStringo The Main, Grader, CurverGrader, and MedianGrader classes have been provided for you and are read only. Your only task is to create the Top 2 Grader class. 299276.011062 LAB ACTIVITY 221: YouTrylt: Grader 0/10 Submission Instructions Downloadable files Main.java Grader.java CurveGrader.java MedianGrader.java Download Compile command javac Main.java Grader.java CurveGrader.java MedianGrader.java Top2Grader.java -Xlint:all -encoding utf-8 We will use this command to compile your code Upload your files below by dragging and dropping into the area or choosing a file on your hard drive. Top2Grader.java Drag file here or Choose on hard drive. Grader.java Main.java import java.util."; 1 2 4. 5 6 17 8 9 19 public class Main { public static void main(String[] args) { Main m = new Main(); m.go(); } private void go() { List graders = getGraders(); for (Grader g : graders) { System.out.printf("%s calculates %.2f%n", g, g.calculateGrade()); } } private List getGraders() { Integer ary[] = new Integer[] {67, 92, 78, 82, 73, 91, 87, 81}; List ret = new ArrayList(); 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 39 31 32 33 34 35 36 37 38 39 Grader g1 = new Grader(ary); ret.add(81); Grader g2 new CurveGrader(ary, 5); ret.add(82); Grader g3 = new MedianGrader(ary); ret.add(83); Grader g4 = new Top2Grader(ary); ret.add(94); return ret; } Grader.java 1 IN 2 3 4. Main.java Flass Grader { private Integer m_ary[]; public Grader(Integer ary[]) { m_ary = ary; } 7 7 8 public double calculateGrade() { double total 0.0; for (int i : m_ary) total += i; return total/m_ary.length; } 19 11 12 13 14 15 1.6 17 18 19 20 21 22 23 public Integer[] getGrades() { return m_ary; } @Override public String toString() { return "Grader"; } } MedianGrader.java Curve Grader.java 1 class CurveGrader extends Grader 2 { 3 3 private int m_curve; 4 6 public CurveGrader(Integer ary[], int curve) { super (ary); m_curve = curve; } 10 11 12 13 - 14 15 16 17 18 19 29 -21 @Override public double calculateGrade() { double ave = super.calculateGrade(); return ave + m_curve; } @Override public String toString() { return String.format("Curve Grader (%d)", m_curve); } } } MedianGrader.java 1 N CurveGrader.java import java.util.*; class MedianGrader extends Grader { public MedianGrader(Integer ary[]) { super(ary); } 3 4 5 6 7 8 ret = 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24. 25 26 27 28 29 @Override public double calculateGrade() { double ret = 0.0; Arrays.sort(getGrades()); if (getGrades ().length % 2 == 1) { int middle = (getGrades().length/2); getGrades([middle]; } else { int left = (getGrades().length/2)-1; int right = (getGrades().length/2); (getGrades()[left] + getGrades() [right])/2.8; } return ret; } ret = @Override public String toString() { return "Median Grader"; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

=+4 How did it affect HR?

Answered: 1 week ago