Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,350 members, 7,822,661 topics. Date: Thursday, 09 May 2024 at 02:39 PM

Urgently Need Assistant On JAVA GUI - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Urgently Need Assistant On JAVA GUI (715 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:22pm 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.

1 Like

Re: Urgently Need Assistant On JAVA GUI by Nobody: 10:54pm On Apr 18, 2015
You can use JOptionpane. Its not a hard assignment since you are taking just one course. What IDE are you using to write your code?
Re: Urgently Need Assistant On JAVA GUI by Akprof(m): 10:57pm On Apr 18, 2015
I have used JOptionPane, but final output I want does show. I am using eclipse
Re: Urgently Need Assistant On JAVA GUI by Nobody: 11:01pm On Apr 18, 2015
can you paste your code here? Am more familiar with netbeans but lets see.
Re: Urgently Need Assistant On JAVA GUI by Akprof(m): 11:06pm On Apr 18, 2015
import javax.swing.JOptionPane;
import java.util.*;
public class myjavaass2 {
public static void main (String args[]){
int score_p, load,t_unit;
Float gp;
String x,y,z,u = null;
//Capturing Data
x=JOptionPane.showInputDialog("Input Your Score:"wink;
y=JOptionPane.showInputDialog("Enter Your Credit Load Unit:"wink;
z=JOptionPane.showInputDialog("Input Your Total Credit Unit:"wink;
//Convert
score_p=Integer.parseInt(x);
load=Integer.parseInt(y);
t_unit=Integer.parseInt(z);
gp=Float.parseFloat(u);
gp=(float) (score_p*load/t_unit);
//Outputting
JOptionPane.showMessageDialog(null,"My Grade Point is: "+gp);
}
}
Re: Urgently Need Assistant On JAVA GUI by Nobody: 11:11pm On Apr 18, 2015
Since you already declared your variable with the correct data type, why converting it again?


Modified: You captured your data as string. Most programming languages are very stubborn at converting strings to integer or float, i will advise you to collect your data as int and float as the case may be. Just change where you declared them as string to int or float as the case may be.

Also, while calculating your gp, the assignment you did there looks strange, you put float in the bracket. Why? For clarity and accuracy, always do your calculations using bodmas and store your result into a variable for each operation.
Re: Urgently Need Assistant On JAVA GUI by Akprof(m): 11:21pm On Apr 18, 2015
U need to convert because GUI is always in string form
Re: Urgently Need Assistant On JAVA GUI by olyjosh(m): 9:14am On Apr 19, 2015
Are you getting error? Null pointer I guess. That is beacause variable u is null and you are passing it to float.
What is u in your program
Re: Urgently Need Assistant On JAVA GUI by kudaisi(m): 2:25pm 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);
}
}

(1) (Reply)

SSH Keys Generated On Debian Vulnerable / * / I Need Your Help

(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. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.