Can Anyone Help??
I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!!
import javax.swing.*;
import java.util.*;
public class GradePoint
{
public static void main(String[] args)
{
String tempGrades;
String[][] names = new String[10][6];
String outputGrades = new String();
float gpa;
double A = 4;
double a = 4;
double B = 3;
double b = 3;
double C = 2;
double c = 2;
double D = 1;
double d = 1;
double F = 0;
double f = 0;
for(int x = 0; x < 3; x++)
{
names[x][0] = JOptionPane.showInputDialog(null, "Please Enter Student number " + (x + 1) + "s Name ");
for(int y = 1; y < 6; y++)
{
do
tempGrades = JOptionPane.showInputDialog(null, "Please Enter Grade for course number " + (y));
while (!tempGrades.equalsIgnoreCase("A") && !tempGrades.equalsIgnoreCase("B") && !tempGrades.equalsIgnoreCase("C") && !tempGrades.equalsIgnoreCase("D") && !tempGrades.equalsIgnoreCase("F"));
names[x][y]=tempGrades;
}
}
for(int x = 0; x < 3; x++)
{
outputGrades = "Students Name " + names[x][0] + "\n";
for(int y = 1; y < 6; y++)
outputGrades += "Grade for course number " + y + ": " + names[x][y] + "\n";
JOptionPane.showMessageDialog(null, outputGrades);
JOptionPane.showMessageDialog(null, names[x][y]);
JOptionPane.showMessageDialog(null, "Grade Report Finished");
System.exit(0);
}
} 4 2837
"SCOTT DELIBAC" <b1***@email.uophx.edu> wrote in message news:<XGkPb.27044$Xq2.9730@fed1read07>... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!!
You can't access the variables A, a, B, b, etc. based on a string.
Instead, store the grade values in a HashMap:
HashMap grademap = new HashMap();
grademap.put("A", new Integer(4));
grademap.put("B", new Integer(3));
grademap.put("C", new Integer(2));
grademap.put("D", new Integer(1));
grademap.put("F", new Integer(0));
Then you can look up the numeric value based on the grade string:
int value = grademap.get(names[x][y].toUpperCase());
"SCOTT DELIBAC" <b1***@email.uophx.edu> wrote in message news:<XGkPb.27044$Xq2.9730@fed1read07>... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!!
You can't access the variables A, a, B, b, etc. based on a string.
Instead, store the grade values in a HashMap:
HashMap grademap = new HashMap();
grademap.put("A", new Integer(4));
grademap.put("B", new Integer(3));
grademap.put("C", new Integer(2));
grademap.put("D", new Integer(1));
grademap.put("F", new Integer(0));
Then you can look up the numeric value based on the grade string:
int value = grademap.get(names[x][y].toUpperCase());
Thank you I got it.
-Scott
--
Delibac
"Karl von Laudermann" <ka**@ueidaq.com> wrote in message
news:e7**************************@posting.google.c om... "SCOTT DELIBAC" <b1***@email.uophx.edu> wrote in message
news:<XGkPb.27044$Xq2.9730@fed1read07>... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!!
You can't access the variables A, a, B, b, etc. based on a string. Instead, store the grade values in a HashMap:
HashMap grademap = new HashMap(); grademap.put("A", new Integer(4)); grademap.put("B", new Integer(3)); grademap.put("C", new Integer(2)); grademap.put("D", new Integer(1)); grademap.put("F", new Integer(0));
Then you can look up the numeric value based on the grade string: int value = grademap.get(names[x][y].toUpperCase());
Thank you I got it.
-Scott
--
Delibac
"Karl von Laudermann" <ka**@ueidaq.com> wrote in message
news:e7**************************@posting.google.c om... "SCOTT DELIBAC" <b1***@email.uophx.edu> wrote in message
news:<XGkPb.27044$Xq2.9730@fed1read07>... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!!
You can't access the variables A, a, B, b, etc. based on a string. Instead, store the grade values in a HashMap:
HashMap grademap = new HashMap(); grademap.put("A", new Integer(4)); grademap.put("B", new Integer(3)); grademap.put("C", new Integer(2)); grademap.put("D", new Integer(1)); grademap.put("F", new Integer(0));
Then you can look up the numeric value based on the grade string: int value = grademap.get(names[x][y].toUpperCase()); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: RobertMaas |
last post by:
After many years of using LISP, I'm taking a class in Java and finding
the two roughly comparable in some ways and very different in other
ways. Each has a decent size library of useful utilities...
|
by: Patrick |
last post by:
Hello all!
I am porting an application from C++ to Java and have run into a
problem using the DataInputStream reader object. The file I am trying
to read in is anywhere from 20 to 60 MB and has a...
|
by: Ole |
last post by:
Goodday everybody,
i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).
The problem is, that i seem too loose my faith. Namely, ( i have...
|
by: Christian Wilhelm |
last post by:
Hi!
I'm trying to call a Java WebService out of a .net Client. There are two
Methods, one Method requires one Parameter of type Parameter, the other
Method requires one Parameter of type...
|
by: Oleg Konovalov |
last post by:
Hi,
I am trying to pass a bunch of checked checkboxes (Javascript array)
from page1 to the Java action class on subsequent web page (page2).
(on page 1 I have a bunch of DB rows with a checkbox,...
|
by: Andrew Bell |
last post by:
I'm doing a uni course in the UK and one of my semesters is about
programming. This is just going to be compilied and executed with no menu
just using command promt (javac classfile.class)
I am...
|
by: south622 |
last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
|
by: rookiejavadude |
last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
|
by: benyboy |
last post by:
hi, after hours of staring at my computer screen, and browsing through various internet forums i am totally stuck!
I have created the following array which reads from an input file the following...
|
by: lilyumestar |
last post by:
This project is due by Tuesday and I haven't even gotten half of it done. Can anyone please help me with this Exception error? I've been trying to figure it out for several hours
Error Message
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
| |