Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java code only. 15.1 Permit to hunt Hunters need permits to hunt. We imagine an application involving hunters, the permits, and animals to hunt. An
Java code only.
15.1 Permit to hunt Hunters need permits to hunt. We imagine an application involving hunters, the permits, and animals to hunt. An object of type Permit keeps track of the animals to hunt and the amount, a Hunter object needs a permit, then can shoot animals. For each animal shot, the permit needs to be informed, so it can keep track of it. Other objects are the animals. Create a class Animal, with subclasses Deer, Rabbit and Pheasant. Their implementation should have a toString(), the rest is optional fluff. Create a class Permit, with attributes target (Animal), amount (int) and dateFrom (LocalDate.) Give the class the usual methods. Also implement a method shoot(Animal target), which checks whether the amount permitted has been reached, if not, lowers the amount by one and returns true, otherwise returns false. Create a class Hunter, with a List of Animals called trophies, a name, and a Permit. The constructor accepts a String for name and an object of type Animal as the kind of animal to hunt plus an int indicating how many of them can be shot. It then creates the permit for the hunter. Add a method shoot(Animal target), which checks with the permit whether shooting is allowed, and if so, adds the animal to the list of trophies. Create a toString which will show a list of trophies (all animals shot.) Create a class Hunt with a main method. In the main method, add the following code: Hunter pang = new Hunter("Ping Pang", new Deer(), 5); pang.shoot(new Deer()); pang. shoot(new Pheasant ()); pang. shoot(new Deer()); pang. shoot(new Rabbit()); pang. shoot(new Deer()); pang. shoot(new Deer()); System.out.println(pang); Run the code and explain the resultsStep 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