Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Open IntelliJ and create a new project. When selecting the project location, choose the folder winter20-zoo that you just cloned from GitHub. Review the existing
- Open IntelliJ and create a new project. When selecting the project location, choose the folder winter20-zoo that you just cloned from GitHub.
- Review the existing code in the project (but don't change anything yet). Note the following classes:
- Animal - This is the superclass of all animals in the zoo. Every animal has a name and can introduce itself by name.
- ZooMain - This is the class that contains the main method in which every animal introduces itself.
- Reindeer - This is a sample animal class that is a subclass of Animal - notice that it extends Animal. The reindeer has a noseColor property that is specific to reindeer. Reindeer overrides the introduce method in Animal to include not only its name (by calling super.introduce()) but also its special property noseColor in its introduction.
- Depending on when you clone the repository, there may be a variety of other classes in the project that other students have already contributed and the instructor has merged.
- Run the main method in ZooMain to see what the output is.
- Your task is to add an animal to the zoo based on the Issue you selected.
- You will be following the steps to Add Features and Open Pull Request, but will not merge your pull request.
- Before you add or change any code, create a branch for your feature. Name the branch after your animal. E.g.,
git branch lion git checkout lion
- Commit periodically as you work on your feature.
- Add a class for your animal.
- Examples: A lion could have a roarVolume (String such as "loud", "soft"); a zebra could have a numberOfStripes (int).
- Name the class after your animal species, e.g., Lion.
- Make your class a subclass of Animal.
- Add a property to your class that is specific to your animal. Feel free to be creative.
- In your animal species class, override Animal's introduce() method. Start by calling super.introduce() so the animal's name will be included in their introduction. Then write a statement that prints a sentence including the animal's species and its custom property.
- Update the main method in ZooMain to create an animal from your new class and introduce itself.
- Remember to Test.
- When everything works and looks good, push your branch to GitHub. E.g.,
git push origin lion
- On GitHub, create a pull request for your branch. In the pull request message, including the text "Closes #x" where x is your Issue number. This will cause the issue to be automatically closed when your feature is merged.
- Do not merge your pull request. The instructor will merge pull requests after reviewing them.
- Look at the open pull requests (if you are the first, there may not be any yet - you'll have to check back). Review someone else's pull request and write a comment on their pull request. If you see any problems you can let them know. If everything looks good you can say so.
here's the codes for winter20-zoo
Animal.java
/** | |
* An animal in a zoo | |
* | |
* @author | |
* @version 2020.02.01 | |
*/ | |
public class Animal { | |
private String name; | |
/** | |
* Create a zoo animal with the given name | |
* @param name | |
*/ | |
public Animal(String name) { | |
this.name = name; | |
} | |
/** | |
* @return this animal's name | |
*/ | |
public String getName() { | |
return name; | |
} | |
/** | |
* Print a message introducing this animal | |
*/ | |
public void introduce() { | |
System.out.println("Hi, my name is " + name + "."); | |
} | |
} |
Reindeer.java
/** | |
* A reindeer in a zoo | |
* @author | |
* @version 2020.02.01 | |
*/ | |
public class Reindeer extends Animal { | |
private String noseColor; | |
/** | |
* Create a reindeer with the given name and nose color | |
* @param name | |
* @param noseColor | |
*/ | |
public Reindeer(String name, String noseColor) { | |
super(name); | |
this.noseColor = noseColor; | |
} | |
@Override | |
public void introduce() { | |
super.introduce(); | |
System.out.println("I'm a reindeer with a " + noseColor + " nose."); | |
} | |
} |
ZooMain.java
/** | |
* Introduce all the animals in the zoo | |
* | |
* @author PoChin Cheng | |
* @version 2020.02.01 | |
*/ | |
public class ZooMain { | |
public static void main(String[] args) { | |
System.out.println("---------- Zoo Animals, Introduce Yourselves: ----------"); | |
Reindeer reindeer = new Reindeer("Rudolph", "red"); | |
reindeer.introduce(); | |
} |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started