Question
(JAVA) Programming Assignment 3 There are a number of zoos available to tourists. 1. Create a...
(JAVA) Programming Assignment 3
There are a number of zoos available to tourists.
1. Create a Zoo class. Include data fields such as name of zoo, location, size, fee for the past 12 months, number of visitors recorded for the past 12 months, admission rates per visitor and annual budget. (20 points)
2. Include at least two mutators and two accessors. (15 points)
3. Include one default constructor and one more constructor. (15 points)
4. Write separate instance methods that implement: (30 points) a) return a string representing name of the zoo, the location and type of zoo; b) compute total admission based on admission rates and the number of visitors during the last 12 months; c) compute revenue from fees for the past year and total admission.
5. Create a second class to test your Zoo class. (20 points)
In your second class’s Main method, test your class by creating at least three new objects using the constructors or mutators you’ve created in your Zoo class. Each object will represent a specific zoo. Calculate and print revenue for each zoo.
Answers
Zoo.java
public class Zoo{
private String name, location;
private double size, fee, rate, budget;
public Zoo() {
size = 1000;
fee = 10;
rate = 2.5;
budget = 500000;
}
public Zoo(String name, String location, double size, double fee, double rate, double budget, int visitors) {
super();
this.name = name;
this.location = location;
this.size = size;
this.fee = fee;
this.rate = rate;
this.budget = budget;
this.visitors = visitors;
}
public double totalAdmissionCost() {
return visitors * rate;
}
public double totalRevenue() {
double revenue = fee + totalAdmissionCost();
System.out.println("Revenue of the zoo is " + revenue);
return revenue;
}
@Override
public String toString() {
return "Zoo [name=" + name + ", location=" + location + ", size=" + size + ", fee=" + fee + ", rate=" + rate
+ ", budget=" + budget + ", visitors=" + visitors + "]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public double getSize() {
return size;
}
public void setSize(double size) {
this.size = size;
}
public double getFee() {
return fee;
}
public void setFee(double fee) {
this.fee = fee;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public double getBudget() {
return budget;
}
public void setBudget(double budget) {
this.budget = budget;
}
public int getVisitors() {
return visitors;
}
public void setVisitors(int visitors) {
this.visitors = visitors;
}
private int visitors;
}
Test.java
public class Test{
public static void main(String[] args) {
Zoo zoo1 = new Zoo("Corbett", "India", 25000, 1024, 2.8, 10000, 500);
System.out.println(zoo1);
Zoo zoo2 = new Zoo("RedStone", "UK", 12345, 424, 7.2, 124580, 800);
System.out.println(zoo2);
Zoo zoo3 = new Zoo("Venkara", "USA", 4527, 987, 10, 885000, 987);
System.out.println(zoo3);
}
}
Please check the code. If you have any doubts comment below and I am happy to help :)