Results 1 to 6 of 6
Thread: Basic Puppy Program
- 01-06-2013, 07:47 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 2
- Rep Power
- 0
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(); }
once the Lunch(); method is called, this is what the dog will say...
Java Code:public static void Lunch(){ System.out.println("Wooooolf..."); }
- 01-06-2013, 09:04 AM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 301
- Rep Power
- 9
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!
- 01-06-2013, 09:20 AM #3
Re: Basic Puppy Program
... and you can use a Timer.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 01-07-2013, 06:47 AM #4
Member
- Join Date
- Jan 2013
- Posts
- 2
- Rep Power
- 0
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"); } }
@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 onlineLast edited by greeny; 01-07-2013 at 06:52 AM.
- 01-07-2013, 09:49 AM #5
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 301
- Rep Power
- 9
Re: Basic Puppy Program
Java Code: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!
- 01-08-2013, 12:00 AM #6
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
Similar Threads
-
Have too many decimals in my basic program! Please help!
By md33 in forum New To JavaReplies: 4Last Post: 10-30-2012, 10:36 AM -
need help to figure out basic java program
By shane123 in forum New To JavaReplies: 21Last Post: 12-02-2011, 05:12 AM -
Assistance with Basic authentication program
By Fargo94 in forum New To JavaReplies: 4Last Post: 05-17-2011, 10:22 AM -
3 basic program
By jasskulainen in forum New To JavaReplies: 3Last Post: 09-27-2009, 02:39 PM -
Basic Program Please Help!!
By VinceGuad in forum New To JavaReplies: 3Last Post: 02-01-2008, 04:35 PM
Bookmarks