Question:
Java Programming - Please help, running out of time !?
Wzr
2010-04-28 14:25:39 UTC
Please help, I only have an hour until this is due, I have no idea !!


Class Student will have attributes midExam and finalExam(to store test scores each with values of 0 to 100) and an array of up to ten whole numbers called scores[].

A void method addscore() will accept as an argument a whole number from zero to 100, and store that value in the scores[] array.

The class will also have setter method(s) to store or change the midterm and final grades,

Class Student will have a method averageScores() to calculate and return the average of all the scores as a decimal number.

Class Student will also have a method getGpa() to compute the grade as the average of midExam and fianlExam, then averaged (40% weight) with the average scores[]; i.e.

gpa = .6((midExam + finalExam)/2) + .4(average_of_all_scores)
Three answers:
Pain Killer
2010-04-30 14:11:37 UTC
public class Student {

private int midExam = 0;

private int finalExam = 0;

private int[] scores = new int[10];



private int counter = 0;

public int getMidExam() {

return midExam;

}

public int getFinalExam() {

return finalExam;

}

public void setMidExam(int midExam) {

if (midExam < 0 || midExam >100) {

throw new RuntimeException("Exam score has to be between 0 to 100 inclusive of both. MidExam = "+midExam);

}

this.midExam = midExam;

}

public void setFinalExam(int finalExam) {

if (midExam < 0 || midExam >100) {

throw new RuntimeException("Exam score has to be between 0 to 100 inclusive of both. FinalExam = "+finalExam);

}

this.finalExam = finalExam;

}



public void setScore(int score) {

if (score < 0 || score >100) {

throw new RuntimeException("Exam score has to be between 0 to 100 inclusive of both. Score = "+score);

}

if (counter == scores.length) {

throw new RuntimeException("All the scores have already been set");

}

scores[counter++] = score;

}



public void setScores(int[] scores) {

if (scores.length > 10) {

throw new RuntimeException("You can input at max only 10 scores.");

}

this.scores = scores;

}



public int averageScores() {

int total = 0;

for (int i : scores) {

total =+ i;

}

return (int) (total/scores.length);

}



public double getGpa() {

return (0.6*((midExam + finalExam)/2)) + (0.4*(averageScores()));

}

}
abion47
2010-04-28 14:38:30 UTC
Have midExam and finalExam be int variables with values between 0 and 100. scores is an int array[10], also with values between 0 and 100.



method addScore should take an int parameter, check to see if it is a valid value (i.e. 0-100), and if true, add that value to the first empty value in scores.



there should be methods called setMidScore() and setFinalScore(). both should take an int, check to see if it is a valid value (i.e. 0-100), and if true, set the value of midExam / finalExam to the value.



averageScores() should just return the average of every score. (i.e. midExam + finalExam + every-value-in-your-scores-array / the number of values you added together)



getGPA() should just return the result of the formula you provided yourself.
anonymous
2016-04-14 14:12:01 UTC
please check the syntax of main. that is public static void main(String []args). args is an identifier array you can use any name other than keywords. Also, check the name of the file. The file should be saved with the same name as that of the class containing main method, with the extension ".java" Say you have a class abc having the main method, then the file should be saved as abc.java Case sensitive.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...