public class CourseProg { public static void main(String[] args){ // the student
ID: 3538096 • Letter: P
Question
public class CourseProg {
public static void main(String[] args){
// the student info:
String[] names = {"Fay", "May", "Khaled", "Jassem", "Zaina", "Abdullah", "Ali"};
String[] year = {"Freshman", "Sophomore", "Sophomore", "Junior", "Senior", "Junior", "Freshman"};
double[] gpa = {3.3, 2.8, 1.9, 3.9, 3.4, 2.9, 3.5};
String[][] courses = {
{"csis101", "csis120", "math101"} ,
{"csis101", "stat110", "math101", "csis210"} ,
{"csis101", "english101", "math101", "stat200"},
{"csis101", "csis120", "csis255", "math101"},
{"csis101", "csis120", "math101", "english101"} ,
{"csis101", "csis120", "math101"},
{"csis101", "csis110", "csis255", "csis120", "math101", "english101"}
};
Character[][] grades = {
{'C', 'B', 'C'} ,
{'C', 'A', 'A', 'B'} ,
{'C', 'B', 'B', 'D'},
{'A', 'D', 'B', 'B'},
{'A', 'A', 'A', 'A'} ,
{'B', 'C', 'A'},
{'A', 'B', 'C', 'A', 'A', 'B'}
};
Student[] students = new Student[ names.length ] ;
// 1) using the above arrays and a for loop, create the Student objects in the students array
/*
2) make a Course object called csis130 with the following info:
name: csis130
capacity: 25
prerequisits: csis101, csis120 and math101
*/
// 3) try to enrol all the students into the course you created in question 2 (csis130)
// 4) print out csis130
// 5) assign the grades to csis130 by calling the method enterGrades (enter any 3 doubles for all)
// 6) call the csis130 method printOutprint out and check the rankings
}
}
Explanation / Answer
package demo;
import java.util.ArrayList;
public class Student {
private String name;
private String year;
private double gpa;
private ArrayList<Course> courses = new ArrayList<Course>();
public void setName(String name){
this.name = name;
}
public void setYear(String year){
this.year = year;
}
public void setGpa(double gpa){
this.gpa = gpa;
}
public void setCourses(String[] courses){
for(int i=0; i<courses.length; i++)
this.courses.add(new Course(courses[i]));
}
public void addCourse(Course course){
courses.add(course);
}
public String getName(){
return name;
}
public String getYear(){
return year;
}
public ArrayList<Course> getCourses(){
return courses;
}
public double getGpa(){
return gpa;
}
public int getRank(){
int rank = 0;
int temp = 0;
for(int i=0; i<this.getCourses().size(); i++){
Character grade = this.getCourses().get(i).getGrade();
if(grade=='A')
temp = 80;
else if(grade=='B')
temp = 60;
else if(grade=='C')
temp = 40;
else if(grade=='D')
temp = 20;
rank = rank + temp;
}
rank = rank / this.getCourses().size();
return rank;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.