Skip to content

Commit b1ec529

Browse files
committed
Added Park application, then moved it to problems folder. Will come back to this file later.
1 parent c8be074 commit b1ec529

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed

Problems/src/Park/Park.java

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
}

Problems/src/Park/TestPark.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package Park;
2+
/**
3+
* Created by Kimberly Henry <kimberly.henry@outlook.com>
4+
* On: Jul at: 2:50 PM.
5+
* Project: Java Programming
6+
* Package: Park
7+
* File: TestPark
8+
* <p/>
9+
* <p/>
10+
* • Accepts a Park parameter and returns a Boolean value that indicates
11+
* whether the Park has both picnic facilities and a playground.
12+
* <p/>
13+
* • Accepts a Park parameter and four Boolean parameters that represent
14+
* requests for the previously mentioned Park features. The method returns
15+
* true if the Park has all the requested features.
16+
* <p/>
17+
* • Accepts a Park parameter and four Boolean parameters that represent
18+
* requests for the previously mentioned Park features. The method returns
19+
* true if the Park has exactly all the requested features and no others.
20+
* <p/>
21+
* • Accepts a Park parameter and returns the number of facilities that
22+
* the Park features.
23+
* <p/>
24+
* • Accepts two Park parameters and returns the larger Park.
25+
* Declare at least three Park objects, and demonstrate that all the methods
26+
* work correctly. Save the program as TestPark.java.
27+
*/
28+
public class TestPark
29+
{
30+
//TODO and fields, constructors, and methods;
31+
public static void main(String[] args)
32+
{
33+
//TODO add methods;
34+
}
35+
}

0 commit comments

Comments
 (0)