Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: gottaCatchEmAll

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default gottaCatchEmAll

    Hello, my name is Fade and I am trying to practice with making classes, getters and setters and thaught up this code. Its supposed to get a random number x and a random boolean caughtOne; and weigh it against your pound test and tell you if you got a fish or not and how many pounds it was.

     
    package Practice;
     
     
    public class Fish {
    	Random r = new Random();
    	public static final int linetest = 8;
    	private int x = 0;
    	private boolean caughtOne = false;
     
    	// x = r.nextInt(10)+1;
    	// boolean caughtOne1 = r.nextBoolean();
     
    	public void fish(int x, boolean caughtOne) {
    		this.x = x;
    		this.caughtOne = caughtOne;
    	}
     
    	public void setX(int x) {
    		x = r.nextInt(10) + 1;
    	}
     
    	public void setcaughtOne(Boolean caughtOne) {
    		caughtOne = r.nextBoolean();
    	}
     
    	int getX() {
    		return x;
    	}
     
    	Boolean getcaughtOne() {
    		return caughtOne;
    	}
     
    	public void takeTheBait() {
    		if (this.caughtOne == true) {
     
    		} else {
     
    		}
    	}
     
    	public void gotIt(int linetest) {
    		if (this.x > linetest) {
    			System.out.println("you broke the line");
    		} else
    			System.out.println("you caught an " + x + "lbs fish");
     
    	}
     
    }
     
     
    public class Fishing {
    	public static void main(String[] args) {
    		Fish fishy = new Fish();
    		fishy.fish(0,false);
     
    	}
    }


    --- Update ---

    sorry i tried to post the code the correct way but i guess i messed it up.
    Last edited by Norm; October 6th, 2014 at 09:20 PM. Reason: Added []s to code tags

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: gottaCatchEmAll

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Did you have a question, need help with something, or are you just showing your code?

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: gottaCatchEmAll

    Thank you GregBrannon, Like I said I tried to post it in the right format but wasnt quite sure how to do so.

  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: gottaCatchEmAll

    Just wondering but what IDK are you using. I know in eclipse there is a way you can have it generate the getter and setters for you, its pretty nice.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: gottaCatchEmAll

    You're welcome, but Norm fixed your code tags.

    I still don't know what your question is, if you have one.

  6. #6
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: gottaCatchEmAll

    well this code has both my main and my class. I am trying to write a main that will call my class generate a random number and boolean and tell you if you caught a fish or not. this code does have two different java programs in it sorry for the confusion

    --- Update ---

    I am using eclipse

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: gottaCatchEmAll

    I am trying to write a main that will call my class generate a random number and boolean and tell you if you caught a fish or not.
    I assume therefore that it is not doing what you'd hoped. What is it doing? What would you prefer it do? If you're getting error messages, post the entire text of the message.

    It's unreasonable of you to expect us to run your uncommented code, figure out what it's supposed to do, fix errors, debug it, and explain to you what's wrong and what you should do to fix it. You tell us what you've done to accomplish those things, and ask for help when you need help to complete that recipe to a successful product.