I am doing a program that has a weighted average calculation and everything compiles and runs. It is just that my weighted average seems to be calculating incorrectly.
This is the type of output I should see:
Homework:
Number of assignments? 3
Assignment 1 score and max? 14 15
Assignment 2 score and max? 16 20
Assignment 3 score and max? 19 25
Sections attended? 4
Total points = 65 / 80
Weighted score = 40.63
Exam 1:
Score? 81
Curve? 0
Total points = 81 / 100
Weighted score = 16.2
Exam 2:
Score? 95
Curve? 10
Total points = 100 / 100
Weighted score = 30.0
Course grade = 86.83
Below is my code and I think even after getting up this morning and looking at it, I have an error in the calculations, but I can;t pinpoint it. Any useful suggestions would be helpful.
//This program is supposed to receive input from user, and calculated the grades of a //student with a weighted average import java.util.Scanner; public class Grades{ private double weightExam; private double score; private double curveAmount; private double scoreTotal; private double scoreWeighted; private double weightHomeWork; private int section; private int sections; private double sumScore; private double number; private double assignMax; private double assignScore; private int sumMax; Scanner console = new Scanner(System.in); public Grades() { intro(); exam(); homework(); } public void intro() { System.out.println("This program accepts scores from two exams and"); System.out.println("scores from your homework as input and computes"); System.out.println("your grade in the course."); System.out.println(); } public void exam() { for (int i = 0; i < 2; i++) { // 2 exams System.out.print("What is the weight of exam " + i + " (0-100)?"); weightExam = console.nextInt(); System.out.print("Score earned?"); score = console.nextInt(); System.out.print("Was there a curve (1=yes, 2=no)?"); int curve = console.nextInt(); if (curve == 1) { System.out.print("How much was the curve?"); curveAmount = console.nextInt(); } else { curveAmount = 0; } totalScore(); weightedScore(); System.out.println("Total points = " + scoreTotal + "/" + "100"); System.out.println("Weighted score = " + scoreWeighted + "/" + weightExam); } } public void totalScore() { scoreTotal = Math.min(score + curveAmount, 100); } public void weightedScore() { scoreWeighted = (score + curveAmount)/200 * weightExam; } public void homework() { System.out.print("What is the Homework weight (0-100)?"); weightHomeWork = console.nextInt(); System.out.print("Number of assignments?"); number = console.nextInt(); for (int i = 0; i < number; i++) { System.out.println("Assignment " + i+1 + " score and max?"); assignScore = console.nextInt(); assignMax = console.nextInt(); sumScore += assignScore; sumMax += assignMax; } System.out.print("How many sections attended?"); section = console.nextInt(); sections = Math.min(3 * section, 20); System.out.println("Section points = " + sections); weightedHomework(); System.out.println("Total points = " + (sections + sumScore) + "/" + sumMax); System.out.println("Weighted score = " + scoreWeighted + "/" + weightHomeWork); } public void weightedHomework() { scoreWeighted = ((sections + sumScore)/sumMax)*weightHomeWork; } public static void main(String[] args) { new Grades(); } }