Question

JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for...

JAVA PLEASE HELP

The following is a UML diagram for a class. Write the code for this class.

Cat

- breed : String

- color : Color

- name : String

+ Cat( name : String)

+ Cat(name : String, breed : String, color : Color)

+ getName() : String

+ getColor() : Color

+ getBreed() : String

setColor(Color)

setBreed(Breed)

toString()

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

public class Cat
{

String name;
String breed;
String color;

public Cat(String name, String breed, String color)
{
this.name = name;
this.breed = breed;
this.color = color;
}

public String getName()
{
return name;
}
public String getBreed()
{
return breed;
}
public String getColor()
{
return color;
}
@Override
public String toString()
{
return("Hi I am "+ this.getName()+
".\nMy breed and color is " +
this.getBreed()+"," + this.getColor());
}
public static void main(String[] args)
{
Cat obj= new cat("Tommy","Persian cat", "Black");
System.out.println(Tommy.toString());
}
}


output:
Hi I am Tommy

My breed and color is Persian cat , black

According to my understanding i am providing the program Thanks Have a great day.

Add a comment
Know the answer?
Add Answer to:
JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for...
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
  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...

  • Draw the UML class diagram in Java and write theequivalent Java code.Exercise 6 Person...

    Draw the UML class diagram in Java and write the equivalent Java code.Exercise 6 Person + name: string + age : int=0 Student + grades: list Professor + listofstudents : list

  • Answer the following questions regarding the UML Diagram: Human 998 - name: String - breed: String...

    Answer the following questions regarding the UML Diagram: Human 998 - name: String - breed: String + name: String + phone: Int kitties + Cat(name: String, breed: String) + getName(): String + setName(name: String): void What symbol would i put in front of breed to make it a private attribute of Cat? it is already private none of the above

  • Can the folllowing be done in Java, can code for all classes and code for the...

    Can the folllowing be done in Java, can code for all classes and code for the interface be shown please. Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometriObject class for finding the larger of two GeometricObject objects. Write a test program that uses the max method to find the larger of two circles, the larger of two rectangles. The GeometricObject class is provided below: public abstract class GeometricObject { private...

  • This is the question about object-oriend programming(java) please show the detail comment and prefect code of...

    This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...

  • 1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe...

    1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe -name: string -cookTime: int -prepTime: int - ingredients: ArrayList<String> +Recipe(String name, int cTime, int pTime, String... ingredients) +Recipe(String name, int cTime, int pTime) +getNumberOfIngredients(): int +addIngredient(String ingredient): void +getName(): String +getTotalRecipeTime(): int +get Ingredient(int index): String +remove Ingredient(String ingredient): String

  • in java language please Question 2 (14 marks) a) Complete the following UML diagram as lava...

    in java language please Question 2 (14 marks) a) Complete the following UML diagram as lava classes (8 marks): Write a constructor for Computer ser class based on the information you have in the UML Complete the hasSpaces method to check if a string has space or not il. Extend ComputerUser class with two subclasses, as shown below in UML diagram and write the appropriate methods listed in the UML diagram <<abstract>> ComputerUser # username: String #password: String + Computer...

  • Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the...

    Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the Comparable and Cloneable interfaces. //GeometricObject.java: The abstract GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color;...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • Write in java and the class need to use give in the end copy it is...

    Write in java and the class need to use give in the end copy it is fine. Problem Use the Plant, Tree, Flower and Vegetable classes you have already created. Add an equals method to Plant, Tree and Flower only (see #2 below and the code at the end). The equals method in Plant will check the name. In Tree it will test name (use the parent equals), and the height. In Flower it will check name and color. In...

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