₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,616 members, 8,446,287 topics. Date: Thursday, 16 July 2026 at 11:03 AM

Toggle theme

Urgently Need Assistant On JAVA GUI - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingUrgently Need Assistant On JAVA GUI (1240 Views)

1 Reply (Go Down)

Urgently Need Assistant On JAVA GUI by Akprof(op): 10:04pm On Apr 18, 2015
Please Programmers, how do I use GUI so solve problems where some variable are integer and others are float?
E.g
Code a program that output your Grade Point (GP)
where GP=(Grade Point X Course Unit)/Total Unit.
Taking CSC 400 as a the only course you did with unit 3.
Pls code this by using the GUI and not scanner.

I am expecting your instant responses
thanks.
Re: Urgently Need Assistant On JAVA GUI by Nobody: 10:14pm On Apr 18, 2015
Akprof:
Please Programmers, how do I use GUI so solve problems where some variable are integer and others are float?
E.g
Code a program that output your Grade Point (GP)
where GP=(Grade Point X Course Unit)/Total Unit.
Taking CSC 400 as a the only course you did with unit 3.
Pls code this by using the GUI and not scanner.

I am expecting your instant responses
thanks.
Try dis www.dreamincode.net/forums/topic/165458-gpa-calculator-for-javascript/
Re: Urgently Need Assistant On JAVA GUI by Nobody: 10:40pm On Apr 18, 2015
Since the variable is a score, it might be better to have it in float form to reduce margin of error. You could cast the integer scores to float like so:

score1 = 79

becomes

score1 = (float) score1

So the new value of score1 would be 79.0 instead of 79. Hopefully this is somehow of help to you.
For more info: http://stackoverflow.com/questions/4377842/how-can-i-convert-integer-into-float-in-java
Re: Urgently Need Assistant On JAVA GUI by Akprof(op): 11:24pm On Apr 18, 2015
can u av a try of the coding?
Re: Urgently Need Assistant On JAVA GUI by Nobody: 11:42pm On Apr 18, 2015
Akprof:
can u av a try of the coding?
It's GUI, so it's slightly more work than an ordinary java program. Would love to help but I definitely can't. Good luck though! wink
Re: Urgently Need Assistant On JAVA GUI by Akprof(op): 11:48pm On Apr 18, 2015
thanks
Re: Urgently Need Assistant On JAVA GUI by Nobody: 1:42pm On Apr 19, 2015
I am a newbie in Java, I will advice you to use an app or software that will tell where the errors are and make correction before you compiler and run the code. https://play.google.com/store/apps/details?id=com.java.manager
Re: Urgently Need Assistant On JAVA GUI by danvery2k6(m): 2:03am On Apr 20, 2015
funny question, funny replies.


please tell us where exactly you have problems so we can help you learn. copying and pasting code will by no means help you.
Re: Urgently Need Assistant On JAVA GUI by luksybee(m): 9:18am On Apr 20, 2015
You need to parse your values to a string type...

Label, textbox etc can only have a string value...

Hope you get the idea?
Re: Urgently Need Assistant On JAVA GUI by kudaisi(m): 11:14am On Apr 20, 2015
What have you done so far ?
Re: Urgently Need Assistant On JAVA GUI by kudaisi(m):
Try this should work...
package package.name;

import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class GPACalculator {
public static void main(String[] args){
JTextField gradeField = new JTextField(5);
JTextField unitField = new JTextField(5);
int noOfCourses = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter number of courses:" ));
int grades[] = new int[noOfCourses];
int sumOfGrades = 0;
int totalUnits = 0;
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("Enter grade for course"wink);
myPanel.add(gradeField);
myPanel.add(Box.createHorizontalStrut(15)); // a spacer
myPanel.add(new JLabel("Enter units for course"wink);
myPanel.add(unitField);
for (int i = 0; i < noOfCourses; i++){
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Please Enter Grades and Unit value (e.g A and 3)", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
switch(gradeField.getText().charAt(0)){
case 'A':
sumOfGrades += Integer.parseInt(unitField.getText())*5;
break;
case 'B':
sumOfGrades += Integer.parseInt(unitField.getText())*4;
break;
case 'C':
sumOfGrades += Integer.parseInt(unitField.getText())*3;
break;
case 'D':
sumOfGrades += Integer.parseInt(unitField.getText())*2;
break;
case 'E':
sumOfGrades+= Integer.parseInt(unitField.getText())*1;
break;
default:
JOptionPane.showMessageDialog(null, "Invalid grade"wink;
break;
}
totalUnits += Integer.parseInt(unitField.getText());
unitField.setText(""wink;
gradeField.setText(""wink;

}
}
double gpa = sumOfGrades/(double)totalUnits;
JOptionPane.showMessageDialog(null, "Total Credit :"+totalUnits+" Total Score:"+sumOfGrades+"\n GPA is "+ gpa);
}
}
Re: Urgently Need Assistant On JAVA GUI by Standing5(m): 9:01pm On Apr 20, 2015
OP, did the above work for you?
1 Reply

I Need Help On JavaHow Do I Make My Java GUI Stuff Executable (like desktop shortcut)Urgently Need Assistant On JAVA GUI234

Pys60: Too Late For MeFree Training AlertProgrammers Lets Have Some Fun..., For Intelligent Peeps Please