Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** * Write a description of class UniversityTester here. * *

JAVA

3files seprate

1.Classroom.java

2.ClassroomTester.java (provided)

3.Student.java(provided)

image text in transcribed

Use the following files:

ClassroomTester.java

import java.util.ArrayList; /** * Write a description of class UniversityTester here. * * @author (your name) * @version (a version number or a date) */ public class ClassroomTester { public static void main(String[] args) { ArrayList grades1 = new ArrayList(); grades1.add(82.0); grades1.add(91.5); grades1.add(85.0); Student student1 = new Student("Srivani", grades1); ArrayList grades2 = new ArrayList(); grades2.add(95.0); grades2.add(87.0); grades2.add(99.0); grades2.add(100.0); Student student2 = new Student("Carlos", grades2); ArrayList grades3 = new ArrayList(); grades3.add(100.0); grades3.add(98.0); grades3.add(100.0); grades3.add(97.0); Student student3 = new Student("Maria", grades3); ArrayList grades4 = new ArrayList(); grades4.add(80.0); grades4.add(70.0); grades4.add(82.0); grades4.add(75.0); Student student4 = new Student("Fred", grades4); Classroom myClass = new Classroom(); myClass.add(student1); myClass.add(student2); myClass.add(student3); myClass.add(student4); System.out.println(myClass); System.out.println("Expected: [[Student:name=Srivani,grades=[82.0, 91.5, 85.0]], [Student:name=Carlos,grades=[95.0, 87.0, 99.0, 100.0]], [Student:name=Maria,grades=[100.0, 98.0, 100.0, 97.0]], [Student:name=Fred,grades=[80.0, 70.0, 82.0, 75.0]]]"); System.out.println(">90 GPA: " + myClass.hasAverageGreaterThan(90.0)); System.out.println("Expected: Carlos"); System.out.println(">99 GPA: " + myClass.hasAverageGreaterThan(99)); System.out.println("Expected: "); Student best = myClass.bestStudent(); if (best != null) { System.out.println(best.getName()); System.out.println("Expected: Maria"); } System.out.println(myClass.getStudents()); System.out.println("Expected: [Srivani, Carlos, Maria, Fred]"); //test with an empty classroom myClass = new Classroom(); System.out.println(myClass); System.out.println("Expected: []"); System.out.println(">90 GPA: " + myClass.hasAverageGreaterThan(90.0)); System.out.println("Expected: "); best = myClass.bestStudent(); if (best != null) { System.out.println(best.getName()); } System.out.println(myClass.getStudents()); System.out.println("Expected: []"); } } 

Student.java

import java.util.ArrayList; /** * Models a student with a name and collection * pf grades */ public class Student { private String name; private ArrayList grades; /** * Constructor for Student with name * and list of grades * @param name the name of the student * @param list the list of grades */ public Student(String name, ArrayList list) { this.name = name; this.grades = list; } /** * Gets the name of the student * @return the student's name */ public String getName() { return name; } /** * Gets the average of this student's grades * @return the average or 0 if there are no grades */ public double getAverage() { double sum = 0; for ( double g : grades) { sum = sum + g; } double average = 0; if (grades.size() > 0) { average = sum / grades.size(); } return average; } /** * @overrides */ public String toString() { String s = "[Student:name=" + name + ",grades=" + grades.toString() +"]"; return s; } }
u are given a Stadant.clss. (Copy it into Fclipse) A Stndant. hasa name and an Array ist af grades (Doubles) as stan Write a class narned classroom which manages Student objects ou will provide the following variahles. publio classroonno-arguent constructor *publio void add (stuient s adds the student to this Classroom (to an ArrayList .publiu Srins sAvraueGredlerTMan (duble Laryel) gcts the name of the first student in the Classroom who has an average greater than the target or the empty string. Do not use break Do not return from the middic of the loop, Use a boolcan flag it ynu need to terminate early. . publiu AayLislkstring? gesudnts 0 gets an ArayLIst Strings conta nlng the names ot all the Students In this Classroom. . publie Student beststadent.) gets the Student with the highest average in this classroom or null there are no students publle string tostring0 gesng represent ion using Arraylist's toString methed Provide Javadoc

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

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions