Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,246 members, 7,815,355 topics. Date: Thursday, 02 May 2024 at 11:11 AM

Urgently Need Assistant On JAVA GUI - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Urgently Need Assistant On JAVA GUI (1079 Views)

I Need Help On Java / How Do I Make My Java GUI Stuff Executable (like desktop shortcut) / Urgently Need Assistant On JAVA GUI (2) (3) (4)

(1) (Reply) (Go Down)

Urgently Need Assistant On JAVA GUI by Akprof(m): 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

1 Like

Re: Urgently Need Assistant On JAVA GUI by Akprof(m): 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(m): 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): 2:21pm On Apr 20, 2015
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);
}
}

2 Likes

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)

Any One Here Able To Design A Webpage For Me? / Sublime Text Editor. / I.T. Person Urgently Needed

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.