Create a class for the Parks Department in cloverdale The cl

Create a class for the Parks Department in cloverdale. The class is named Park, and it contains a String field for the name of the park, an integer field for the size in acres, and four Boolean fields that hold whether the park has each of these features: Picnic facilities, a bennis court, a playground, and a swimming pool. Including get and set methods for each fields. Include code in the method that sets the number of acres and does not allow a negative number or a number over 400. Then, create a program with methods that do the following: Accepts a Park parameter and returns a Boolean value that indicates whether the Park has both facilities and a playground Accepts a Park parameter and four Boolean parameters that represent requests for the previously mentioned Park features The method returns true if the Park has all the requested features. Accepts a Park parameter and tour Boolean parameters that represent requests for the previously mentioned Park features The method returns true if the Park has exactly all the requested features and no others Accepts a Park parameter and returns the number et facilities that the Park features. Accepts two Park parameters and returns the larger Park. Declare at least three Park objects, and demonstrate that all the methods work correctly. Save the program as

Solution

Park.java

public class Park {
private String name;
private int size;
private boolean picnicFacilities;
private boolean tennisCourt;
private boolean playGround;
private boolean swimmingPool;
public Park() {
   super();

}
public String getName() {
   return name;
}
public void setName(String name) {
   this.name = name;
}
public int getSize() {
   return size;
}
public void setSize(int size) {
   if(size>0 && size<=400)
       this.size = size;  
       else
       new IllegalArgumentException(\":: Size must be greater than 0 and below 400 :: \");  
  
}
public boolean isPicnicFacilities() {
   return picnicFacilities;
}
public void setPicnicFacilities(boolean picnicFacilities) {
   this.picnicFacilities = picnicFacilities;
}
public boolean isTennisCourt() {
   return tennisCourt;
}
public void setTennisCourt(boolean tennisCourt) {
   this.tennisCourt = tennisCourt;
}
public boolean isPlayGround() {
   return playGround;
}
public void setPlayGround(boolean playGround) {
   this.playGround = playGround;
}
public boolean isSwimmingPool() {
   return swimmingPool;
}
public void setSwimmingPool(boolean swimmingPool) {
   this.swimmingPool = swimmingPool;
}
public boolean comparePicnicFacilitesAndPlayGround(Park park)
{
   if(park.picnicFacilities && park.isPlayGround())
   {
   return true;
   }
   else
   return false;
}

public boolean compareAllfacilities(Park park,boolean picnic,boolean tennis,boolean playground,boolean swimmingpool)
{
if(park.isPicnicFacilities()==picnic && park.isTennisCourt()==tennis && park.isPlayGround()==playground && park.isSwimmingPool()==swimmingpool)
return true;
else
   return false;
}

public int countParkFeatures(Park park)
{
   int count=0;
   if(park.isPicnicFacilities())
       count++;
   if(park.isPlayGround())
       count++;
   if(park.swimmingPool)
       count++;
   if(park.tennisCourt)
       count++;
  
   return count;
      
}
public boolean compareparkSize(Park park)
{
   int park1=this.getSize();
   int park2=park.getSize();
   if(park1>park2)
       return true;
   else
       return false;
}
}

____________________________________________

TestClass.java

import java.util.Scanner;

public class TestClass {

