Created
September 14, 2012 02:10
-
-
Save oschrenk/3719383 to your computer and use it in GitHub Desktop.
Could someone tell me why my quiz scores are not displaying?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Student jimmy = new Student(null, null, 0); | |
jimmy.setQuizScore(95, 0); | |
jimmy.setQuizScore(73, 1); | |
jimmy.setQuizScore(100, 2); | |
jimmy.setQuizScore(55, 3); | |
jimmy.setQuizScore(73, 4); | |
jimmy.setQuizScore(66, 5); | |
jimmy.setQuizScore(92, 6); | |
jimmy.setQuizScore(51, 7); | |
jimmy.setQuizScore(82, 8); | |
jimmy.setQuizScore(62, 9); | |
jimmy.setProjectScore(89, 0); | |
jimmy.setProjectScore(85, 1); | |
jimmy.setProjectScore(97, 2); | |
jimmy.setProjectScore(76, 3); | |
jimmy.setProjectScore(98, 4); | |
jimmy.setProjectScore(85, 5); | |
jimmy.setProjectScore(62, 6); | |
jimmy.setProjectScore(82, 7); | |
jimmy.setProjectScore(51, 8); | |
jimmy.setProjectScore(74, 9); | |
jimmy.setProjectScore(92, 10); | |
jimmy.setProjectScore(58, 11); | |
jimmy.setProjectScore(52, 12); | |
jimmy.setProjectScore(76, 13); | |
jimmy.setProjectScore(94, 14); | |
int currentIndex = 0; | |
int projectLength = jimmy.getProjectsLength(); | |
int quizLength = jimmy.getQuizzesLength(); | |
while (currentIndex <= projectLength) { | |
System.out.println(jimmy.getProjectScoreForID(currentIndex)); | |
currentIndex++; | |
} | |
currentIndex = 0; | |
while (currentIndex <= quizLength) { | |
System.out.println(jimmy.getQuizScoreForID(currentIndex)); | |
currentIndex++; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Student { | |
private String firstname; | |
private String lastname; | |
private int studentID; | |
private double[] projects; | |
private double[] quizzes; | |
public Student(String firstname, String lastname, int ID) { | |
this.firstname = firstname; | |
this.lastname = lastname; | |
studentID = ID; | |
projects = new double[15]; | |
quizzes = new double[10]; | |
int i = this.projects.length - 1; | |
while (i >= 0) { | |
this.projects[i] = -1; | |
i--; | |
} | |
int i1 = this.quizzes.length - 1; | |
while (i1 >= 0) { | |
this.quizzes[i1] = -1; | |
i1--; | |
} | |
} | |
public boolean setProjectScore(double projectScore, int projectID) { | |
if ((projectID >= projects.length) || (projectID < 0)) { | |
return false; | |
} else { | |
projects[projectID] = projectScore; | |
return true; | |
} | |
} | |
public boolean setQuizScore(double quizScore, int quizID) { | |
if ((quizID >= quizzes.length) || (quizID < 0)) { | |
return false; | |
} else { | |
quizzes[quizID] = quizScore; | |
return true; | |
} | |
} | |
public int getProjectsLength() { | |
return this.projects.length; | |
} | |
public int getQuizzesLength() { | |
return this.quizzes.length; | |
} | |
public double getProjectScore(int index) { | |
if (index < 0 || index > projects.length - 1) { | |
return -1; | |
} | |
return projects[index]; | |
} | |
public double getQuizscore(int index) { | |
if (index < 0 || index > quizzes.length - 1) { | |
return -1; | |
} | |
return quizzes[index]; | |
} | |
public String getProjectScoreForID(int id) { | |
String grade = ""; | |
if (id <= this.projects.length - 1) { | |
if (projects[id] >= 90) { | |
grade = "A"; | |
} | |
if (80 <= projects[id] && projects[id] < 90) { | |
grade = "B"; | |
} | |
if (70 <= projects[id] && projects[id] < 80) { | |
grade = "C"; | |
} | |
if (60 <= projects[id] && projects[id] < 70) { | |
grade = "D"; | |
} | |
if (50 <= projects[id] && projects[id] < 60) { | |
grade = "F"; | |
} | |
} | |
return grade; | |
} | |
public String getQuizScoreForID(int id) { | |
String grade = ""; | |
if (id <= this.quizzes.length - 1) { | |
if (quizzes[id] >= 90) { | |
grade = "A"; | |
} | |
if (80 <= quizzes[id] && quizzes[id] < 90) { | |
grade = "B"; | |
} | |
if (70 <= quizzes[id] && quizzes[id] < 80) { | |
grade = "C"; | |
} | |
if (60 <= quizzes[id] && quizzes[id] < 70) { | |
grade = "D"; | |
} | |
if (50 <= quizzes[id] && quizzes[id] < 60) { | |
grade = "F"; | |
} | |
} | |
return grade; | |
} | |
public int getNextQuizIndex() { | |
int i = 0; | |
do { | |
if (quizzes[i] == -1.0) { | |
return i; | |
} | |
i++; | |
} while (i < quizzes.length); | |
return -1; | |
} | |
public int getNextProjectIndex() { | |
int i = 0; | |
do { | |
if (projects[i] == -1.0) { | |
return i; | |
} | |
i++; | |
} while (i < projects.length); | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment