what is wrong with my code? need help
yea i have to make a grade calculator that when i run the program it asks me standard questions and i type them into the box and it shows in the bottom (using eclipse btw). So i type stuff in 1 by 1 and basically when i go through it several times its suppose to calculate my gpa but my codes all wrong and stuff. heres what my code says. anyone can help me out or send some insight?
import javax.swing.JOptionPane;
public class proj22
{
public static void main(String args[]) {
PrintExplanation();
name=name();
semesterValue=semesterValue();
courseName=courseName();
courseGrade = courseGrade();
GetValidNumberInput(courseName, credits, GPA);
GPA=CalculateGPA(credits, gradeNumber);
}
private static String name() {
// TODO Auto-generated method stub
return null;
}
private static String courseName() {
// TODO Auto-generated method stub
return null;
}
private static String courseGrade() {
// TODO Auto-generated method stub
return null;
}
private static String semesterValue() {
// TODO Auto-generated method stub
return null;
}
int lowerNum=1;
int upperNum=4;
static int gradeNumber,credits, GPA, semester;
static String name, creditsValue, semesterValue, courseName, courseGrade, prompt_user;
int totalCredits = 0;
int totalQualityPoints= 0;
//This explains what the program does and shows it to the person who is running it.
public static void PrintExplanation(){
JOptionPane.showMessageDialog(null, "This allows you to calculate your GPA for the semster you are/were in by entering the number/letter of your grades).");
}
public static void GetValidNumberInput(String promptStr, int lowerNum, int upperNum){
String name;
name= JOptionPane.showInputDialog("Hello, What is your name?");
System.out.println( "showInputDialog: " + name);
String semesterValue;
semesterValue = JOptionPane.showInputDialog("What semester are you in?");
System.out.println( "showInputDialog: " + semesterValue);
do {
String courseName;
courseName = JOptionPane.showInputDialog("What is the course name? \n or type 'end' if no courses left");
if(courseName.equals("end")) break;
System.out.println( "showInputDialog: " + courseName);
String courseGrade;
courseGrade= JOptionPane.showInputDialog("What did you make in this class?");
System.out.println( "showInputDialog: " + courseGrade);
String creditsValue;
creditsValue = JOptionPane.showInputDialog("How many hours was this class?");
if(credits < lowerNum || credits > upperNum){
JOptionPane.showMessageDialog(null,"That is not a valid number.");
} else {
credits += Integer.parseInt(creditsValue);
}
}while(!courseName.equals("end"));
}
public static void GenerateGPAReport ( int totalCredits, int totalQualityPoints){
//This shows what the GPA is
JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+totalCredits+ "\n Total Quality Points:"+totalQualityPoints+"\n GPA:"+GPA);
}
public static int CalculateGPA (int totalCredits, int totalQualityPoints){
//Calculates the GPA
totalQualityPoints = credits * gradeNumber;
GPA = totalQualityPoints / totalCredits;
return GPA;
}
public static int ConvertGradeToPoints(String grade){
//This converts the grades inputed to a number (i.e. A = 4, B=3, C=2, ect)
;
if (grade.equalsIgnoreCase("A")){ gradeNumber = 4;
}
else
if
(grade.equalsIgnoreCase("B")){
gradeNumber = 3;
}
else
if
(grade.equalsIgnoreCase("C")) { gradeNumber = 2;
}
else
if
(grade.equalsIgnoreCase("D")){
gradeNumber = 1;
}
else
{
gradeNumber = 0;
}
return
gradeNumber;
}
}
Re: what is wrong with my code? need help
wrap your code in code tags so we can see the code formatted as you would see it in you IDE. But I'd recommend you repost only the section of code that is giving you errors most of your methods have no logic yet, so there really isn't a reason to post it. But you will want to create a VO for your name, courseName, etc, etc; it will be composed of getters and setters and should resemble something like this:
Code java:
public class SampleVO {
String name = null;
String courseTitle = null;
int grade = 0;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCourseTitle() {
return courseTitle;
}
public void setCourseTitle(String courseTitle) {
this.courseTitle = courseTitle;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
}
Re: what is wrong with my code? need help
here it is
Quote:
import javax.swing.JOptionPane;
public class proj22
{
public static void main(String args[]) {
PrintExplanation();
name=name();
semesterValue=semesterValue();
courseName=courseName();
courseGrade = courseGrade();
GetValidNumberInput(courseName, credits, GPA);
GPA=CalculateGPA(credits, gradeNumber);
}
private static String name() {
// TODO Auto-generated method stub
return null;
}
private static String courseName() {
// TODO Auto-generated method stub
return null;
}
private static String courseGrade() {
// TODO Auto-generated method stub
return null;
}
private static String semesterValue() {
// TODO Auto-generated method stub
return null;
}
int lowerNum=1;
int upperNum=4;
static int gradeNumber,credits, GPA, semester;
static String name, creditsValue, semesterValue, courseName, courseGrade, prompt_user;
int totalCredits = 0;
int totalQualityPoints= 0;
//This explains what the program does and shows it to the person who is running it.
public static void PrintExplanation(){
JOptionPane.showMessageDialog(null, "This allows you to calculate your GPA for the semster you are/were in by entering the number/letter of your grades).");
}
public static void GetValidNumberInput(String promptStr, int lowerNum, int upperNum){
String name;
name= JOptionPane.showInputDialog("Hello, What is your name?");
System.out.println( "showInputDialog: " + name);
String semesterValue;
semesterValue = JOptionPane.showInputDialog("What semester are you in?");
System.out.println( "showInputDialog: " + semesterValue);
do {
String courseName;
courseName = JOptionPane.showInputDialog("What is the course name? \n or type 'end' if no courses left");
if(courseName.equals("end")) break;
System.out.println( "showInputDialog: " + courseName);
String courseGrade;
courseGrade= JOptionPane.showInputDialog("What did you make in this class?");
System.out.println( "showInputDialog: " + courseGrade);
String creditsValue;
creditsValue = JOptionPane.showInputDialog("How many hours was this class?");
if(credits < lowerNum || credits > upperNum){
JOptionPane.showMessageDialog(null,"That is not a valid number.");
} else {
credits += Integer.parseInt(creditsValue);
}
}while(!courseName.equals("end"));
}
public static void GenerateGPAReport ( int totalCredits, int totalQualityPoints){
//This shows what the GPA is
JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+totalCredits+ "\n Total Quality Points:"+totalQualityPoints+"\n GPA:"+GPA);
}
public static int CalculateGPA (int totalCredits, int totalQualityPoints){
//Calculates the GPA
totalQualityPoints = credits * gradeNumber;
GPA = totalQualityPoints / totalCredits;
return GPA;
}
public static int ConvertGradeToPoints(String grade){
//This converts the grades inputed to a number (i.e. A = 4, B=3, C=2, ect)
;
if (grade.equalsIgnoreCase("A")){ gradeNumber = 4;
}
else
if
(grade.equalsIgnoreCase("B")){
gradeNumber = 3;
}
else
if
(grade.equalsIgnoreCase("C")) { gradeNumber = 2;
}
else
if
(grade.equalsIgnoreCase("D")){
gradeNumber = 1;
}
else
{
gradeNumber = 0;
}
return
gradeNumber;
}
}
Re: what is wrong with my code? need help
Quote:
Originally Posted by
balmung123
yea i have to make a grade calculator that when i run the program it asks me standard questions and i type them into the box and it shows in the bottom (using eclipse btw). So i type stuff in 1 by 1 and basically when i go through it several times its suppose to calculate my gpa but my codes all wrong and stuff. heres what my code says. anyone can help me out or send some insight?
Hello balmung123!
Can you elaborate what's wrong with your code (errors, exceptions, unexpected behaviour)?
And please edit your post and use the code tags to format it.