Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34
  1. #21
    Quizzle23 is offline Member
    Join Date
    Feb 2011
    Posts
    34
    Rep Power
    0

    Default

    Oh also how is there a certain way you have to format PI? I'm getting an error saying final parameter PI may not be assigned. I have tried PI, Pi and pi. This is off my first program so I have to get PI and set PI. I'm confused. lol

  2. #22
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,781
    Rep Power
    7

    Default

    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.
    Java Code:
    String s;
    if(false) {
        s = "hello";
    }
    System.out.println(s);
    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.

  3. #23
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Quizzle23 View Post
    No one is upset and I was not cheating, just trying to find an easier way to display my code. Oh by the way 1 I'm not a dude and 2 I got an A.

    Anyways for those who are not jerks. How would I divide 3 different items?
    For instance:

    If testDays needs to equal testWidgets / testHours / testProduction. How would it be formatted? I have tried everything in my book but it will not compile. Thanks in advance
    This was not pointed to you but to some jerk who's posts have now been removed who was a real plague to the site yesterday.

  4. #24
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    This was not pointed to you but to some jerk who's posts have now been removed who was a real plague to the site yesterday.
    I can confirm that; reply #7 and #8 don't make sense anymore and can be removed (if possible). Sometimes a little idiot disturbs the forums, yesterday there was one of them that wanted to make a fool of himself after he wasn't spoonfed.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #25
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by masijade View Post
    This was not pointed to you but to some jerk who's posts have now been removed who was a real plague to the site yesterday.
    Even I have also made that clear to the OP in my previous post.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  6. #26
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    And I thank you.

  7. #27
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Whoops! replied to an old comment :D -removed-

  8. #28
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by masijade View Post
    And I thank you.
    You Are Welcome! :D
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  9. #29
    Quizzle23 is offline Member
    Join Date
    Feb 2011
    Posts
    34
    Rep Power
    0

    Default

    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!");
    	}
    }

  10. #30
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Java Code:
    testDays = (testWidgets / testHours) / (testEnding) ; }
    Uhm, what is that brace "}" for?

  11. #31
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by masijade View Post
    Java Code:
    testDays = (testWidgets / testHours) / (testEnding) ; }
    Uhm, what is that brace "}" for?
    It balances the superfluous { before "testWidgets =".

    -Gary-

  12. #32
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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?

  13. #33
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    @masijade: Just want to point out that I'm not OP. I just answered your question because it was there. :-)

    -Gary-

  14. #34
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by gcalvin View Post
    @masijade: Just want to point out that I'm not OP. I just answered your question because it was there. :-)

    -Gary-
    I know, that last post wasn't directed at you though. ;-)

    I was a bit blind missing the block opening brace.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. The null message is driving me crazy
    By Yakg in forum New To Java
    Replies: 5
    Last Post: 12-02-2010, 07:03 PM
  2. image does not refresh-driving me crazy
    By jambon in forum AWT / Swing
    Replies: 1
    Last Post: 04-09-2010, 04:25 PM
  3. THIS PROGRAM IS DRIVING ME CRAZY!!! help fixing it
    By syntrax in forum New To Java
    Replies: 2
    Last Post: 12-18-2009, 04:27 AM
  4. Loop driving me loopy!!!!!
    By soc86 in forum New To Java
    Replies: 8
    Last Post: 01-16-2009, 01:00 AM
  5. Errors driving me crazy! although compiles fine
    By irishsea2828 in forum New To Java
    Replies: 1
    Last Post: 04-08-2008, 03:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •