Question

Write a Pet UML Diagram

Create your own UML diagram — similar to the above UML diagram — for a Pet class that meets the specification below.

 1. Create the fields indicated below. Use these names exactly as given for your fields. Define them in exactly this order

. • name — The name of the pet, e.g., “Rufus”, “Mittens”, “Smelly”, etc. 

• animal — The type of pet, e.g., “dog”, “cat”, “asparagus”, etc. 

• age — The (integer) number of years the pet has been alive, e.g., 1, 2, 3, etc. 

2. Create a mutator for each of the above in the order listed. Use the standard Java naming convention for mutators.

3. Create an accessor for each of the above in the order listed. Use the standard Java naming convention for accessors. 

4. After creating and drawing the UML diagram, take the UML PreLab quiz and enter each line of data you created for your Pet UML diagram. 

Example: Suppose you are taking the quiz for the example Car UML above instead of your Pet UML. Don’t enter any spaces at all. When the quiz asks: Enter line 1: You would enter: Car 

When the quiz asks: Enter line 2: You would enter: -make:String 

When the quiz asks: Enter line 3: You would enter: -yearModel:int 

When the quiz asks: Enter line 4: You would enter: +setMake(make:String):void 

Don’t enter any of the figures representing the sides of the box

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;

import java.util.Scanner;

class Pet //class Pet

{

   String name; //members of the class as private

   String animal;

   int age;

   public Pet()//default constructor

   {

   }

   public void setName(String name)//method to set name with the passing argument

   {

      name = name;

   }

   public void setAnimal(String animal)//method to set animal type passing argument

   {

      animal = animal;

   }

   public void setAge(int ag)//method to set age of animal

   {

      age = ag;

   }

   public String getName()//get name of the animal

   {

      return name;

   }

   public String getAnimal()//get animal type

   {

      return animal;

   }

   public int getAge()//get animal age

   {

      return age;

   }

}//closing class


class Main//test class

{

   public static void main(String []args)

   {

      String na,type;//needed variables

      int year;

      Pet p = new Pet();//create objects of the class

      p.setName("Rufus");//call mutators for all methods

      p.setAnimal("Dog");

      p.setAge(5);

      na = p.getName();//call accessors and get value, save it to variable

      type = p.getAnimal();

      year = p.getAge();

      System.out.println("Name: "+na +"\nAnimal: "+type +"\nAge: "+year);//print all information

      

   }

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Write a Pet UML Diagram
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT