In: Computer Science
Create a small program that calculates the final grade in this course, given the different assignments and exams you will be required to take. The program should ask for all the grades through the semester, and as a final output it should compute the weighted average as well as give the final letter grade. You should use the syllabus for this course to calculate the final grade. • Five assignments worth 30 points each. • Three projects worth 100 points each. • Seven quizzes worth 20 points each. • Participation is worth 10 points. Your final grade is calculated out of the total points you earn. For example, if the total possible points are 500 and you have a 461, your grade is 461/500 x 100 = 92% which is an A-. Extra Credit: If you wish to challenge yourself, you can make sure that the program “fails gracefully”. If someone enters the wrong information or data type, prompt the user with a handled message. Although we will deal with error handling later in the semester, thinking about exceptions is always important. Another way to make the program slightly more challenging is to accept an undetermined number of quizzes.
Answer:
Source Code:
package marks;
import java.util.Scanner;
public class Result {
private double midTerm;
private double endSem;
private double quizAvg;
public double getMidTerm() {
return midTerm;
}
public void setMidTerm(double midTerm) {
this.midTerm = midTerm;
}
public double getEndSem() {
return endSem;
}
public void setEndSem(double endSem) {
this.endSem = endSem;
}
public double getQuizAvg() {
return quizAvg;
}
public void setQuizAvg(double quizAvg) {
this.quizAvg = quizAvg;
}
public void calculate(double midterm,double endsem, double quizavg) {
/** a. There are n quizzes, each graded on the basis of 10 points
* b. There is one mid term and one end semester each graded on the basis of 100 points
* c. the end semester counts for 50% of the grade, the mid term counts for 25% and the quiz
* score together counts for a total of 25%
*
**/
double midTermPercentage=midterm*0.25;
double endSemPercentage=endsem*0.5;
double quizPercentage=quizavg*0.25;
double finalResult=midTermPercentage+endSemPercentage+quizPercentage;
System.out.println("Final Percentage is: "+finalResult);
System.out.println();
System.out.print("The student Grade is: ");
if(finalResult>=80)
{
System.out.print("A");
}
else if(finalResult>=60 && finalResult<80)
{
System.out.print("B");
}
else if(finalResult>=40 && finalResult<60)
{
System.out.print("C");
}
else
{
System.out.print("D");
}
}
public static void main(String[] args) {
int sum=0;
Scanner sc=new Scanner(System.in);
Result r=new Result();
System.out.println("Enter The Marks Scored in Mid Term out Of 100");
double midTerm=sc.nextDouble();
r.setMidTerm(midTerm);
System.out.println("Enter The Marks Scored in end Semester out Of 100");
double endSem=sc.nextDouble();
r.setEndSem(endSem);
System.out.println("Enter The no .of Quiz");
int noOfQuiz=sc.nextInt();
System.out.println("Enter the marks in each quiz out of 10");
double quiz[]=new double[noOfQuiz];
for(int i=0;i<quiz.length;i++)
{ System.out.println("enter marks for quiz: " +(i+1));
quiz[i]=sc.nextDouble();
}
for(int j=0;j<quiz.length;j++)
{
sum+=quiz[j];
}
double quizAvg=(sum/noOfQuiz)*10;
r.setQuizAvg(quizAvg);
r.calculate(r.getMidTerm(),r.getEndSem(),r.getQuizAvg());
}
}