Skip to content

Instantly share code, notes, and snippets.

@jesselima
Created April 6, 2018 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesselima/7373d058a138f2cd342807b9733f14d4 to your computer and use it in GitHub Desktop.
Save jesselima/7373d058a138f2cd342807b9733f14d4 to your computer and use it in GitHub Desktop.
This is the ReportCard class the creates Student Cards.
package com.example.reportcard;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by jesse on 04/04/18.
* This is a part of the project ReportCard.
*/
public class ReportCard {
// CLASS ATTRIBUTES
private List<String> listStudentNames;
private List<String> disciplines;
private List<List> listOfStudentsGrades;
private HashMap<String, List<String>> hashListDisciplinesAndGrades;
// EMPTY CONSTRUCTOR
public ReportCard() {
}
/**
* FULL CONSTRUCTOR
* @param listStudentNames are the names of the students.
* @param disciplines are the list od disciplines the the student receives grades.
* @param listOfStudentsGrades It's a list of object type List. Each position of the list store a list with all grades of one student.
* @param hashListDisciplinesAndGrades its a List that each position holds a student name <String> and a List<String>. Each item List holds the student name and all of his disciplines names and grades.
*/
public ReportCard(List<String> listStudentNames, List<String> disciplines, List<List> listOfStudentsGrades, HashMap<String, List<String>> hashListDisciplinesAndGrades) {
this.listStudentNames = listStudentNames;
this.disciplines = disciplines;
this.listOfStudentsGrades = listOfStudentsGrades;
// this.studentGrades = studentGrades;
this.hashListDisciplinesAndGrades = hashListDisciplinesAndGrades;
}
// METHODS GETTERS AND SETTERS
public List<String> getListStudentNames() {
return listStudentNames;
}
public void setListStudentNames(List<String> listStudentNames) {
this.listStudentNames = listStudentNames;
}
public List<String> getDisciplines() {
return disciplines;
}
public void setDisciplines(List<String> disciplines) {
this.disciplines = disciplines;
}
public List<List> getListOfStudentsGrades() {
return listOfStudentsGrades;
}
public void setListOfStudentsGrades(List<List> listOfStudentsGrades) {
this.listOfStudentsGrades = listOfStudentsGrades;
}
public HashMap<String, List<String>> getHashListDisciplinesAndGrades() {
return hashListDisciplinesAndGrades;
}
public void setHashListDisciplinesAndGrades(HashMap<String, List<String>> hashListDisciplinesAndGrades) {
this.hashListDisciplinesAndGrades = hashListDisciplinesAndGrades;
}
@Override
public String toString() {
String message = "";
List<String> grades = new ArrayList<>();
// Execute this for each student on the list.
for (int i = 0; i < listStudentNames.size(); i++) {
// Get the value of the position 0 in the list "listStudentNames".
message += "\nSTUDENT REPORT CARD - Name: " + listStudentNames.get(i) + "\n";
for (int id = 0; id < disciplines.size(); id++) {
// For each discipline, get a grade list in
grades.add(disciplines.get(id) + ": " + listOfStudentsGrades.get(i).get(id));
}
hashListDisciplinesAndGrades.put(listStudentNames.get(i), grades);
String studentName = listStudentNames.get(i);
message += String.valueOf(hashListDisciplinesAndGrades.get(studentName));
}
return message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment