• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Any problem with my code what more to add on???

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.Scanner;
public class JPetWorld
{
public static void main (String[] args){
Pet p = new Pet( "Meow meow", 'F' );
Scanner sc = new Scanner (System.in);
System.out.print("Press enter to proceed") ;
sc.nextLine() ;
private String name;
private char gender;
private String hunger;
private String mood;
private String cleanliness;

public Pet(String _name, char _gender){
name = _name;
gender = _gender;
}
public void buyAccomodation(String accom) {}
public int buyFood(int num){return 1;}
public void feed() {}
public void playFetch() {}
public void playHideAndSeek() {}
public void bath() {}
public void advanceDay() {}
public void bidFarewell() {}
}

You are given the Pet class with the following class diagram.
Pet

name: String
gender: char
hunger: String
mood: String
cleanliness: String


Pet(name: String, gender: char)
buyAccomodation(accom: String)
buyFood(num: int): int
feed()
playFetch()
playHideAndSeek()
bath()
advanceDay()
bidFarewell()

Using the Pet class given, you are required to write the JPetWorld program according to the following requirements.

a. Declare one integer called foodQuantity presenting the quantity of pet food the owner has. Initialise it to zero.

b. Choose Pet
Prompt and read from the user
- the pet name
- the pet gender ( a char)

and create a Pet object using the information entered.

c. Choose Pet Accomodation
Prompt and read from the user
- the type of pet accomodation (sofa or basket)

Then call the buyAccommodation method of the pet object to buy an accommodation using the information entered.

d. Buy Pet Food
Prompt and read from the user
- the quantity of pet food to buy

Call the buyFood method of the pet object using the information entered. The buyfood method will return an integer representing the actual quantity of food bought. This is because the shop may not have enough quantity of pet food that the owner wants to buy. Thus the actual quantity may be lesser than the quantity the user intended to buy. Set the foodQuantity variable to the actual quantity of food bought.

e. Menu
Write a loop that will loop 10 times. In the loop, do the following:
- display a menu and prompt as follows:
Menu
1. Check pet food quantity
2. Feed Pet
3. Play with pet
4. Bath pet
5. Advance to next day
6. Bid farewell and Exit

Enter choice


- Read the user input.

- Choice 1 (Check pet food quantity)
If the user selects choice 1, display the value of the variable foodQuantity in the following format:




- Choice 2 (Feed pet)
If the user selects choice 2, test if the value of the variable foodQuantity is greater than zero. If it is,
� Call the feed method of the pet object
� Decrease the foodQuantity variable by 1
� Display the message �Pet is eating food�slurp, slurp�
Else,
� Only display �Not enough food to feed pet!�


- Choice 3 (Play with pet)
If the user selects choice 3, display the following submenu and prompt:

1. Play fetch
2. Play hide and seek

Enter choice:

Read the user input.
If the owner selects choice 1, call the playFetch method of the pet object.
If the owner selects choice 2, call the playHideAndSeek method of the pet object.

- Choice 4 (Bath pet)
If the user selects choice 4, prompt and read from the owner for the temperature of the bath water.
If the temperature of the bath water is below 20oC, display �Cannot bath. Too cold!�.
If the temperature of the bath water is above 40oC, display �Cannot bath. Too hot!�.
Else, call the bath method of the pet object and display �Pet is bathing�splash, splash!�

- Choice 5 (Advance day)
If the user selects choice 5, call the advanceDay method of the pet object.

- Choice 6 (Bid farewell and Exit)
If the user selects choice 6, call the bidFarewell method of the pet and then terminate the loop.

- Other input
If the user enters any other input, display the message �Invalid choice.�
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is this supposed to be?



If it's a method it needs a return type and you shouldn't capitalize it. If it's a constructor it's named wrong.

Edit: I believe it's also in the wrong place. You can't have either a method or constructor inside another method.

Edit#2: Also doesn't appear that you close your class with a closing }.

When posting code use the code tags.

[ August 19, 2005: Message edited by: Hentay Duke ]
[ August 19, 2005: Message edited by: Hentay Duke ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why did you post the exact same here question again instead of adding to the thread you started yesterday?

Your code here is for class JPetWorld. Where is the code for your Pet class?
[ August 19, 2005: Message edited by: Marilyn de Queiroz ]
 
kel lim
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry what u mean by pet class .....sorry i dont really understand i also do not know how to use the pet class that teacher given me
 
reply
    Bookmark Topic Watch Topic
  • New Topic