|
| 1 | +package Park; |
| 2 | +import java.util.Scanner; |
| 3 | +/** |
| 4 | + * Created by Kimberly Henry <kimberly.henry@outlook.com> |
| 5 | + * On: Jul at: 2:47 PM. |
| 6 | + * Project: Java Programming |
| 7 | + * Package: Park |
| 8 | + * File: Park |
| 9 | + * Create a class for the Parks Department in Cloverdale. The class is named Park, |
| 10 | + * and it contains a String field for the name of the park, an integer field for |
| 11 | + * the size in acres, and four Boolean fields that hold whether the park has each |
| 12 | + * of these features: picnic facilities, a tennis court, a playground, and a |
| 13 | + * swimming pool. |
| 14 | + * Include get and set methods for each field. |
| 15 | + * Include code in the method that sets the number of acres and does not allow a negative |
| 16 | + * number or a number over 400. |
| 17 | + * Save the file as Park.java. |
| 18 | + */ |
| 19 | +public class Park |
| 20 | + { |
| 21 | + private String parkName; |
| 22 | + private int parkAcres; |
| 23 | + private boolean hasPicnic; |
| 24 | + private boolean hasTennisCourt; |
| 25 | + private boolean hasPlayground; |
| 26 | + private boolean hasSwimming; |
| 27 | + public Scanner enter = new Scanner(System.in); |
| 28 | + public void setParkName(String park) |
| 29 | + { |
| 30 | + parkName = park; |
| 31 | + } |
| 32 | + public void setParkAcres() |
| 33 | + { |
| 34 | + int acres; |
| 35 | + System.out.println("Enter the number of acres for park: "); |
| 36 | + acres = enter.nextInt(); |
| 37 | + if (acres < 0) |
| 38 | + { |
| 39 | + System.out.println("Acres is INVALID. Please enter a number greater than 0."); |
| 40 | + setParkAcres(); |
| 41 | + } |
| 42 | + else if (parkAcres > 400) |
| 43 | + { |
| 44 | + System.out.println("Acres is INVALID. Please enter a number less than 401."); |
| 45 | + setParkAcres(); |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + parkAcres = acres; |
| 50 | + } |
| 51 | + } |
| 52 | + public void setHasPicnic() |
| 53 | + { |
| 54 | + int picnic; |
| 55 | + System.out.println("Does park have picnic area?"); |
| 56 | + System.out.println("1 - YES\n0 - NO"); |
| 57 | + picnic = enter.nextInt(); |
| 58 | + switch (picnic) |
| 59 | + { |
| 60 | + case 1: |
| 61 | + picnic = 1; |
| 62 | + hasPicnic = (1 > 0); |
| 63 | + break; |
| 64 | + case 2: |
| 65 | + picnic = 0; |
| 66 | + hasPicnic = (0 > 1); |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | + public void setHasTennisCourt() |
| 71 | + { |
| 72 | + int tennis; |
| 73 | + System.out.println("Does park have a Tennis Court?"); |
| 74 | + System.out.println("1 - YES\n0 - NO"); |
| 75 | + tennis = enter.nextInt(); |
| 76 | + switch (tennis) |
| 77 | + { |
| 78 | + case 1: |
| 79 | + tennis = 1; |
| 80 | + hasTennisCourt = (1 > 0); |
| 81 | + break; |
| 82 | + case 2: |
| 83 | + tennis = 0; |
| 84 | + hasTennisCourt = (0 > 1); |
| 85 | + break; |
| 86 | + } |
| 87 | + } |
| 88 | + public void setHasPlayground() |
| 89 | + { |
| 90 | + int playground; |
| 91 | + System.out.println("Does park have a Playground?"); |
| 92 | + System.out.println("1 - YES\n0 - NO"); |
| 93 | + playground = enter.nextInt(); |
| 94 | + switch (playground) |
| 95 | + { |
| 96 | + case 1: |
| 97 | + playground = 1; |
| 98 | + hasPlayground = (1 > 0); |
| 99 | + break; |
| 100 | + case 2: |
| 101 | + playground = 0; |
| 102 | + hasPlayground = (0 > 1); |
| 103 | + break; |
| 104 | + } |
| 105 | + } |
| 106 | + public void setHasSwimming() |
| 107 | + { |
| 108 | + int swimming; |
| 109 | + System.out.println("Does park have a Swimming Pool?"); |
| 110 | + System.out.println("1 - YES\n0 - NO"); |
| 111 | + swimming = enter.nextInt(); |
| 112 | + switch (swimming) |
| 113 | + { |
| 114 | + case 1: |
| 115 | + swimming = 1; |
| 116 | + hasSwimming = (1 > 0); |
| 117 | + break; |
| 118 | + case 2: |
| 119 | + swimming = 0; |
| 120 | + hasSwimming = (0 > 1); |
| 121 | + break; |
| 122 | + } |
| 123 | + } |
| 124 | + public String getParkName() |
| 125 | + { |
| 126 | + return parkName; |
| 127 | + } |
| 128 | + public int getParkAcres() |
| 129 | + { |
| 130 | + return parkAcres; |
| 131 | + } |
| 132 | + public boolean isHasPicnic() |
| 133 | + { |
| 134 | + return hasPicnic; |
| 135 | + } |
| 136 | + public boolean isHasTennisCourt() |
| 137 | + { |
| 138 | + return hasTennisCourt; |
| 139 | + } |
| 140 | + public boolean isHasPlayground() |
| 141 | + { |
| 142 | + return hasPlayground; |
| 143 | + } |
| 144 | + public boolean isHasSwimming() |
| 145 | + { |
| 146 | + return hasSwimming; |
| 147 | + } |
| 148 | + } |
0 commit comments