473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with this program do not understand why it doesnt work

6
Hi, I don't know why the final output does not work right. It does not display anything and I don't know why.


import javax.swing.*;
public class lab5 {


public static void main(String [] args){
String finalGrade;
String grade="";
String display = "";
String course="";
int GPA=0;
double finalCalc;
int confirm;
double avg=0;

do{
courses();

enterGrade(grade);

display += " "+course+ " " + grade;
confirm=JOptionPane.showConfirmDialog(null,"Do you have another course?", "More?", JOptionPane.YES_NO_OPTION);
}
while(confirm==JOptionPane.YES_OPTION);
gradeList(display, grade, GPA, course, avg);

}



public static String courses ()
{
String course;

course=JOptionPane.showInputDialog("Enter course taken(IT101, IT103, IT108, IT212, IT214, IT224, IT341)");

return course;
}


public static String enterGrade(String course)
{
String grade;

grade=JOptionPane.showInputDialog("Enter grade for: " + course + " (ex. A+, A, A-)");

return grade;
}


public static int finalGPA(String grade)
{
int GPA;
if (( grade=="A+") || (grade=="A") || (grade=="A-"))
{
GPA=4;
}
else if (( grade=="B+") || (grade=="B") || (grade=="B-"))
{
GPA=3;
}
else if (( grade=="C+") || (grade=="C") || (grade=="C-"))
{
GPA=2;
}
else if (( grade=="D+") || (grade=="D") || (grade=="D-"))
{
GPA=1;
}
else
GPA=0;
return GPA;
}


public static double calc(int GPA, int i)
{
double avg=GPA/i;
return avg;
}


public static void gradeList(String output, String grade, int GPA, String course, double avg)
{

output += "Course Grade\n" + course + grade + "\n\n ---------------------\n" + avg;
JOptionPane.showMessageDialog(null, output);
}
}
Apr 16 '07 #1
3 2216
Ganon11
3,652 Expert 2GB
One mistake I notice:

Your method, courses(), is returning a String object. Inside the method, you are creating and returning this just fine; but where you call it (in main(), the first line of your do...while loop) you don't have a String object receiving it. Should you be setting course equal to the result:

Expand|Select|Wrap|Line Numbers
  1. course = courses();
Apr 16 '07 #2
baden
6
One mistake I notice:

Your method, courses(), is returning a String object. Inside the method, you are creating and returning this just fine; but where you call it (in main(), the first line of your do...while loop) you don't have a String object receiving it. Should you be setting course equal to the result:

Expand|Select|Wrap|Line Numbers
  1. course = courses();
Okay i fixed that everything works like i want but it is not calcuating the final gpa. Basically the last line in the output should calculate the avarage of the grades after they have been converted from string to an integer
Apr 16 '07 #3
Ganon11
3,652 Expert 2GB
A few more mistakes I found:

1) Your enterGrade() method was also String returning, but you were not doing anything with the result, just like the courses() method.

2) In your finalGPA function, you are using == with Strings - you should be using the .equals() method, like:

Expand|Select|Wrap|Line Numbers
  1. grade.equals("A+"); // not grade == "A+"
3) You have defined the functions finalGPA and calc, but I don't see you use them anywhere in your code...is this a problem?
Apr 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: | last post by:
Hello, I hope someone will help me or I will have to dive from 11th floor. Why this --> test = @"Melanie "Jets" Riggs" doesnt work in asp? I need something like that and I dont know how to make it...
5
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If...
2
by: Simon Harvey | last post by:
Hi everyone, I'm having a problem with getting a control that I'm using to work. I have a placeholder control sitting within a user control. On certain occasions at runtime I create a...
1
by: evantri | last post by:
this is my program code int main (int argc, char *argv) { int i; double minx = -1.0; double maxx = 1.0; double miny = -1.0;
3
by: Arun Nair | last post by:
''' Can anyone help me with this program it just takes probability of the first team and runs the program doesnt takes the probability of the second team even though specified''' from random...
1
Digital Don
by: Digital Don | last post by:
I am writing a program for Peg solitaire... To check for no repetition of previous states I use a Set for storage of Board states.. The pronblem is when I declare the set as type char i.e. set...
6
by: moreliens | last post by:
Hi, I have the following Javascript Code which checks if the user has entered numerics in the fields. If non numeric characters are found, it displays error message and then sets the focus back to...
1
by: Dany13 | last post by:
hi all. i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for...
9
by: AGP | last post by:
I've been scratching my head for weeks to understand why some code doesnt work for me. here is what i have: dim sVal as string = "13.2401516" dim x as double x = sVal debug.writeline ( x)
14
by: berky | last post by:
I am so very close to making this program happen, however I am running into an error with single character words. When My program runs, if I put a single letter word in like A or I then...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.