Stats: 3,191,719 members, 7,945,238 topics. Date: Tuesday, 10 September 2024 at 01:02 PM |
Nairaland Forum / Science/Technology / Programming / Urgently Need Assistant On JAVA GUI (737 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)
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:" ![]() y=JOptionPane.showInputDialog("Enter Your Credit Load Unit:" ![]() z=JOptionPane.showInputDialog("Input Your Total Credit Unit:" ![]() //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; |
(1) (Reply)
We Need An ASP.NET Developer( Urgently) / This Nairaland has a lot of problems / React Native Vertical Scrollview Example Android
(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. 15 |