Thursday, April 16th, 2009 | Author: AngelicLight
newage
ifyouhadthechance asked:


here is the problem:

For this assignment, you will program the template class Tamagotchi that models a Tamagochi, as well as an application class that simulates playing the toy.
To get started, model a Tamagotchi by its name, type, color, current age, fullness and happiness status both represented by an integer, and its sick status, which is a boolean. The types of Tamagotchi are Duck, Bear, Fresh Prince, and Temple Guard. Make all data fields private and write setter/getter methods for each of these. Write a constructor for the class which sets default values for all instance variables.

First, you must prompt the user to enter a name, type and color for their Tamagotchi. These three prompts will not be done within methods of the Tamagotchi class, but directly input from the main method in the application class and assigned to the virtual pet using the corresponding “set” methods….

thats just the first part of the problem. i got stuck because i had a coding error “cannot find constructor Tamagotchi” line 22). here is my template as well as my program thus far.

template class:

public class Tamagotchi{

//define defaults
String name;
String type;
String color;
int age;
int happiness;
int hunger;
boolean sick;

public Tamagotchi(){
name = “noName”;
type = “none”;
color = “none”;
age = 0;
happiness = 4;
hunger = 4;
sick = false;
}

//display stats
public void displayStats() {
System.out.println(”Your tamogotchi’s name is ” + name + “.”);
System.out.println(”Your tamogotchi is a ” + type + “.”);
System.out.println(”The tamogotchi is ” + color + “.”);
System.out.println(”The tamogotchi’s age is ” + age + “.”);
System.out.println(”The tamogotchi’s happiness is ” + happiness + “.”);
System.out.println(”The tamogotchi’s hunger is ” + hunger + “.”);
}

//name
public String getName(String newName){
name = newName;
return name;
}
//type
public String getType(String newType){
type = newType;
return type;
}
//color
public String getColor(String newColor){
color = newColor;
return color;
}
//age
public int getAge(int newAge){
age = newAge;
return age;
}
//happiness level
public int getHappiness(int newHappiness){
happiness = newHappiness;
return happiness;
}
//hunger level
public int getHunger(int newHunger){
hunger = newHunger;
return hunger;
}
//sick or not
public boolean getSick(boolean sickness){
sick = sickness;
return sick;
}
}

the application class:

import java.util.Scanner;

public class Tamagotchis{
public static void main(String[] args){

//define a scanner
Scanner input = new Scanner(System.in);

//get user input for a name, type, and color
System.out.println(”Please enter a name for your new pet: “);
String petname = input.nextLine();
System.out.println(”What type of tamagotchi is ” + petname + “? You can choose a duck, bear, fresh prince, or temple guard.”);
String pettype = input.nextLine();
while ((pettype != “duck”) || (pettype != “bear”) || (pettype != “fresh prince”) ||(pettype != “temple guard”)){
System.out.println(”Sorry, that is not one of your choices! Please choose from a duck, bear, fresh prince, or temple guard”);
pettype = input.nextLine();
}
System.out.println(”What color should ” + petname + ” be?”);
String petcolor = input.nextLine();

//create tamagotchi object
Tamagotchi newpet = new Tamagotchi(petname, pettype, petcolor);

//print out the tamagotchi’s current status
newpet.displayStats();
}
}

Cooper

Category: theage
You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

One Response

  1. For the following parameters petname pettype and type of arguments as the one that accepts the class named tamagotchi that accepts the same order and type of arguments as the class named tamagotchi that accepts the class named tamagotchi that accepts.
    For the same order and type of arguments as the following parameters petname pettype and petcolor.