Results 1 to 6 of 6
  1. #1
    greeny is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Basic Puppy Program

    Hello I am creating a simple dog, I need help making the value add a +1. Basically you select an interaction to do with the dog. The dog then accepts the interaction, but adds a plus 1. I want it so if you feed the dog a number of times too quickly, then the dog will die. Also I need help making it so that after a min, the value -1 so that the dog will become hungry again.

    So pretty much this makes it so that if the dog eats too much- it dies, and if it eats to little- it dies. As you feed the dog the value goes +1, but if you dont feed for a min it -1. (+10 = over-fed/dead | -10 = under-fed/dead | 0 = healthy)




    Lunch inside Main method
    this is an IF statement, so if they choose input == 1 then it should add +1 to lunch...
    Java Code:
    		if (input == 1){
    		Lunch();
    		}
    Lunch method
    once the Lunch(); method is called, this is what the dog will say...
    Java Code:
    	public static void Lunch(){
    		System.out.println("Wooooolf...");
    	}
    so pretty much I want it to do, Lunch +1.

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Basic Puppy Program

    I do not understand what your exect problem is... is it the timing? The adding up of a value? Both?
    You may get the current system time with System.currentTimeMillis();
    You may declare a variable that stores your dogs food: int iMyDogFood = 0;
    You may increment this by using iMyDogFood++;
    I like likes!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Basic Puppy Program

    ... and you can use a Timer.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    greeny is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: Basic Puppy Program

    Hello everyone thanks for the reply. Yes the Timer sounds like what I am trying to add although I don't know how to implement it. Most of my code is made with printed code, so its not very complex & could probably be revise by someone with better skill then me(since i'm a beginner). My current code is as shown:

    Java Code:
    /*
     * Basic Call function in use here, for testing
     */
    
    import java.util.Scanner;
    
    public class TestPup1{
    	public static void main(String []args){
    		Scanner in = new Scanner(System.in);
    		System.out.println("Name your new puppy.");
    		String name = in.nextLine();
    		System.out.println("Choose what interaction to do...");
    		System.out.println("1 = lunch time, 2 = bad puppy");
    		System.out.println("---------------------------------------------------------------");		
    		int lunch = 0, bark = 0;
    		int input = in.nextInt();
    				
    		if (input == 1){
    		Lunch();
    		lunch = +1;
    		}
    		else if (input == 2){
    		Bark();
    		bark = +1;
    		}
    		else{
    			System.out.println("You select an interaction to do with the puppy...");
    		}
    		
    		//Beginning of the IF statements for whether or not the puppy gets TOO MUCH or TOO LITTLE care.
    		//Note: Fix error: the bark death message keeps popping up without being called for.. 
    		
    		if (bark < 4){
    			System.out.println("You scold your dog too much, maybe the pup wasnt best for you? It has died from abuse.");
    		}
    		else if (lunch < 10){
    			System.out.println("Your dog has been over fed... and has sadly died from being over weight.");
    		}
    		else if (lunch > 10){
    				System.out.println("Your dog has been under fed... and has sadly died from starvation.");
    		}
    	}
    	
    	public static void Bark(){
    		System.out.println("Grrrr...!");
    		System.out.println("You scolded your dog for being bad, hope the puppy learn its lesson.");
    	}
    	
    	public static void Lunch(){
    		System.out.print("Wooooolf...");
    		System.out.println("You have fed your dog, be sure to feed him every few minutes");
    	}
    	
    	
    }
    This is my first attempt to make my own program, although simple. It may be a little messy, hopefully it wont confuse anyone =D.
    @Sierra
    My problem is Timing & Adding the values ;). I want the time to remove -1 from the current amount every MINUTE. But i also want it as to where you click the interaction, the value adds +1 to the current amount. Hope that is easier to understand.

    @Darryl
    Sure, i will try to find a timer example online
    Last edited by greeny; 01-07-2013 at 05:52 AM.

  5. #5
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Basic Puppy Program

    Java Code:
    lunch = +1;
    Here you always assign lunch to be 1. I think you want to ADD it up here which would be "lunch = lunch + 1;" or "lunch++;" or "lunch += 1;"

    For the timing you may either use the Timer as Darryl said or create your own loop using what I said above fetching the system time and checking whether it is 60 seconds after the last stored time.

    Please note that methods should start by convention with a lower case letter:
    public static void Bark()
    should be
    public static void bark()
    I like likes!

  6. #6
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: Basic Puppy Program

    You may also want to place code from line 16 - line 41 inside a while loop so that the program will continue running. The way it is written now, it will run through only once.

Similar Threads

  1. Replies: 4
    Last Post: 10-30-2012, 09:36 AM
  2. need help to figure out basic java program
    By shane123 in forum New To Java
    Replies: 21
    Last Post: 12-02-2011, 04:12 AM
  3. Assistance with Basic authentication program
    By Fargo94 in forum New To Java
    Replies: 4
    Last Post: 05-17-2011, 09:22 AM
  4. 3 basic program
    By jasskulainen in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 01:39 PM
  5. Basic Program Please Help!!
    By VinceGuad in forum New To Java
    Replies: 3
    Last Post: 02-01-2008, 03:35 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
  •