Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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 results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Jacob is a natural leader.

Answered: 1 week ago

Question

Do you think physicians should have unions? Why or why not?

Answered: 1 week ago