Question: Please help me, this is supposed to be in Java OOP thank you so much in advance. Here's a template for Course.java as well (Template
Please help me, this is supposed to be in Java OOP
thank you so much in advance.
Here's a template for Course.java as well (Template will be all the way at the bottom).
Complete the Course.java class and use the TestCourse.java class to test your work. The methods and constructors you are to work on are the following:
-
Course (constructor to initialize name and Faculty data fields)
-
addStudent( method to add a Student object to the roster data field)
-
getGPAs( method that returns an array of doubles whose elements are the GPA of each Student object in roster)
-
getStudents( method that returns an array of Strings that represent Student names, first and last )
-
getClassGrades( method that returns an array of integers whose elements are the grade for each Student object for this Course)
Classes: MATH 194, ENGR 212, CS 231, PHYS 200
Here is my code from the previous Assignment. I don't know what you mean by add classes code. This is all I have:
public class Faculty { private String firstName; private String lastName; private String levelOfEducation; private String academicBackground; private String department; public Faculty(String firstName,String lastName,String levelOfEducation,String academicBackground,String department) { this.firstName = firstName; this.lastName = lastName; this.levelOfEducation = levelOfEducation; this.academicBackground = academicBackground; this.department = department; } // setter public void setFirstName(String firstName) {this.firstName = firstName;} public void setLastName(String lastName) {this.lastName = lastName;} public void setLevelOfeducation(String levelOfEducation) {this.levelOfEducation = levelOfEducation;} public void setGetAcademicBackground(String academicBackground) {this.academicBackground = academicBackground;} public void setDepartment(String department) {this.department = department;} //getter public String getFirstName() {return firstName;} public String getLastName() {return lastName;} public String getLevelOfEducation() {return levelOfEducation;} public String getAcademicBackground() {return academicBackground;} public String getDepartment() {return department;} public String toString() { return "Faculty:"+" "+firstName +" "+lastName+" "+ levelOfEducation +" in " + academicBackground +" Department: "+department; } public static void main(String[] args) { Faculty gutierrez = new Faculty("Octavio", "Ortiz", "MS", "Aerospace Engineering", "Math, Engineering, Computer Science" ); System.out.println(gutierrez); } }
The toString method has been implemented for you, such that the following output is display when TestCourse.java is executed:
Sample Output: (Note that the Student objects to be added to the Course are randomized)
Student Name: Tara Downs Email: TDowns@somedomain.com Classes: [PHYS 200, ENGR 212, CS 231, MATH 194] Grades: [67, 97, 65, 88] Student Name: Dennis Ortiz Email: DOrtiz@somedomain.com Classes: [MATH 194, ENGR 212, CS 231, PHYS 200] Grades: [84, 87, 72, 92] Student Name: Olivia Little Email: OLittle@somedomain.com Classes: [ENGR 212, MATH 194, PHYS 200, CS 231] Grades: [72, 75, 100, 74] Student Name: Tara Dale Email: TDale@somedomain.com Classes: [ENGR 212, MATH 194, CS 231, PHYS 200] Grades: [81, 74, 60, 66] Student Name: Nicolas Reid Email: NReid@somedomain.com Classes: [ENGR 212, CS 231, PHYS 200, MATH 194] Grades: [89, 63, 92, 69] Student Name: Jason Donovan Email: JDonovan@somedomain.com Classes: [MATH 194, PHYS 200, ENGR 212, CS 231] Grades: [80, 95, 80, 60] Student Name: Trizten Reid Email: TReid@somedomain.com Classes: [PHYS 200, MATH 194, CS 231, ENGR 212] Grades: [76, 100, 95, 73] Student Name: Maria Cooks Email: MCooks@somedomain.com Classes: [PHYS 200, CS 231, MATH 194, ENGR 212] Grades: [73, 93, 96, 68] Student Name: Oscar Ortiz Email: OOrtiz@somedomain.com Classes: [CS 231, ENGR 212, MATH 194, PHYS 200] Grades: [83, 91, 61, 82] Student Name: John Lopez Email: JLopez@somedomain.com Classes: [CS 231, MATH 194, PHYS 200, ENGR 212] Grades: [61, 63, 72, 74] CS 231 Faculty: Octavio Ortiz MS in Aerospace Engineering Department: Math, Engineering and Comp Sci Name: Tara Downs Grade: 65 GPA: 2.250000 Name: Dennis Ortiz Grade: 72 GPA: 3.000000 Name: Olivia Little Grade: 74 GPA: 2.500000 Name: Tara Dale Grade: 60 GPA: 1.750000 Name: Nicolas Reid Grade: 63 GPA: 2.250000 Name: Jason Donovan Grade: 60 GPA: 2.750000 Name: Trizten Reid Grade: 95 GPA: 3.000000 Name: Maria Cooks Grade: 93 GPA: 2.750000 Name: Oscar Ortiz Grade: 83 GPA: 2.750000 Name: John Lopez Grade: 61 GPA: 1.500000
In the Sample Output, the grade each Student object has in CS 231 is printed at the end (from Course.java toString). It can be cross-referenced with each Student object's classes and grades array. That is, John Lopez has a 61 in CS 231. CS 231 is the first element in his classes array, thus the first element in his grades array is retrieved by getClassGrades() from Course.java.
Deliverable: Course.java
Template for Course.java:
import java.util.ArrayList;
public class Course_Template
{
//Students (ArrayList) and one Faculty (1)
private String name;
private ArrayList roster = new ArrayList();
private Faculty teacher;
//Constructor (executed when a new Course is created) public Course( )
{
//initialize the name and teacher data fields with appropriate parameters
}
//getter methods
public Faculty getFaculty(){ return this.teacher; }
public void addStudent( )
{
//Add Student objects to roster
//Include approriate parameter
}
//retrieve array to Student gpas
public double[] getGPAs()
{
//traverse the ArrayList of Student objects
//for each Student object, retrieve their gpa and store in an element of a new array of doubles
//return array with Student gpa's
}
//get array of Student names
public String[] getStudents()
{
//traverse the ArrayList of Student objects
//for each Student object, retrieve the first and last name
//store both first and last name, separated by a space, in an element of a new array of Strings
//return array with Student names
}
//get array of course grades public int[] getClassGrades()
{
//This method will retrieve the Student object's grade for this Course
//traverse the ArrayList of Student objects
//for each Student object, first identify the location of this Course in their classes array
//for each Student object, from the grades array get the grade corresponding to the location obtained previously //store the Student object's grade for this Course in an element of a new array of ints
//return array with grades for this Course
}
public String toString()
{
//Get names of Student objects in roster
String[] studentNames = getStudents();
//Get Student objects' grades for this Course
int[] classGrades = getClassGrades();
//Get Student objects' gpas
double[] gpas = getGPAs();
//Add Faculty object to str
String str = this.name + " " + this.teacher + " ";
//Append every Student object in roster to str (Name: some name Grade: some grade GPA: some GPA)
for( int i = 0; i < getStudents().length; i++ ){
str += String.format("Name: %-15s Grade: %3d GPA: %4f ",
studentNames[i], classGrades[i], gpas[i] );
}
//return String when Course object is referenced return str;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
