zoltzer 0 Newbie Poster

I need any help I can get!! Below is my coding. When I run the program it just averages out all the numbers that I put in, which doesn't coincide with the homework assignment as stated right here:

For this assignment, you will write a Java program that will determine an overall course grade based on this criteria:

Category % of final grade 
Matlab homework 25% 
Matlab final 25% 
C++ homework 25% 
C++ final 25% 

Specifically, your program will need to do the following:

Ask the user for the # of Matlab homework assignments 
Ask the user for the total points possible for Matlab homework 
Ask the user for the # of C++ homework assignments 
Ask the user for the total points possible for C++ homework 
Ask the user for the score on the Matlab final 
Ask the user for the total points possible on the Matlab final 
Ask the user for the score on the C++ final 
Ask the user for the total points possible on the C++ final 
Display the percentage for each of the four categories 
Display the final grade percentage 
Display the final grade according to the scale below. 
Percent Letter grade 
90-100% A 
80-90% B 
70-80% C 
60-70% D 
< 60% E 


Make sure all your user input is "error proof" -- meaning your program will keep asking the user for valid input (and displaying an error message when invalid input is displayed). The code samples below show two different ways to make sure you have valid input. 

Here is my code:

import javax.swing.JOptionPane;
class Student {

    public static void main(String[] args)
    {
        Student s = new Student();
        s.inputGrades();
        System.out.println("Average --> " + s.getAverage());
        System.out.println("Letter grade --> " + s.letterGrade());
        System.out.println("s.toString() --> " + s.toString());

}

final double MATLAB_ASSIGNMENTS = .25;
final double MATLAB_POSSIBLE_ASSIGNMENTS = .25;
final double CASSIGNMENTS = .25;
final double CPOSSIBLE_ASSIGNMENTS = .25;
final double MATLAB_FINAL = .25;
final double MATLAB_FINAL_POSSIBLE = .25;
final double CFINAL = .25;
final double CFINAL_POSSIBLE = .25;

String name, finalLetterGrade;
int matlabHome = 0;
int matlabHomeposs = 0;
int cHome = 0;
int cHomeposs = 0;
int matlabFinal = 0;
int matlabFinalposs = 0;
int cFinal = 0;
int cFinalposs = 0;
double finalNumericGrade = 0;


public Student() {
System.out.println (" Initializing Student...");

}

public void inputGrades() {
name=JOptionPane.showInputDialog("Enter Student's full Name:");
matlabHome = Integer.parseInt(JOptionPane.showInputDialog( "How many Matlab assignments were there?" ));
matlabHomeposs = Integer.parseInt(JOptionPane.showInputDialog( "How many points were possible for Matlab Homework?" ));
cHome = Integer.parseInt(JOptionPane.showInputDialog( "How many C++ assignments were there" ));
cHomeposs = Integer.parseInt(JOptionPane.showInputDialog( "How many points were possible for the C++ Homework?" ));
matlabFinal = Integer.parseInt(JOptionPane.showInputDialog( "What was your Matlab final exam score?" ));
matlabFinalposs = Integer.parseInt(JOptionPane.showInputDialog( "Really, that's all? So what were the possible points on that exam?" ));
cFinal = Integer.parseInt(JOptionPane.showInputDialog( "What was your C++ final exam score? " ));
cFinalposs = Integer.parseInt(JOptionPane.showInputDialog( "Not too bad, I suppose, but how many points were possible for the C++ Final? " ));
}

public double getAverage(){
finalNumericGrade =
(matlabHome * MATLAB_ASSIGNMENTS) +
(matlabHomeposs * MATLAB_POSSIBLE_ASSIGNMENTS) +
(cHome * CASSIGNMENTS) +
(cHomeposs * CPOSSIBLE_ASSIGNMENTS) +
(matlabFinal * MATLAB_FINAL) +
(matlabFinalposs * MATLAB_FINAL_POSSIBLE) +
(cFinal * CFINAL)+
(cFinalposs * CFINAL_POSSIBLE);
return finalNumericGrade;
}

private String letterGrade(){
if (finalNumericGrade >= 93)
finalLetterGrade = "A";
else
if ((finalNumericGrade >= 85) & (finalNumericGrade < 93))
finalLetterGrade = "B";
else
if ((finalNumericGrade >= 78) & (finalNumericGrade < 85))
finalLetterGrade = "C";
else
if ((finalNumericGrade >= 70) & (finalNumericGrade < 78))
finalLetterGrade = "D";
else
if (finalNumericGrade < 70)
finalLetterGrade = "F";

return finalLetterGrade;



}


public String toString() {
String studentStringValue= " Student Name is: "+name +"\n";
studentStringValue+= " Matlab Assignments are: " + matlabHome + "\n";
studentStringValue+=" Matlab homework grade: " + matlabHomeposs + "\n";
studentStringValue+=" C++ assignments are: " + cHome + "\n";
studentStringValue+=" C++ homework grade is " + cHomeposs + "\n";
studentStringValue+=" Matlab final points are: " + matlabFinal + "\n";
studentStringValue+=" Matlab final grade is: " + matlabFinalposs + "\n";
studentStringValue+=" C++ final points are: " + cFinal + "\n\n";
studentStringValue+=" C++ final grade is : " + cFinalposs + "\n";
studentStringValue+=" Final Numeric Grade is: " + finalNumericGrade + "\n";
studentStringValue+=" Final Letter Grade is: " + finalLetterGrade +"\n";

return studentStringValue;
}


public void printName(){
System.out.print(" "+name);
}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.