| | |
Help with a java program home work assignment
![]() |
•
•
Join Date: Jul 2005
Posts: 9
Reputation:
Solved Threads: 0
Hey to everyone out there. I am new to this and seeking assistance with a java program assignment. if anyone can help let me know. The program is completed all I have left is to produce accurate output of a students grade. Here is the code:
The code is supposed to produce the name of the student, the grades and the final letter grade. I can not get the letter grade to appear in the output.
////////////////////////////////////////////////////////////////
import javax.swing.JOptionPane;
class Student {
final double ASSIGNMENT_ONE_PERCENTAGE = .10;
final double ASSIGNMENT_TWO_PERCENTAGE = .10;
final double ASSIGNMENT_THREE_PERCENTAGE = .10;
final double ASSIGNMENT_FOUR_PERCENTAGE = .10;
final double MIDTERM_PERCENTAGE = .25;
final double FINALEXAM_PERCENTAGE = .25;
final double PARTICIPATION_PERCENTAGE = .10;
String name, finalLetterGrade;
int assignmentOne = 0;
int assignmentTwo = 0;
int assignmentThree = 0;
int assignmentFour = 0;
int midterm = 0;
int finalExamGrade = 0;
int participation = 0;
double finalNumericGrade = 0;
public Student() {
System.out.println (" Initializing Student...");
}
public void inputGrades() {
name=JOptionPane.showInputDialog("Enter Student's full Name:");
assignmentOne = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment One Grade" ));
assignmentTwo = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment Two Grade" ));
assignmentThree = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment Three Grade" ));
assignmentFour = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment Four Grade" ));
midterm = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Midterm Grade" ));
finalExamGrade = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Final Examination Grade" ));
participation = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Participation Grade" ));
}
public double getAverage(){
finalNumericGrade =
(assignmentOne * ASSIGNMENT_ONE_PERCENTAGE) +
(assignmentTwo * ASSIGNMENT_TWO_PERCENTAGE) +
(assignmentThree * ASSIGNMENT_THREE_PERCENTAGE) +
(assignmentFour * ASSIGNMENT_FOUR_PERCENTAGE) +
(midterm * MIDTERM_PERCENTAGE) +
(finalExamGrade * FINALEXAM_PERCENTAGE) +
(participation * PARTICIPATION_PERCENTAGE);
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+= " Assignment One grade is: " + assignmentOne + "\n";
studentStringValue+=" Assignment Two grade is: " + assignmentTwo + "\n";
studentStringValue+=" Assignment Three grade is: " + assignmentThree + "\n";
studentStringValue+=" Assignment Four grade is: " + assignmentFour + "\n";
studentStringValue+=" Midterm grade is: " + midterm + "\n";
studentStringValue+=" Final Exam is: " + finalExamGrade + "\n";
studentStringValue+=" Participation grade is: " + participation + "\n\n";
studentStringValue+=" Final Numeric Grade is: " + finalNumericGrade + "\n";
studentStringValue+=" Final Letter Grade is: " + finalLetterGrade +"\n";
return studentStringValue;
}
public void printName(){
System.out.print(" "+name);
}
}
////////////////////////////////////////////////////////////////
I can not get the letter grade to reflect in the output. ANy ideas?
The code is supposed to produce the name of the student, the grades and the final letter grade. I can not get the letter grade to appear in the output.
////////////////////////////////////////////////////////////////
import javax.swing.JOptionPane;
class Student {
final double ASSIGNMENT_ONE_PERCENTAGE = .10;
final double ASSIGNMENT_TWO_PERCENTAGE = .10;
final double ASSIGNMENT_THREE_PERCENTAGE = .10;
final double ASSIGNMENT_FOUR_PERCENTAGE = .10;
final double MIDTERM_PERCENTAGE = .25;
final double FINALEXAM_PERCENTAGE = .25;
final double PARTICIPATION_PERCENTAGE = .10;
String name, finalLetterGrade;
int assignmentOne = 0;
int assignmentTwo = 0;
int assignmentThree = 0;
int assignmentFour = 0;
int midterm = 0;
int finalExamGrade = 0;
int participation = 0;
double finalNumericGrade = 0;
public Student() {
System.out.println (" Initializing Student...");
}
public void inputGrades() {
name=JOptionPane.showInputDialog("Enter Student's full Name:");
assignmentOne = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment One Grade" ));
assignmentTwo = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment Two Grade" ));
assignmentThree = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment Three Grade" ));
assignmentFour = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Assignment Four Grade" ));
midterm = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Midterm Grade" ));
finalExamGrade = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Final Examination Grade" ));
participation = Integer.parseInt(JOptionPane.showInputDialog( "Enter the Participation Grade" ));
}
public double getAverage(){
finalNumericGrade =
(assignmentOne * ASSIGNMENT_ONE_PERCENTAGE) +
(assignmentTwo * ASSIGNMENT_TWO_PERCENTAGE) +
(assignmentThree * ASSIGNMENT_THREE_PERCENTAGE) +
(assignmentFour * ASSIGNMENT_FOUR_PERCENTAGE) +
(midterm * MIDTERM_PERCENTAGE) +
(finalExamGrade * FINALEXAM_PERCENTAGE) +
(participation * PARTICIPATION_PERCENTAGE);
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+= " Assignment One grade is: " + assignmentOne + "\n";
studentStringValue+=" Assignment Two grade is: " + assignmentTwo + "\n";
studentStringValue+=" Assignment Three grade is: " + assignmentThree + "\n";
studentStringValue+=" Assignment Four grade is: " + assignmentFour + "\n";
studentStringValue+=" Midterm grade is: " + midterm + "\n";
studentStringValue+=" Final Exam is: " + finalExamGrade + "\n";
studentStringValue+=" Participation grade is: " + participation + "\n\n";
studentStringValue+=" Final Numeric Grade is: " + finalNumericGrade + "\n";
studentStringValue+=" Final Letter Grade is: " + finalLetterGrade +"\n";
return studentStringValue;
}
public void printName(){
System.out.print(" "+name);
}
}
////////////////////////////////////////////////////////////////
I can not get the letter grade to reflect in the output. ANy ideas?
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
You don't have a "main" method to even run the program? Once you do, your program will work fine(I've already tried it).
Add this method to your code:
Remember that you MUST call those methods, they won't run themselves.
Add this method to your code:
Java Syntax (Toggle Plain Text)
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()); }
Remember that you MUST call those methods, they won't run themselves.
![]() |
Similar Threads
- put the Dos 's command into java program? (Java)
- c home work (C)
- Help with Java program writing (Java)
- Basic data and cobtrol structure,applet,class,eventhandling (JSP)
- JAVA program help (Student/Grades) (Java)
- set me some home work plz (C++)
Other Threads in the Java Forum
- Previous Thread: tokenizer
- Next Thread: About OMA Device Management client
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class clear client code compile compiler component database development dice digit eclipse equation error event formatingtextintooltipjava fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list main map method methods mobile myregfun netbeans nonstatic notdisplaying openjavafx pearl problem program project qt recursion repositories scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver storm string superclass swing system thread threads tree variablebinding windows xor






