Question

JAVA

3files seprate

1.Classroom.java

2.ClassroomTester.java (provided)

3.Student.java(provided)

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 Arraylists toString methed Provide Javadoc

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<Double> grades1 = new ArrayList<>();
       grades1.add(82.0);
       grades1.add(91.5);
       grades1.add(85.0);
       Student student1 = new Student("Srivani", grades1);
      
       ArrayList<Double> 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<Double> 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<Double> 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<Double> 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<Double> 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;
    }

}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Classroom.java

import java.util.ArrayList;

public class Classroom {

private ArrayList<Student> arl=null;

public Classroom() {

arl=new ArrayList<Student>();

}

public void add(Student s)

{

arl.add(s);

}

public String hasAverageGreaterThan(double target)

{

for(int i=0;i<arl.size();i++)

{

if(arl.get(i).getAverage()>target)

return arl.get(i).getName();

}

return "";

}

public ArrayList<String> getStudents()

{

ArrayList<String> studs=new ArrayList<String>();

for(int i=0;i<arl.size();i++)

{

studs.add(arl.get(i).getName());

}

return studs;

}

public Student bestStudent()

{

if(arl.size()==0)

return null;

else

{

double max=arl.get(0).getAverage();

int indx=0;

for(int i=0;i<arl.size();i++)

{

if(max<arl.get(i).getAverage())

{

max=arl.get(i).getAverage();

indx=i;

}

}

return arl.get(indx);

}

}

@Override

public String toString() {

return arl +"";

}

}

____________________

Student.java

import java.util.ArrayList;
/**
* Models a student with a name and collection
* pf grades
*/
public class Student
{
private String name;
private ArrayList<Double> 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<Double> 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;
}

}

___________________

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<Double> grades1 = new ArrayList<>();
grades1.add(82.0);
grades1.add(91.5);
grades1.add(85.0);
Student student1 = new Student("Srivani", grades1);
  
ArrayList<Double> 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<Double> 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<Double> 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: []");
  
}
}

____________________

Output:

[[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]]]
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]]]
>90 GPA: Carlos
Expected: Carlos
>99 GPA:
Expected:
Maria
Expected: Maria
[Srivani, Carlos, Maria, Fred]
Expected: [Srivani, Carlos, Maria, Fred]
[]
Expected: []
>90 GPA:
Expected:
[]
Expected: []

_______Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** *...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, How can I make the program print out "Invalid data!!" and nothing else if the...

    Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...

  • Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models...

    Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models a person */ public class Person { private String name; private String gender; private int age; /** * Consructs a Person object * @param name the name of the person * @param gender the gender of the person either * m for male or f for female * @param age the age of the person */ public Person(String name, String gender, int age) {...

  • JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {    ...

    JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {     /**      * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList      * containing all the indexes of Strings in arr that match String s. For this method, two Strings,      * p and q, match when p.equals(q) returns true or if both of the compared references are null.      *      * @param s The string...

  • Complete the following Java class. In this class, inside the main() method, user first enters the...

    Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in...

    Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author fenghui */ public class Course {     private String cName;     private ArrayList<Subject> cores;     private ArrayList<Major> majors;     private ArrayList<Subject> electives;     private int cCredit;          public Course(String n, int cc){         cName = n;         cCredit = cc;         cores = new ArrayList<Subject>(0);         majors =...

  • Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already...

    Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already have from previous labs) Contents Based on the graphics you learned this week Create an instance (an object, i.e., st1) of student in myJPanel Display his/her basic information Display for 10 times what he/she is up to (using the method whatIsUp() that your student class already has) -------------------------------------------------------------------------------------------------- \\app.java public class app { public static void main(String args[]) { myJFrame mjf = new myJFrame();...

  • please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the...

    please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the program is supposed to read from my input file and do the following        1) print out the original data in the file without doing anything to it.        2) an ordered list of all students names (last names) alphabetically and the average GPA of all student togther . 3) freshman list in alphabeticalorder by last name with the average GPA of the freshmen...

  • Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with...

    Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) {     myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame {    myJPanel6 p6;    public myJFrame6 ()    {        super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField        p6 = new myJPanel6(); //------------------------------------------------------...

  • I need to change the following code so that it results in the sample output below...

    I need to change the following code so that it results in the sample output below but also imports and utilizes the code from the GradeCalculator, MaxMin, and Student classes in the com.csc123 package. If you need to change anything in the any of the classes that's fine but there needs to be all 4 classes. I've included the sample input and what I've done so far: package lab03; import java.util.ArrayList; import java.util.Scanner; import com.csc241.*; public class Lab03 { public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT