Results 21 to 34 of 34
- 02-22-2011, 05:15 AM #21
Member
- Join Date
- Feb 2011
- Posts
- 34
- Rep Power
- 0
- 02-22-2011, 05:23 AM #22
Well it does help if you post the code that is causing you problems.
x / y / z works perfectly fine in Java. So something is wrong with your code which we cannot see.
As for PI, what the error is saying is that there is a possible path through your code were PI is not given a value.
Since the if statement is never entered the varaiable s never has a value assigned. This is what the complier is complaining about. So give PI a value.Java Code:String s; if(false) { s = "hello"; } System.out.println(s);
- 02-22-2011, 08:01 AM #23
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 02-22-2011, 08:50 AM #24
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-22-2011, 01:33 PM #25
Even I have also made that clear to the OP in my previous post.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 02-22-2011, 01:40 PM #26
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
And I thank you.
- 02-22-2011, 02:29 PM #27
Whoops! replied to an old comment :D -removed-
- 02-22-2011, 03:36 PM #28
- 02-24-2011, 04:07 AM #29
Member
- Join Date
- Feb 2011
- Posts
- 34
- Rep Power
- 0
This code is really log but here goes.
Java Code:public class Widgets { private String name; private int hoursWorked; private int perHour; private int totalDays; public Widgets(String widgets, int production, int hours, int days) { name = widgets; hoursWorked = production; perHour = hours; totalDays = days; } public void setName(String widgets) { name = widgets; } public void setHoursWorked(int production) { hoursWorked = production; } public void setPerHour(int hours) { perHour = hours; } public void setTotalDays(int days) { totalDays = days; } public String getName() { return name; } public int getHoursWorked() { return hoursWorked; } public int getPerHour() { return perHour; } public int getTotalDays() { return totalDays; } }Java Code:import javax.swing.JOptionPane; public class TestWidgets { public static void main (String [] args) { String testWidgets; int testHours; int testProduction; int testDays; { testWidgets = JOptionPane.showInputDialog("What is your current quota?"); testHours = Integer.parseInt( JOptionPane.showInputDialog("How many hours have been worked? ")); testProduction = Integer.parseInt( JOptionPane.showInputDialog("Currently how many Widgets are you making per hour?")); testDays = (testWidgets / testHours) / (testEnding) ; } JOptionPane.showMessageDialog(null, "You need " + testWidgets + "." + " \nCurrently you have worked" + testHours + " hours. \nHow many Widgets are you currently making per hour? " + testProduction + "\nIt will take you " + testDays + " days to meet" + " your quota!"); } }
- 02-24-2011, 07:37 AM #30
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Uhm, what is that brace "}" for?Java Code:testDays = (testWidgets / testHours) / (testEnding) ; }
- 02-24-2011, 07:45 AM #31
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
- 02-24-2011, 07:53 AM #32
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
So then, what, exactly, is your problem? Let me guess, you have a division by 0. Make sure that "testHours" and "testEnding" are not 0 before doing your division.
Edit: You do, however, realise that you will result in rounded down, whole numbers, right?
- 02-24-2011, 07:55 AM #33
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
@masijade: Just want to point out that I'm not OP. I just answered your question because it was there. :-)
-Gary-
- 02-24-2011, 08:00 AM #34
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
The null message is driving me crazy
By Yakg in forum New To JavaReplies: 5Last Post: 12-02-2010, 07:03 PM -
image does not refresh-driving me crazy
By jambon in forum AWT / SwingReplies: 1Last Post: 04-09-2010, 04:25 PM -
THIS PROGRAM IS DRIVING ME CRAZY!!! help fixing it
By syntrax in forum New To JavaReplies: 2Last Post: 12-18-2009, 04:27 AM -
Loop driving me loopy!!!!!
By soc86 in forum New To JavaReplies: 8Last Post: 01-16-2009, 01:00 AM -
Errors driving me crazy! although compiles fine
By irishsea2828 in forum New To JavaReplies: 1Last Post: 04-08-2008, 03:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks