-
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...
Code:
if (input == 1){
Lunch();
}
Lunch method
once the Lunch(); method is called, this is what the dog will say...
Code:
public static void Lunch(){
System.out.println("Wooooolf...");
}
so pretty much I want it to do, Lunch +1.
-
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++;
-
Re: Basic Puppy Program
... and you can use a Timer.
db
-
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:
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
-
Re: Basic Puppy Program
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()
-
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.