The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
C&O: Dog
a) Write a class to represent a Dog. This should include the following:
I). Attributes for the Dog class are name (String), breed (String), age (int), a unique licenceNo (int), and an attribute to indicate if the dog is dangerous called isDangerous (boolean).
ii). A default constructor which should set appropriate default values for each attribute except the licenceNo which is unique to each Dog object.
iii). A second constructor which accepts and sets values for each of the attributes.
iv). Getter and setter methods for name, breed, age, isDangerous.
v). A getter method for the licenceNo of each Dog object.
vi). A method called bark() that takes no parameters, returns nothing and prints the dog’s name by says Woof! Woof! Woof! when called. See sample output below.
vii). A method called toString() that prints all details about a Dog object (see sample output below for format)
NAME: <dog name>
BREED: <dog breed>
AGE: <dog age>
IS DANGEROUS? <is dog dangerous>
LICENCE NO: <licence number>
b) Write a main method in a new class called TestDog and in this method:
i). Declare an array of 3 Dog objects. Use the second constructor for the first 2 Dogs and the default constructor for the last Dog.
Number name breed age isDangerous
1 “Lady” “Poodle” 2 False
2 “Rocky” “Pit Bull” 4 True
ii). Call the setName(<…>), setBreed(<…>), setAge(<…>), setIsDangerous(<…>) method to change the information on the 3rd Dog.
Num name breed age isDangerous
3 “Spot” “Dalmatian” 3 False
iii). Call the getName(), getBreed(), getAge(), getIsDangerous() and getLicenceNo() methods to print the information of the 3rd Dog to the screen (it should be displayed exactly as the sample output below).
iv). Call the bark() method for all of the Dogs.
v). Use the ternary operator to print a message for each dog that states if it is dangerous.
vi). Call the toString() method to print the details for the first 2 Dogs.
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly