Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey, I hava problem with my code I cannot figure out where is the problem... public class Student { private String name; private ArrayList tests

Hey,

I hava problem with my code I cannot figure out where is the problem...

 public class Student { private String name; private ArrayList tests = new ArrayList(); private ArrayList assignments = new ArrayList(); public Student(String n) { name = n; } public void addTest(double score) { tests.add(score); } public void addAssignment(double score) { assignments.add(score); } public double getAverage(ArrayList a) { if (a.size() = 0) return 0; else { double total = 0; for (int i=0; i< a.size(); i++) { total += a.get(i) } return total/a.size(); } } public double getTestAverage() { return getAverage(tests); } public double getAssignmentAverage() { return getAverage(assignments); } public double calcOverallAverage(double testPct, double assignPct) { return testPct*getTestAverage() + assignPct*getAssignmentAverage(); } public String toString() { return name + " has test average: " + getTestAverage() + " and assignment average: " + getAssignmentAverage(); } } 

 public class Driver { public static void main(String[] args) { Student s1 = new Student("Sandy"); s1.addAssignment(78.0); s1.addAssignment(92.5); s1.addAssignment(87.5); s1.addAssignment(77.5); s1.addTest(69.5); s1.addTest(83.0); printStudentInfo(s1); Student s2 = new Student("Tommy"); double[] scores = {77.0, 82, 95, 98, 83.5, 100, 76, 88.5, 91.5, 85}; for (int i=0; i<=scores.length; i+=2) { s2.addAssignment(scores[i]); s2.addTest(scores[i+1]); } printStudentInfo(s1); } public void printStudentInfo(Student s) { System.out.println(s); double avg1 = s.calcOverallAverage(0.50, 0.50); double avg2 = s.calcOverallAverage(0.60, 0.40); System.out.printf("Overall average by 50/50 and 60/40: %5.2f and %5.2f ", avg1, avg2); } } 

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

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago

Question

Understand what a service-oriented culture is.

Answered: 1 week ago

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago