Question: You Do It Creating a Class that Contains Instance Fields and Methods 153 Next, you create a class to store information about event services offered
You Do It Creating a Class that Contains Instance Fields and Methods 153 Next, you create a class to store information about event services offered at Paradise Day Spa. 1. Open a new document in your text editor, and type the following class header and the curly braces to surround the class body: public class SpaService Between the curly braces for the class, insert two private data fields that will hold data about a spa service: private String serviceDescription; private double price; Within the class's curly braces and after the field declarations, enter the following two methods that set the field values. The setServiceDescriptionO method accepts a String parameter and assigns it to the serviceDescription field for each object that eventually will be instantiated. Similarly, the setPriceO method accepts a double parameter and assigns it to the price field. Note that neither of these methods is static public void setServiceDescription(String service) 2. 3. serviceDescription-service; public void setPrice(double pr) price = pr ; Next, add two methods that retrieve the field values as follows: public String getServiceDescriptionO 4. return serviceDescription public double getPriceO return price; Save the file as SpaService.java, compile it, and then correct any syntax errors. Remember, you cannot run this file as a program because it does not contain a public static mainO method. After you read the next section, you will use this class to create objects. 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
