|
-
September 23rd, 1999, 01:52 PM
#1
java programming
hello. I need some help with a little program I was trying to write. myBook does not give such good examples. It is a program that should print out a dogs name age and speak. It should also print out a fetching line which I am still having a little but of problems with.
I appreciate all e-mail back to me and any response to this..
thanks
karen
[email protected]
public class p1{
Public static void main(String[]args)
{
//what should i be writing here???
}
Public static void dogyears(Dog d)
{
//(what should i be writing here???
//It says a static method to access a dog object and display the Dog's age in "dogyears" means human //age *7 )
}
class Dog
{
private String name;
private int age;
private int speed;
Dog()
{}
Dog( String n, int a, int s)
{
name = n;
age = a;
speed = s;
}
String getName()
{
return name;
}
int getAge()
{
return age;
}
int getSpeed()
{
return speed;
}
void showDog()
{
System.out.println( getName()
+ " is "
+ getAge()
+ " years old and runs "
+ getSpeed()
+ " feet per second.");
}
void fetch( int feet)
{
System.out.println( getName()
+ " retrieved a ball thrown "
+ feet
+ " feet in "
+ 2 * ( feet / getSpeed() )
+ " seconds.");
}
void speak()
{
String [] msg = { "Woff Woff", "Ruff Ruff", "Arf Arf", "Grrr"};
int index= (int)(Math.random()*msg.length);
System.out.println(name + " says \""+msg[index]+"\".\n");
}
}
thanks again
hello. I need some help with a little program I was trying to write. myBook does not give such good examples. It is a program that should print out a dogs name age and speak. It should also print out a fetching line which I am still having a little but of problems with.
I appreciate all e-mail back to me and any response to this..
thanks
karen
[email protected]
public class p1{
Public static void main(String[]args)
{
//what should i be writing here???
}
Public static void dogyears(Dog d)
{
//(what should i be writing here???
//It says a static method to access a dog object and display the Dog's age in "dogyears" means human //age *7 )
}
class Dog
{
private String name;
private int age;
private int speed;
Dog()
{}
Dog( String n, int a, int s)
{
name = n;
age = a;
speed = s;
}
String getName()
{
return name;
}
int getAge()
{
return age;
}
int getSpeed()
{
return speed;
}
void showDog()
{
System.out.println( getName()
+ " is "
+ getAge()
+ " years old and runs "
+ getSpeed()
+ " feet per second.");
}
void fetch( int feet)
{
System.out.println( getName()
+ " retrieved a ball thrown "
+ feet
+ " feet in "
+ 2 * ( feet / getSpeed() )
+ " seconds.");
}
void speak()
{
String [] msg = { "Woff Woff", "Ruff Ruff", "Arf Arf", "Grrr"};
int index= (int)(Math.random()*msg.length);
System.out.println(name + " says \""+msg[index]+"\".\n");
}
}
thanks again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|