Question

Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available.

I will paste both of the simple .JAVA codes below

Given a class called student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available LAB ACTIVTY 10.12.1: zyLab: Deans List 0/2 Files provided by your instructor Course.java and Student.java Download Current file: Course·Java Load default template ▼ 1 import java.util.; 2 import java.io.* 4 * A list of students in a course 5 碜 碜 6 public class Course / /collection of Students private ArrayList(Student) roster; 10 12 Constructor for objects of class Course 14 public Course)f 15 16 17 rosternew ArrayList<Student> O; 19 return a new ArrayList with all Students that have 20 a GPA of at least 3.5

COURSE.JAVA

import java.util.*;

import java.io.*;

/******************************************************

* A list of students in a course

*****************************************************/

public class Course{

    /** collection of Students */

    private ArrayList<Student> roster;

/*****************************************************

Constructor for objects of class Course

*****************************************************/

    public Course(){

        roster = new ArrayList<Student>();

  }

/*****************************************************

@return a new ArrayList with all Students that have

a GPA of at least 3.5

*****************************************************/   

    public ArrayList<Student> getDeansList(){

        /** Your code goes here */

       

    }

   

/*****************************************************

Add a student to the course

*****************************************************/

    public void addStudent(Student s){

        roster.add(s);

    }

   

/*****************************************************

Main method for testing

*****************************************************/

    public static void main(String args[]){

       Course cis162 = new Course();

       cis162.addStudent(new Student("Henry", "Cabot", 3.5));

       cis162.addStudent(new Student("Brenda", "Stern", 2.0));

       cis162.addStudent(new Student("Lynda", "Robison", 3.2));

       cis162.addStudent(new Student("Jane", "Flynn", 3.9));

       ArrayList<Student> stars = cis162.getDeansList();

    }   

}

STUDENT.JAVA

import java.text.*;

/*************************************************

* A simple student class including name and gpa.

*

* @author Scott Grissom

* @version March 21, 2016

*************************************************/

public class Student{

   

    /** student name */

    private String first, last;

   

    /** student GPA */

    private double gpa;

/************************************************

Constructor for Student

************************************************/

    public Student(String f, String l, double d){

        first = f;

        last = l;

        gpa = d;

    }

   

/************************************************

@return GPA

************************************************/

    public double getGPA(){

        return gpa;

    }

/************************************************

@return last name

************************************************/

    public String getLast(){

        return last;

    }

   

/************************************************

to String

@return String representation of the object

************************************************/    

    public String toString(){

        DecimalFormat fmt = new DecimalFormat("#.0");

        return first + " " + last + " " + fmt.format(gpa);

    }

   

    public static void main (String [] args){

        Student s = new Student ("Henry", "Walker", 3.6);

        System.out.println(s);

    }

}

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

Below is your code: -

public ArrayList<Student> getDeansList() {

/** Your code goes here */

//create a empty list

ArrayList<Student> deansList = new ArrayList<>();

//loop through the roster

for (Student student : roster) {

//if GPA is atleast 3.5, add to list

if(student.getGPA() >= 3.5) {

deansList.add(student);

}

}

//return the list.

return deansList;

}

After adding the code in the class and chaning the main method as below: -

public static void main(String args[]) {

Course cis162 = new Course();

cis162.addStudent(new Student("Henry", "Cabot", 3.5));

cis162.addStudent(new Student("Brenda", "Stern", 2.0));

cis162.addStudent(new Student("Lynda", "Robison", 3.2));

cis162.addStudent(new Student("Jane", "Flynn", 3.9));

ArrayList<Student> stars = cis162.getDeansList();

for (Student student : stars) {

System.out.println(student);

}

}

We get the output as below

Henry Cabot 3.5
Jane Flynn 3.9

Add a comment
Know the answer?
Add Answer to:
Given a class called Student and a class called Course that contains an ArrayList of Student....
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
  • Write a class called Course_xxx that represents a course taken at a school. Represent each student...

    Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class...

  • I asked this a little bit ago but didn't clarify exactly what I needed, so I'm...

    I asked this a little bit ago but didn't clarify exactly what I needed, so I'm asking again...I've attached my code below the question. Thanks! Do not change the original contract of the Course class. Instead, ONLY change the implementation of property students, from an array to and ArrayList, and update any methods in class Course that access students to reflect ArrayList. The methods are overridden. That means that you do not need to change the header for methods, only...

  • Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.

    Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.Given files: main.cpp - contains the main function for testing the program.Course.cpp - represents a course, which contains a vector of Student objects as a course roster. (Type your code in here)Course.h - header file for the Course class.Student.cpp - represents a classroom student, which has three data members: first name, last name, and...

  • public class Scheduler {    private List<Course> classes;    private List<Student> students;    public Scheduler() {...

    public class Scheduler {    private List<Course> classes;    private List<Student> students;    public Scheduler() {        classes = new ArrayList<Course>();        students = new ArrayList<Student>();    }       public void addCourse(Course course) {        this.classes.add(course);    }    public List<Course> getCourses() {        List<Course> newCList=new ArrayList<>();        for(int i=0;i<classes.size();i++){        newCList.add(classes.get(i));        }        return newCList;    }    public void addStudent(Student student) {        this.students.add(student);    }   ...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The...

    Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The clone method must allow a deep copy on the students field. In addition, add the equals(Object o) and the toString() methods. Write a test program to invoke the compareTo, clone, equals, and toString methods in a meaningful way. Below is the Listing from the book that needs to be rewritten public class Course {    private String courseName;    private String[] students = new...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

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