ps Lock G H K L Name CSc 1302 - Practical Test 2 (C) Write a class called Park p
ID: 3912719 • Letter: P
Question
ps Lock G H K L Name CSc 1302 - Practical Test 2 (C) Write a class called Park private instance variables: name is a String: fieldl (the size of field I) is a double field2 (the size of field 2) is a double: field3 (the size of field 3) is a double - constructors -Instance methods . setName . getName .setFieldSize(double fsize) . getParkSign: return a letter sign for the field: if (fieldI+field2+field3)/3 - > 1000,"P" 500-1000, "B getLargestField: return the size of the largest Field in the Park Write a class called GAParks with main method Create an array with 3 Park objects and one park's name is your own name - Set their field size to random values by using setFieldSize(double fsize[l) method Print out all 7 parks including name, parksign, and size of smallest field Woody Parks sign is "T" Suntrust Park's sign is "B" Largest field in this park with size-495.0 Largest Field in this park with size 17.0Explanation / Answer
GAParks.java
public class GAParks {
public static void main(String[] args) {
Park p1 = new Park();
p1.setName("Woody");
double fsize[] = new double[3];
for(int i=0;i<fsize.length;i++) {
fsize[i]=Math.random()*1000;
}
p1.setFieldSize(fsize);
Park p2 = new Park();
p2.setName("Suntrust");
for(int i=0;i<fsize.length;i++) {
fsize[i]=Math.random()*1000;
}
p2.setFieldSize(fsize);
Park p3 = new Park();
p3.setName("East");
for(int i=0;i<fsize.length;i++) {
fsize[i]=Math.random()*1000;
}
p3.setFieldSize(fsize);
System.out.println(p1.getName()+" Park's Sign is "+p1.getParkSign()+" Largest Field in this park with size = "+p1.getLargeField());
System.out.println(p2.getName()+" Park's Sign is "+p2.getParkSign()+" Largest Field in this park with size = "+p2.getLargeField());
System.out.println(p3.getName()+" Park's Sign is "+p3.getParkSign()+" Largest Field in this park with size = "+p3.getLargeField());
}
}
Park.java
public class Park {
private String name;
private double field1, field2, field3;
public Park() {
}
public Park(String name, double field1, double field2, double field3) {
this.name = name;
this.field1=field1;
this.field2=field2;
this.field3=field3;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setFieldSize(double fsize[]) {
field1=fsize[0];
field2=fsize[1];
field3=fsize[2];
}
public char getParkSign() {
double avg = (field1+field2+field3)/3;
if(avg>=1000) {
return 'F';
} else if(avg>=500 && avg<1000) {
return 'B';
} else {
return 'T';
}
}
public double getLargeField() {
if(field1>=field2 && field1>=field3) {
return field1;
} else if(field2>=field3) {
return field2;
} else {
return field3;
}
}
}
Output:
Woody Park's Sign is T Largest Field in this park with size = 534.4716256017379
Suntrust Park's Sign is T Largest Field in this park with size = 877.2805870748834
East Park's Sign is B Largest Field in this park with size = 877.4009660877472
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.