   public static void main(String[] args) {

   Park park1=new Park();
   park1.setName(\"Central Park\");
   park1.setSize(4);
   park1.setPicnicFacilities(true);
   park1.setTennisCourt(true);
   park1.setPlayGround(true);
   park1.setSwimmingPool(true);
     
   Park park2=new Park();
   park2.setName(\"Prospect Park\");
   park2.setSize(3);
   park2.setPicnicFacilities(false);
   park2.setTennisCourt(false);
   park2.setPlayGround(true);
   park2.setSwimmingPool(true);
     
   Park park3=new Park();
   park3.setName(\"Washington Square Park\");
   park3.setSize(5);
   park3.setPicnicFacilities(true);
   park3.setTennisCourt(true);
   park3.setPlayGround(true);
   park3.setSwimmingPool(true);
   System.out.println(\"\ _______Info about \"+park1.getName()+\"_________\");
   Park park=new Park();
   if(park.comparePicnicFacilitesAndPlayGround(park1))
       System.out.println(park1.getName()+\" has Both Picnic facilities and Play Ground Facilities \");
   else
       System.out.println(park1.getName()+\" has no both Picnic facilities and Play Ground Facilities \");
     
   park.compareAllfacilities(park1,true,true,true,true);
   if(park.comparePicnicFacilitesAndPlayGround(park1))
       System.out.println(park1.getName()+\" has All Facilities \");
   else
       System.out.println(park1.getName()+\" has not All Facilities \");
     
   System.out.println(\"The Number of Features the \"+park1.getName()+\" is :\"+park1.countParkFeatures(park1));
     
     
   System.out.println(\"\ _______Info about \"+park2.getName()+\"_________\");
   if(park.comparePicnicFacilitesAndPlayGround(park2))
       System.out.println(park2.getName()+\" has Both Picnic facilities and Play Ground Facilities \");
   else
       System.out.println(park2.getName()+\" has no both Picnic facilities and Play Ground Facilities \");
     
   park.compareAllfacilities(park2,true,true,true,true);
   if(park.comparePicnicFacilitesAndPlayGround(park2))
       System.out.println(park2.getName()+\" has All Facilities \");
   else
       System.out.println(park2.getName()+\" has not All Facilities \");
     
   System.out.println(\"The Number of Features the \"+park2.getName()+\" is :\"+park2.countParkFeatures(park2));
     
   System.out.println(\"\ _______Info about \"+park3.getName()+\"_________\");
   if(park.comparePicnicFacilitesAndPlayGround(park3))
       System.out.println(park3.getName()+\" has Both Picnic facilities and Play Ground Facilities \");
   else
       System.out.println(park3.getName()+\" has no both Picnic facilities and Play Ground Facilities \");
     
   park.compareAllfacilities(park3,true,true,true,true);
   if(park.comparePicnicFacilitesAndPlayGround(park3))
       System.out.println(park3.getName()+\" has All Facilities \");
   else
       System.out.println(park3.getName()+\" has not All Facilities \");
     
   System.out.println(\"The Number of Features the \"+park3.getName()+\" is :\"+park3.countParkFeatures(park3));
     
   System.out.println(\"\ _______Comparing Park Sizes_________\");
   if(park1.compareparkSize(park2))
       System.out.println(park1.getName()+\" size is bigger than \"+park2.getName());
   else
       System.out.println(park1.getName()+\" size is smaller than \"+park2.getName());
  
   if(park2.compareparkSize(park3))
       System.out.println(park2.getName()+\" size is bigger than \"+park3.getName());
   else
       System.out.println(park2.getName()+\" size is smaller than \"+park3.getName());
  
   if(park1.compareparkSize(park3))
       System.out.println(park1.getName()+\" size is bigger than \"+park3.getName());
   else
       System.out.println(park1.getName()+\" size is smaller than \"+park3.getName());

   }

}

______________________________________________

Output:


_______Info about Central Park_________
Central Park has Both Picnic facilities and Play Ground Facilities
Central Park has All Facilities
The Number of Features the Central Park is :4

_______Info about Prospect Park_________
Prospect Park has no both Picnic facilities and Play Ground Facilities
Prospect Park has not All Facilities
The Number of Features the Prospect Park is :2

_______Info about Washington Square Park_________
Washington Square Park has Both Picnic facilities and Play Ground Facilities
Washington Square Park has All Facilities
The Number of Features the Washington Square Park is :4

_______Comparing Park Sizes_________
Central Park size is bigger than Prospect Park
Prospect Park size is smaller than Washington Square Park
Central Park size is smaller than Washington Square Park

______________________________________Thank You

 Create a class for the Parks Department in cloverdale. The class is named Park, and it contains a String field for the name of the park, an integer field for t
 Create a class for the Parks Department in cloverdale. The class is named Park, and it contains a String field for the name of the park, an integer field for t
 Create a class for the Parks Department in cloverdale. The class is named Park, and it contains a String field for the name of the park, an integer field for t
 Create a class for the Parks Department in cloverdale. The class is named Park, and it contains a String field for the name of the park, an integer field for t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site