Skip to content

Instantly share code, notes, and snippets.

@tudor-paraschivescu
Created July 17, 2017 16:28
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 tudor-paraschivescu/2591c63155615d04f5d1b6f99c416649 to your computer and use it in GitHub Desktop.
Save tudor-paraschivescu/2591c63155615d04f5d1b6f99c416649 to your computer and use it in GitHub Desktop.
Report card that stores grades for English, Math, Computer Science, History and Geography subjects. Made for the Android Basics Nanodegree program on Udacity.
/**
* Report card class that stores grades for
* English, Math, Computer Science, History and Geography subjects.
* Created by Tudor Paraschivescu on 17/07/2017.
*/
public class ReportCard {
private static final char NO_GRADE = '-';
private String studentName;
private char englishGrade;
private char mathGrade;
private char computerScienceGrade;
private char historyGrade;
private char geographyGrade;
/* Generate a report card for a student without his grades */
public ReportCard(String studentName) {
this.studentName = studentName;
this.englishGrade = NO_GRADE;
this.mathGrade = NO_GRADE;
this.computerScienceGrade = NO_GRADE;
this.historyGrade = NO_GRADE;
this.geographyGrade = NO_GRADE;
}
/* Generate a report card for a student with grades for
* English, Math, Computer Science, History and Geography subjects
* Grades are given with letters from A to F */
public ReportCard(String studentName, char englishGrade, char mathGrade,
char computerScienceGrade, char historyGrade, char geographyGrade) {
this.studentName = studentName;
this.englishGrade = englishGrade;
this.mathGrade = mathGrade;
this.computerScienceGrade = computerScienceGrade;
this.historyGrade = historyGrade;
this.geographyGrade = geographyGrade;
}
/* Get the name of the student */
public String getStudentName() {
return studentName;
}
/* Get the grade for the English class */
public char getEnglishGrade() {
return englishGrade;
}
/* Get the grade for the Math class */
public char getMathGrade() {
return mathGrade;
}
/* Get the grade for the Computer Science class */
public char getComputerScienceGrade() {
return computerScienceGrade;
}
/* Get the grade for the History class */
public char getHistoryGrade() {
return historyGrade;
}
/* Get the grade for the Geography class */
public char getGeographyGrade() {
return geographyGrade;
}
/* Set the name of the student */
public void setStudentName(String studentName) {
this.studentName = studentName;
}
/* Set the grade for the English class */
public void setEnglishGrade(char englishGrade) {
this.englishGrade = englishGrade;
}
/* Set the grade for the Math class */
public void setMathGrade(char mathGrade) {
this.mathGrade = mathGrade;
}
/* Set the grade for the Computer Science class */
public void setComputerScienceGrade(char computerScienceGrade) {
this.computerScienceGrade = computerScienceGrade;
}
/* Set the grade for the History class */
public void setHistoryGrade(char historyGrade) {
this.historyGrade = historyGrade;
}
/* Set the grade for the Geography class */
public void setGeographyGrade(char geographyGrade) {
this.geographyGrade = geographyGrade;
}
@Override
public String toString() {
String fullReport = "";
fullReport += "Name: " + getStudentName() + "\n";
fullReport += "English Grade: " + getEnglishGrade() + "\n";
fullReport += "Math Grade: " + getMathGrade() + "\n";
fullReport += "Computer Science Grade: " + getComputerScienceGrade() + "\n";
fullReport += "History Grade: " + getHistoryGrade() + "\n";
fullReport += "Geography Grade: " + getGeographyGrade() + "\n";
return fullReport;
}
public static void main(String[] args) {
// Make a report card for Katherine
ReportCard katherineReportCard = new ReportCard("Katherine Kuan", 'A',
'B', 'A', 'B', 'B');
System.out.println(katherineReportCard.toString());
// Make a report card for Kunal
ReportCard kunalReportCard = new ReportCard("Kunal Chawla");
System.out.println(kunalReportCard.toString());
// Add Kunal's grades
kunalReportCard.setEnglishGrade('B');
kunalReportCard.setComputerScienceGrade('A');
kunalReportCard.setMathGrade('A');
kunalReportCard.setGeographyGrade('C');
kunalReportCard.setHistoryGrade('B');
System.out.println(kunalReportCard.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment